-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·137 lines (121 loc) · 5.75 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·137 lines (121 loc) · 5.75 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env bash
#
# predatorctl - system installer.
#
# Installs the app into a root-owned directory (not user-writable), registers
# the launcher, the icon, the menu entry (.desktop) and the auth_admin_keep
# polkit rule (password once per session — NOT passwordless).
#
# Usage: sudo ./install.sh [--after=UNIT]
#
# --after=UNIT optional systemd unit name, e.g.
# --after=power-profiles-daemon.service. Some system
# power-management daemons also own
# /sys/firmware/acpi/platform_profile and can start (via
# D-Bus activation) *after* predatorctl-restore.service at
# boot, overwriting the restored thermal profile with their
# own default. Passing one here adds a drop-in ordering
# predatorctl-restore.service after it (Wants=+After=), so
# it starts first and settles before we write.
#
# NOT applied unless you ask: Wants= would also *start* that
# unit, and some of these daemons Conflicts= each other (e.g.
# power-profiles-daemon conflicts with tlp) -- pulling one in
# could stop a power-management tool you're already using on
# purpose. Only pass this if you've hit the race yourself.
#
set -euo pipefail
APP_DIR="/usr/local/lib/predatorctl"
BIN="/usr/local/bin/predatorctl"
DESKTOP="/usr/share/applications/io.github.rdmsilva.predatorctl.desktop"
ICON="/usr/share/icons/hicolor/scalable/apps/predatorctl.svg"
POLKIT="/etc/polkit-1/rules.d/49-predatorctl.rules"
HELPER="$APP_DIR/helper/predatorctl-helper"
RESTORE_HELPER="$APP_DIR/helper/predatorctl-restore"
RESTORE_UNIT="/etc/systemd/system/predatorctl-restore.service"
RESTORE_ETC="/etc/predatorctl"
RESTORE_DROPIN_DIR="/etc/systemd/system/predatorctl-restore.service.d"
AFTER_UNIT=""
for arg in "$@"; do
case "$arg" in
--after=*) AFTER_UNIT="${arg#--after=}" ;;
*)
echo "Error: unknown argument '$arg' (usage: sudo ./install.sh [--after=UNIT])" >&2
exit 1
;;
esac
done
SRC="$(cd "$(dirname "$0")" && pwd)"
if [[ $EUID -ne 0 ]]; then
echo "Error: run as root → sudo ./install.sh" >&2
exit 1
fi
if [[ -n "$AFTER_UNIT" && ! "$AFTER_UNIT" =~ ^[A-Za-z0-9:_.@-]+\.service$ ]]; then
echo "Error: '--after=$AFTER_UNIT' doesn't look like a systemd unit name (expected *.service)" >&2
exit 1
fi
echo "==> Installing predatorctl into $APP_DIR"
rm -rf "$APP_DIR"
install -d -m 755 "$APP_DIR"
cp -r "$SRC/src" "$APP_DIR/src"
cp -r "$SRC/helper" "$APP_DIR/helper"
find "$APP_DIR" -type d -name "__pycache__" -exec rm -rf {} +
# everything root-owned; helper executable (invoked directly via pkexec)
chown -R root:root "$APP_DIR"
find "$APP_DIR" -type d -exec chmod 755 {} +
find "$APP_DIR" -type f -exec chmod 644 {} +
chmod 755 "$HELPER"
chmod 755 "$RESTORE_HELPER"
echo "==> Launcher: $BIN"
cat > "$BIN" <<EOF
#!/bin/sh
exec python3 "$APP_DIR/src/main.py" "\$@"
EOF
chmod 755 "$BIN"
echo "==> Icon: $ICON"
install -d -m 755 "$(dirname "$ICON")"
install -m 644 "$SRC/data/icons/predatorctl.svg" "$ICON"
echo "==> Menu entry: $DESKTOP"
rm -f /usr/share/applications/predatorctl.desktop # old filename (pre-icon-fix installs); the
# app-id/desktop-file basename mismatch was
# why the taskbar icon fell back to generic
install -m 644 "$SRC/data/io.github.rdmsilva.predatorctl.desktop" "$DESKTOP"
echo "==> Polkit rule (auth_admin_keep): $POLKIT"
install -m 644 "$SRC/data/49-predatorctl.rules" "$POLKIT"
echo "==> Boot-time preference restore (enabled, auto-populated as you use the app): $RESTORE_UNIT"
install -d -m 755 "$RESTORE_ETC"
install -m 644 "$SRC/data/restore.conf.example" "$RESTORE_ETC/restore.conf.example"
install -m 644 "$SRC/data/predatorctl-restore.service" "$RESTORE_UNIT"
rm -rf "$RESTORE_DROPIN_DIR"
if [[ -n "$AFTER_UNIT" ]]; then
echo "==> Ordering predatorctl-restore.service after: $AFTER_UNIT (opt-in, see install.sh usage)"
install -d -m 755 "$RESTORE_DROPIN_DIR"
printf '[Unit]\nAfter=%s\nWants=%s\n' "$AFTER_UNIT" "$AFTER_UNIT" > "$RESTORE_DROPIN_DIR/after.conf"
chmod 644 "$RESTORE_DROPIN_DIR/after.conf"
fi
systemctl daemon-reload 2>/dev/null || true
# Safe to enable unconditionally: ConditionPathExists=/etc/predatorctl/restore.conf
# in the unit makes this a no-op (successful, RemainAfterExit) until that file
# exists -- which predatorctl-helper creates itself the first time you change
# a setting in the app (see _persist() there). No manual config step needed.
systemctl enable --now predatorctl-restore.service 2>/dev/null || true
# refresh caches (silent if the tools aren't present)
gtk-update-icon-cache -q /usr/share/icons/hicolor 2>/dev/null || true
update-desktop-database /usr/share/applications 2>/dev/null || true
echo
echo "Done. 'Predator Control' is now in your application menu."
echo "You'll be asked for your password once per session (auth_admin_keep, ~5 min)."
echo
echo "linuwu_sense reloads with driver defaults on every reboot. From now on,"
echo "every profile/RGB/battery-limiter/fan change you make in the app is"
echo "automatically saved to $RESTORE_ETC/restore.conf and reapplied at boot"
echo "-- no extra steps needed. See $RESTORE_ETC/restore.conf.example if you"
echo "ever want to add or edit an entry by hand."
if [[ -z "$AFTER_UNIT" ]]; then
echo
echo "If your thermal profile reverts shortly after boot, a system"
echo "power-management daemon (e.g. power-profiles-daemon on GNOME/KDE)"
echo "may be racing us for /sys/firmware/acpi/platform_profile. Re-run with"
echo " sudo ./install.sh --after=power-profiles-daemon.service"
echo "to fix it -- see install.sh for why this isn't the default."
fi