Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
Β·379 lines (342 loc) Β· 17.6 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
Β·379 lines (342 loc) Β· 17.6 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#!/usr/bin/env bash
# Predator NoSense - Quick Installer Script
# Usage: curl -sSL https://raw.githubusercontent.com/eduardo-qts/Predator-NoSense/main/setup.sh | bash
set -euo pipefail
# ---------------------------------------------------------------------------
# Configuration
# ---------------------------------------------------------------------------
REPO_URL="https://github.com/eduardo-qts/Predator-NoSense.git"
RELEASES_API="https://api.github.com/repos/eduardo-qts/Predator-NoSense/releases/latest"
TOTAL_STEPS=7
# ---------------------------------------------------------------------------
# Colors & styling (gracefully degrade when not a TTY or NO_COLOR is set)
# ---------------------------------------------------------------------------
if [[ -t 1 && -z "${NO_COLOR:-}" ]]; then
BOLD=$'\e[1m'; DIM=$'\e[2m'; RESET=$'\e[0m'
RED=$'\e[38;5;196m'; GREEN=$'\e[38;5;82m'; YELLOW=$'\e[38;5;220m'
CYAN=$'\e[38;5;51m'; BLUE=$'\e[38;5;39m'; MAGENTA=$'\e[38;5;201m'
ORANGE=$'\e[38;5;208m'; GREY=$'\e[38;5;245m'
HIDE_CURSOR=$'\e[?25l'; SHOW_CURSOR=$'\e[?25h'
else
BOLD=''; DIM=''; RESET=''
RED=''; GREEN=''; YELLOW=''; CYAN=''; BLUE=''; MAGENTA=''; ORANGE=''; GREY=''
HIDE_CURSOR=''; SHOW_CURSOR=''
fi
CURRENT_STEP=0
LOG_FILE="$(mktemp)"
# ---------------------------------------------------------------------------
# Cleanup & error handling
# ---------------------------------------------------------------------------
cleanup() {
printf '%s' "$SHOW_CURSOR"
[[ -n "${LOG_FILE:-}" && -f "$LOG_FILE" ]] && rm -f "$LOG_FILE"
[[ -n "${TMP_DIR:-}" && -d "$TMP_DIR" ]] && rm -rf "$TMP_DIR"
}
fail() {
printf '%s\n' "$SHOW_CURSOR"
printf '%s\n' " ${RED}${BOLD}β FATAL:${RESET} ${RED}$1${RESET}"
if [[ -s "$LOG_FILE" ]]; then
printf '%s\n' " ${GREY}ββ last output ββββββββββββββββββββββββββββββββ${RESET}"
sed 's/^/ /' "$LOG_FILE" | tail -n 12
printf '%s\n' " ${GREY}βββββββββββββββββββββββββββββββββββββββββββββββ${RESET}"
fi
exit 1
}
trap cleanup EXIT
trap 'fail "Installation interrupted."' INT TERM
# ---------------------------------------------------------------------------
# ASCII art banner
# ---------------------------------------------------------------------------
banner() {
clear 2>/dev/null || true
printf '\n'
# Predator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ββββββββββββ ββββββ βββββββββ βββββββ βββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββ βββ βββββββββββ βββ βββ βββββββββββ
βββββββ ββββββββββββββ βββ βββββββββββ βββ βββ βββββββββββ
βββ βββ ββββββββββββββββββββββ βββ βββ ββββββββββββ βββ
βββ βββ ββββββββββββββββββ βββ βββ βββ βββββββ βββ βββ
WORDMARK
printf '%s' "$RESET"
printf '%s%s N O S E N S E Β· RGB Keyboard Control%s\n' "$CYAN" "$BOLD" "$RESET"
printf '%s ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ%s\n\n' "$GREY" "$RESET"
}
# ---------------------------------------------------------------------------
# Output helpers
# ---------------------------------------------------------------------------
step() {
CURRENT_STEP=$((CURRENT_STEP + 1))
printf '\n%s%s[%d/%d]%s %s%s%s\n' \
"$BOLD" "$CYAN" "$CURRENT_STEP" "$TOTAL_STEPS" "$RESET" "$BOLD" "$1" "$RESET"
}
info() { printf ' %sβ’%s %s\n' "$BLUE" "$RESET" "$1"; }
ok() { printf ' %sβ%s %s\n' "$GREEN" "$RESET" "$1"; }
warn() { printf ' %s!%s %s%s%s\n' "$YELLOW" "$RESET" "$YELLOW" "$1" "$RESET"; }
# Run a command silently with an animated spinner. On failure, abort with log.
# run_spin "Message" cmd arg1 arg2 ...
run_spin() {
local msg="$1"; shift
local frames='β β β Ήβ Έβ Όβ ΄β ¦β §β β '
local pid i=0 char
: > "$LOG_FILE"
( "$@" >"$LOG_FILE" 2>&1 ) &
pid=$!
printf '%s' "$HIDE_CURSOR"
while kill -0 "$pid" 2>/dev/null; do
char="${frames:i++%${#frames}:1}"
printf '\r %s%s%s %s' "$MAGENTA" "$char" "$RESET" "$msg"
sleep 0.08
done
printf '%s' "$SHOW_CURSOR"
if wait "$pid"; then
printf '\r %sβ%s %s\033[K\n' "$GREEN" "$RESET" "$msg"
else
printf '\r %sβ%s %s\033[K\n' "$RED" "$RESET" "$msg"
fail "$msg"
fi
}
# ---------------------------------------------------------------------------
# Pre-flight checks
# ---------------------------------------------------------------------------
banner
step "Running pre-flight checks"
# Architecture
ARCH="$(uname -m)"
if [[ "$ARCH" != "x86_64" ]]; then
fail "Predator NoSense requires an x86_64 system (detected: $ARCH)."
fi
ok "Architecture: ${BOLD}$ARCH${RESET}"
# OS detection
if [[ -f /etc/os-release ]]; then
. /etc/os-release
OS="${ID:-unknown}"
LIKE="${ID_LIKE:-}"
else
fail "Cannot read /etc/os-release β unsupported OS."
fi
ok "Distribution: ${BOLD}${PRETTY_NAME:-$OS}${RESET}"
# Resolve the package manager. We prefer matching the distro family, but fall
# back to whichever supported package manager is actually on PATH so that
# derivatives (Mint, Pop!_OS, EndeavourOS, Nobara, etc.) work transparently.
KVER="$(uname -r)"
PM=""
if [[ "$OS" == "arch" || "$LIKE" == *"arch"* ]] || command -v pacman >/dev/null 2>&1; then
PM="pacman"; PKG_TYPE="pkg.tar.zst"
elif [[ "$OS" == "ubuntu" || "$OS" == "debian" || "$LIKE" == *"debian"* || "$LIKE" == *"ubuntu"* ]] || command -v apt-get >/dev/null 2>&1; then
PM="apt"; PKG_TYPE="deb"
elif [[ "$OS" == "fedora" || "$LIKE" == *"fedora"* || "$LIKE" == *"rhel"* ]] || command -v dnf >/dev/null 2>&1; then
PM="dnf"; PKG_TYPE="rpm"
elif [[ "$LIKE" == *"suse"* ]] || command -v zypper >/dev/null 2>&1; then
PM="zypper"; PKG_TYPE="rpm"
fi
# The case/command-v order above can mis-rank on multi-PM systems; pin it to the
# distro family when we recognise one, regardless of what else is on PATH.
case "$OS" in
arch|manjaro|endeavouros|cachyos|garuda) PM="pacman"; PKG_TYPE="pkg.tar.zst" ;;
ubuntu|debian|linuxmint|pop|elementary|zorin|kali|raspbian) PM="apt"; PKG_TYPE="deb" ;;
fedora|rhel|centos|rocky|almalinux|nobara) PM="dnf"; PKG_TYPE="rpm" ;;
opensuse*|sles|suse) PM="zypper"; PKG_TYPE="rpm" ;;
esac
if [[ -z "$PM" ]]; then
fail "No supported package manager found (need apt, dnf, pacman or zypper). See BUILD.md for a manual install."
fi
ok "Package manager: ${BOLD}$PM${RESET} (app packages: .$PKG_TYPE)"
# Cache sudo credentials up front so spinners don't hide the password prompt.
if [[ $EUID -ne 0 ]]; then
info "Administrator privileges are required."
if [[ -r /dev/tty ]]; then
sudo -v < /dev/tty || fail "Could not obtain sudo privileges."
else
sudo -v || fail "Could not obtain sudo privileges."
fi
# Keep the sudo timestamp alive during the long build steps.
( while kill -0 "$$" 2>/dev/null; do sudo -n true 2>/dev/null; sleep 50; done ) &
SUDO_KEEPALIVE=$!
fi
ok "Privileges confirmed."
# ---------------------------------------------------------------------------
# Install dependencies (rsync is required by install_service.sh)
# ---------------------------------------------------------------------------
step "Installing build dependencies"
case "$PM" in
apt)
run_spin "Updating package index" sudo apt-get update -qq
run_spin "Installing curl git make gcc rsync jq + kernel headers" \
sudo apt-get install -y curl git make gcc rsync jq "linux-headers-$KVER"
INSTALL_CMD=(sudo apt-get install -y)
;;
dnf)
run_spin "Installing curl git make gcc rsync jq + kernel headers" \
sudo dnf install -y curl git make gcc rsync jq "kernel-devel-$KVER"
INSTALL_CMD=(sudo dnf install -y)
;;
zypper)
run_spin "Installing curl git make gcc rsync jq + kernel sources" \
sudo zypper --non-interactive install curl git make gcc rsync jq kernel-default-devel
INSTALL_CMD=(sudo zypper --non-interactive install)
;;
pacman)
# Arch's headers package depends on the running kernel flavour.
case "$KVER" in
*-lts) HDR_PKG="linux-lts-headers" ;;
*-zen) HDR_PKG="linux-zen-headers" ;;
*-hardened) HDR_PKG="linux-hardened-headers" ;;
*-cachyos*) HDR_PKG="linux-cachyos-headers" ;;
*) HDR_PKG="linux-headers" ;;
esac
info "Detected kernel flavour β ${BOLD}$HDR_PKG${RESET}"
run_spin "Installing base-devel git curl rsync jq + $HDR_PKG" \
sudo pacman -S --needed --noconfirm base-devel git curl rsync jq "$HDR_PKG"
INSTALL_CMD=(sudo pacman -U --noconfirm)
;;
esac
# Verify the kernel build tree exists β the #1 cause of module build failures
# (e.g. headers installed for a different kernel than the one you booted).
if [[ ! -d "/lib/modules/$KVER/build" ]]; then
warn "Kernel build tree for '$KVER' not found at /lib/modules/$KVER/build."
warn "You likely need to reboot into the kernel matching the headers just installed."
fi
ok "All dependencies present."
# ---------------------------------------------------------------------------
# Clone repository
# ---------------------------------------------------------------------------
step "Fetching source code"
TMP_DIR="$(mktemp -d)"
run_spin "Cloning $REPO_URL" \
git clone --depth 1 "$REPO_URL" "$TMP_DIR/Predator-NoSense"
cd "$TMP_DIR/Predator-NoSense/backend"
ok "Repository ready."
# ---------------------------------------------------------------------------
# Build & install the kernel module service (init-system aware)
# ---------------------------------------------------------------------------
step "Building & installing the kernel module"
sudo chmod +x ./*.sh
# Detect the init system so the module survives reboots on the right manager.
if [[ -d /run/systemd/system ]]; then
INIT="systemd"
elif command -v rc-service >/dev/null 2>&1 && { [[ -d /run/openrc ]] || command -v openrc >/dev/null 2>&1; }; then
INIT="openrc"
else
INIT="none"
fi
ok "Init system: ${BOLD}$INIT${RESET}"
info "Compiling the facer kernel module (this can take a moment)..."
case "$INIT" in
systemd)
run_spin "Installing turbo-fan systemd service & module" sudo ./install_service.sh
SERVICE_HINT="systemctl start/stop turbo-fan"
;;
openrc)
run_spin "Installing turbo-fan OpenRC service & module" sudo ./install_openrc.sh
SERVICE_HINT="rc-service turbo-fan start/stop"
;;
none)
warn "No systemd or OpenRC detected β installing the module for this boot only."
info "It will NOT survive a reboot; load it again with backend/install.sh."
run_spin "Building & loading the facer module" sudo ./install.sh
SERVICE_HINT="re-run backend/install.sh after each reboot"
;;
esac
ok "Kernel module installed."
# ---------------------------------------------------------------------------
# Download & install the desktop application
# ---------------------------------------------------------------------------
step "Installing the desktop application"
info "Querying GitHub for the latest release..."
LATEST_RELEASE_JSON="$(curl -fsSL "$RELEASES_API" || true)"
DOWNLOAD_URL="$(printf '%s' "$LATEST_RELEASE_JSON" \
| jq -r ".assets[] | select(.name | endswith(\".$PKG_TYPE\")) | .browser_download_url" \
| head -n 1)"
if [[ -z "$DOWNLOAD_URL" || "$DOWNLOAD_URL" == "null" ]]; then
warn "No .$PKG_TYPE release asset was found on GitHub."
info "The kernel module is installed, but the GUI app was skipped."
info "Publish a release with built packages, or build it manually (see BUILD.md)."
APP_INSTALLED=false
else
run_spin "Downloading application package" \
curl -fL "$DOWNLOAD_URL" -o "$TMP_DIR/app.$PKG_TYPE"
run_spin "Installing Predator NoSense" "${INSTALL_CMD[@]}" "$TMP_DIR/app.$PKG_TYPE"
ok "Application installed."
APP_INSTALLED=true
fi
# ---------------------------------------------------------------------------
# Grant non-root access to the keyboard char devices
# ---------------------------------------------------------------------------
# The keyboard devices come up owned by root, group "input" (mode 0660) via the
# udev rule shipped with the package. Without group membership the GUI can only
# apply colors through pkexec β prompting for a password on every change. Adding
# the user to "input" makes writes work directly, with no password.
step "Configuring keyboard access"
# Resolve the human user even when the script itself is run through sudo.
TARGET_USER="${SUDO_USER:-$(id -un)}"
# Reload the udev rule so the devices pick up the "input" group right away
# (the module may have loaded before the rule was present).
if command -v udevadm >/dev/null 2>&1; then
run_spin "Reloading udev rules" \
sudo sh -c 'udevadm control --reload-rules && udevadm trigger'
fi
if [[ "$TARGET_USER" == "root" ]]; then
warn "Could not determine a non-root user to add to the 'input' group."
warn "Run manually: sudo usermod -aG input <your-user> (then re-login)."
elif id -nG "$TARGET_USER" 2>/dev/null | tr ' ' '\n' | grep -qx input; then
ok "User ${BOLD}$TARGET_USER${RESET} is already in the 'input' group."
else
run_spin "Adding $TARGET_USER to the 'input' group" \
sudo usermod -aG input "$TARGET_USER"
NEED_RELOGIN=true
fi
# ---------------------------------------------------------------------------
# Done
# ---------------------------------------------------------------------------
step "Finishing up"
ok "Cleanup complete."
printf '\n%s%s ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ%s\n' "$GREEN" "$BOLD" "$RESET"
printf '%s%s β INSTALLATION COMPLETE! π β%s\n' "$GREEN" "$BOLD" "$RESET"
printf '%s%s ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ%s\n\n' "$GREEN" "$BOLD" "$RESET"
if [[ "${APP_INSTALLED:-false}" == "true" ]]; then
printf ' %sβ%s Launch %s%sPredator NoSense%s from your application menu.\n' \
"$CYAN" "$RESET" "$BOLD" "$ORANGE" "$RESET"
else
printf ' %sβ%s The kernel module is active. Build the GUI per %sBUILD.md%s.\n' \
"$CYAN" "$RESET" "$BOLD" "$RESET"
fi
printf ' %sβ%s Manage the service: %s%s%s.\n' \
"$CYAN" "$RESET" "$DIM" "${SERVICE_HINT:-systemctl start/stop turbo-fan}" "$RESET"
if [[ "${NEED_RELOGIN:-false}" == "true" ]]; then
printf ' %sβ%s %sLog out and back in once%s so the new "input" group applies β otherwise the app will keep asking for a password on every change.\n' \
"$CYAN" "$RESET" "$YELLOW" "$RESET"
fi
printf '\n %sEnjoy the glow. %sβ‘%s\n\n' "$MAGENTA" "$YELLOW" "$RESET"