-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·103 lines (89 loc) · 3.55 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·103 lines (89 loc) · 3.55 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
#!/bin/sh
# Audio Output Switcher — installer (POSIX sh; works with sh/dash/bash)
# Safe install: JS syntax, JSON and schema are validated FIRST, and only then
# are the files copied, so broken code never reaches the running GNOME Shell.
set -eu
UUID="audio-output-switcher@mehmetnuri.github.io"
EXT_DIR="$HOME/.local/share/gnome-shell/extensions/$UUID"
SCRIPT_DIR="$(cd -- "$(dirname -- "$0")" && pwd)"
say() { printf '==> %s\n' "$1"; }
die() { printf 'ERROR: %s\n' "$1" >&2; exit 1; }
# --- 1. Pre-flight validation --------------------------------------------
say "Validating files"
command -v glib-compile-schemas >/dev/null 2>&1 \
|| die "glib-compile-schemas not found (package: libglib2.0-bin)"
# JSON validation (metadata.json)
if command -v python3 >/dev/null 2>&1; then
python3 -c "import json,sys; json.load(open(sys.argv[1]))" "$SCRIPT_DIR/metadata.json" \
|| die "metadata.json is not valid JSON"
fi
# JS syntax validation — parses WITHOUT running the code (new Function).
if command -v gjs >/dev/null 2>&1; then
VALIDATOR="$(mktemp)"
trap 'rm -f "$VALIDATOR"' EXIT
cat > "$VALIDATOR" <<'EOF'
const GLib = imports.gi.GLib;
const System = imports.system;
let failed = false;
for (let i = 0; i < ARGV.length; i++) {
const path = ARGV[i];
const [ok, bytes] = GLib.file_get_contents(path);
if (!ok) { printerr(`Cannot read: ${path}`); failed = true; continue; }
const code = new TextDecoder('utf-8').decode(bytes);
try {
// Parse only; imports/gi are not executed.
new Function(code);
} catch (e) {
printerr(`SYNTAX ERROR: ${path}\n ${e}`);
failed = true;
}
}
System.exit(failed ? 1 : 0);
EOF
gjs "$VALIDATOR" "$SCRIPT_DIR/extension.js" "$SCRIPT_DIR/prefs.js" \
|| die "JS syntax validation failed — install aborted (running shell untouched)"
say "JS syntax OK"
else
say "WARNING: gjs missing, JS syntax validation skipped"
fi
# --- 2. Install ----------------------------------------------------------
say "Installing: $UUID"
mkdir -p "$EXT_DIR"
cp -f "$SCRIPT_DIR/metadata.json" "$EXT_DIR/"
cp -f "$SCRIPT_DIR/extension.js" "$EXT_DIR/"
cp -f "$SCRIPT_DIR/prefs.js" "$EXT_DIR/"
cp -f "$SCRIPT_DIR/README.md" "$EXT_DIR/" 2>/dev/null || true
rm -rf "$EXT_DIR/schemas"
cp -r "$SCRIPT_DIR/schemas" "$EXT_DIR/"
# Translations (locale/<lang>/LC_MESSAGES/*.mo)
if [ -d "$SCRIPT_DIR/locale" ]; then
rm -rf "$EXT_DIR/locale"
cp -r "$SCRIPT_DIR/locale" "$EXT_DIR/"
fi
say "Compiling schema"
glib-compile-schemas "$EXT_DIR/schemas/" || die "Failed to compile schema"
say "Enabling"
gnome-extensions enable "$UUID" 2>/dev/null \
|| say "Could not enable now (try again after restarting the shell)"
# --- 3. Reload instructions ----------------------------------------------
echo
say "Install complete."
echo
if [ "${XDG_SESSION_TYPE:-}" = "wayland" ]; then
cat <<'EOF'
IMPORTANT (Wayland): the running GNOME Shell does not automatically reload
updated code into memory. To apply the new code, LOG OUT and LOG BACK IN,
then if needed:
gnome-extensions enable audio-output-switcher@mehmetnuri.github.io
EOF
else
cat <<'EOF'
IMPORTANT (X11/Xorg): the running GNOME Shell does not automatically reload
updated code into memory. To LOAD the new code, restart GNOME Shell:
Alt + F2 -> type r -> Enter
(Your windows stay open.) Then use the shortcut: Super+Alt+O
Recovery: if the shell ever freezes, switch to a TTY with Ctrl+Alt+F3 and run
killall -3 gnome-shell
to get back to the desktop (no hard power-off required).
EOF
fi