-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·122 lines (103 loc) · 3.76 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·122 lines (103 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env bash
set -euo pipefail
UUID="eppmode@yurij.de"
HELPER_NAME="eppmode-helper"
HELPER_INSTALL_PATH="/usr/local/bin/${HELPER_NAME}"
SUDOERS_FILE="/etc/sudoers.d/eppmode"
STATE_DIR="/var/lib/eppmode"
PPD_UNIT="power-profiles-daemon.service"
PPD_DROPIN_DIR="/etc/systemd/system/${PPD_UNIT}.d"
PPD_DROPIN="${PPD_DROPIN_DIR}/eppmode.conf"
UNITS=(
eppmode-restore.service
eppmode-reassert.service
eppmode-reassert.path
eppmode-reassert.timer
eppmode-battery.service
eppmode-battery.timer
)
UDEV_RULE="99-eppmode-power.rules"
PPD_GUARD_SOURCE="eppmode-ppd-guard.conf"
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
candidates=(
"${script_dir}/tools"
"${HOME}/.local/share/gnome-shell/extensions/${UUID}/tools"
"/usr/share/gnome-shell/extensions/${UUID}/tools"
)
tools_dir=""
for path in "${candidates[@]}"; do
if [[ -f "${path}/${HELPER_NAME}" ]]; then
tools_dir="${path}"
break
fi
done
if [[ -z "${tools_dir}" ]]; then
echo "tools/ directory not found. Looked in:" >&2
printf ' %s\n' "${candidates[@]}" >&2
exit 1
fi
if ! command -v sudo >/dev/null 2>&1; then
echo "sudo not found. Install sudo or run this as root." >&2
exit 1
fi
if [[ ! -d /sys/devices/system/cpu/cpu0/cpufreq ]]; then
echo "No CPU cpufreq sysfs interface found. Nothing was installed." >&2
exit 1
fi
if [[ ! -r /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference ]]; then
echo "CPU EPP sysfs interface not found. This tool is intended for systems exposing energy_performance_preference." >&2
exit 1
fi
target_user="${SUDO_USER:-${USER:-$(id -un)}}"
if [[ -z "${target_user}" ]]; then
echo "Could not determine target user." >&2
exit 1
fi
if [[ ! "${target_user}" =~ ^[a-z_][a-z0-9._-]*$ ]]; then
echo "Refusing to write sudoers for unexpected username: ${target_user}" >&2
exit 1
fi
echo "Installing helper from ${tools_dir}/${HELPER_NAME} to ${HELPER_INSTALL_PATH}"
sudo install -o root -g root -m 0755 "${tools_dir}/${HELPER_NAME}" "${HELPER_INSTALL_PATH}"
sudo install -d -o root -g root -m 0755 "${STATE_DIR}"
sudo rm -f "${STATE_DIR}/platform-profile-unreliable"
sudo tee "${SUDOERS_FILE}" >/dev/null <<EOF
${target_user} ALL=(root) NOPASSWD: ${HELPER_INSTALL_PATH}
EOF
sudo chmod 0440 "${SUDOERS_FILE}"
sudo visudo -c -f "${SUDOERS_FILE}" >/dev/null
if command -v systemctl >/dev/null 2>&1; then
if systemctl cat "${PPD_UNIT}" >/dev/null 2>&1; then
if [[ ! -x /usr/libexec/power-profiles-daemon ]]; then
echo "Expected /usr/libexec/power-profiles-daemon was not found." >&2
exit 1
fi
sudo install -d -o root -g root -m 0755 "${PPD_DROPIN_DIR}"
sudo install -o root -g root -m 0644 \
"${tools_dir}/${PPD_GUARD_SOURCE}" "${PPD_DROPIN}"
fi
for unit in "${UNITS[@]}"; do
echo "Installing ${unit}"
sudo install -o root -g root -m 0644 "${tools_dir}/${unit}" "/etc/systemd/system/${unit}"
done
if [[ -r /sys/firmware/acpi/platform_profile && -r /sys/firmware/acpi/platform_profile_choices ]]; then
sudo install -o root -g root -m 0644 "${tools_dir}/${UDEV_RULE}" "/etc/udev/rules.d/${UDEV_RULE}"
if command -v udevadm >/dev/null 2>&1; then
sudo udevadm control --reload-rules
fi
else
echo "No ACPI platform_profile sysfs interface; skipping udev rule (EPP-only reassertion still applies)." >&2
fi
sudo systemctl daemon-reload
if systemctl cat "${PPD_UNIT}" >/dev/null 2>&1; then
sudo systemctl restart "${PPD_UNIT}"
fi
sudo systemctl enable eppmode-restore.service
sudo systemctl start eppmode-restore.service
sudo systemctl enable --now eppmode-reassert.path eppmode-reassert.timer
sudo systemctl enable --now eppmode-battery.timer
else
echo "systemctl not found; skipping systemd unit install." >&2
fi
echo "Done."
echo "Restart GNOME Shell or disable/enable the extension."