Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·293 lines (254 loc) · 15.2 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·293 lines (254 loc) · 15.2 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
#!/usr/bin/env bash
set -e
# Finish setup's terminal (omarchy-launch-floating-terminal-with-presentation)
# prints "Done!" whatever the exit code: a failed step has to say so itself.
# ERR, not EXIT: the wizard's cancel is an explicit exit with its own message.
trap 'echo "==> Setup failed — see the error above. Fix it and run setup again." >&2' ERR
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Backend lives outside the plugin dir: omarchy-shell hot-reloads plugins on
# any write under ~/.config/omarchy/plugins (python's __pycache__ included).
INSTALL_DIR="$HOME/.local/share/omarchy-vpn"
PLUGIN_ID="omarchy-vpn"
PLUGIN_DIR="$HOME/.config/omarchy/plugins/$PLUGIN_ID"
LEGACY_DIR="$HOME/.config/waybar/vpn-manager" # Omarchy 3 / waybar install
if ! command -v omarchy-shell >/dev/null; then
echo "error: omarchy-shell not found — this version needs Omarchy 4" >&2
echo " (the Omarchy 3 / waybar version lives in its own repository)" >&2
exit 1
fi
echo "==> omarchy-vpn installer"
echo ""
# ── Questions (before any sudo) ───────────────────────────────────────────────
# Detects what's installed, asks protocols/features (preselected), saves
# config.json and writes the packages still missing to fd 3 (PKG_FILE; the
# env marker tells it fd 3 is ours).
# -B: nothing may be written under the plugin dir (hot reload).
PKG_FILE=$(mktemp)
trap 'rm -f "$PKG_FILE"' EXIT
OMARCHY_VPN_WIZARD_FD=3 python3 -B "$REPO_DIR/src/vpn_manager.py" --install-wizard 3>"$PKG_FILE" || {
echo "==> Cancelled — nothing changed."
exit 1
}
mapfile -t MISSING < "$PKG_FILE"
# the wizard's last line after a yes to "Switch DNS to systemd-resolved?"
SWITCH_RESOLVCONF=""
if [[ ${#MISSING[@]} -gt 0 && ${MISSING[-1]} == ":resolv-stub" ]]; then
SWITCH_RESOLVCONF=1
MISSING=("${MISSING[@]:0:${#MISSING[@]}-1}")
fi
# ── Root helpers, read before any sudo ────────────────────────────────────────
# The checkout is user-writable: root installs the bytes read here, so a file
# swapped in during the password prompt never reaches /usr/local/bin.
declare -A HELPER HELPER_SHA
for name in omarchy-vpn-helper happ-killswitch openvpn-dns-updown omarchy-vpn-incy-network omarchy-vpn-dns-bootstrap; do
# "." keeps trailing newlines; && so a failed cat stops set -e (not printf's status)
HELPER[$name]=$(cat "$REPO_DIR/scripts/$name" && printf .)
HELPER[$name]=${HELPER[$name]%.}
HELPER_SHA[$name]=$(printf %s "${HELPER[$name]}" | sha256sum | cut -d' ' -f1)
done
# Root gets ONLY these stdlib-only modules; keep worker/launcher/config/assets user-side.
# network.protect_socket is root-side; network.prepare_config's app imports must stay lazy.
declare -A ROOT_MODULE ROOT_MODULE_SHA
for name in incy/__init__.py incy/broker.py incy/network.py incy/privileged.py vpn_dns/__init__.py vpn_dns/control.py vpn_dns/resolvers.py vpn_dns/profiles.py vpn_dns/runtime.py; do
ROOT_MODULE[$name]=$(cat "$REPO_DIR/src/$name" && printf .)
ROOT_MODULE[$name]=${ROOT_MODULE[$name]%.}
ROOT_MODULE_SHA[$name]=$(printf %s "${ROOT_MODULE[$name]}" | sha256sum | cut -d' ' -f1)
done
install_helper() { # NAME → /usr/local/bin/NAME, root:root 755, re-hashed as root
echo "==> Installing $1 to /usr/local/bin..."
printf %s "${HELPER[$1]}" | sudo install -o root -g root -m 755 /dev/stdin "/usr/local/bin/$1"
[[ $(sudo sha256sum "/usr/local/bin/$1" | cut -d' ' -f1) == "${HELPER_SHA[$1]}" ]] || {
echo "error: /usr/local/bin/$1 doesn't match the copy read before sudo" >&2
return 1
}
}
# ── Dependencies ──────────────────────────────────────────────────────────────
echo ""
echo "==> Root steps: packages, helpers, sudoers rule"
sudo -v
# openresolv (left by an older install.sh) conflicts with systemd-resolvconf, and
# --noconfirm answers "no" to removing a conflicting package. Not one transaction:
# if pacman -S fails after this, a re-run asks again and finishes the switch.
if [[ -n $SWITCH_RESOLVCONF ]] && pacman -Q openresolv 2>/dev/null | grep -q "^openresolv "; then
echo "==> Replacing openresolv with systemd-resolvconf..."
sudo pacman -R --noconfirm openresolv
fi
if (( ${#MISSING[@]} )); then
echo "==> Installing: ${MISSING[*]}"
sudo pacman -S --needed --noconfirm "${MISSING[@]}"
else
echo "==> All packages already installed"
fi
if [[ -n $SWITCH_RESOLVCONF ]]; then
echo "==> /etc/resolv.conf -> systemd-resolved's stub"
sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
fi
# ── sudoers rule ──────────────────────────────────────────────────────────────
SUDOERS_FILE="/etc/sudoers.d/vpn-manager"
# Managed by this installer: rewrite on every run so upgrades pick up new rules.
# Three things only, each with a fixed command surface:
# omarchy-vpn-helper (scripts/, root-owned): WireGuard/AmneziaWG/OpenVPN up/down,
# import, delete, autostart, endpoints — profile names only, never paths;
# one fixed Windscribe helper-service reset (no service/PID argument);
# incy-network — fixed mode + session token, root-owned Python -I entry;
# it refuses imports that could run commands as root (WireGuard PostUp/…,
# OpenVPN directives off its allowlist: up/route-up/plugin/…);
# happ-killswitch (root-owned): the kill switch's nft rules;
# sysctl -w net.ipv6.conf.{all,default}.disable_ipv6={0,1} (IPv6 leak guard —
# none of the providers tunnel IPv6, see src/ipv6guard.py).
# It used to grant `wg-quick *`, `cp * /etc/wireguard/*`, `cat /etc/wireguard/*`,
# `kill` and `openvpn --config *` — sudoers' `*` spans `/` and `..`, and a PostUp
# line runs as root, so every process running as the user had passwordless root
# (and could read the private keys). plugins.omarchy.org's scanner blocks that.
# openvpn-dns-updown (root-owned) applies OpenVPN-pushed DNS via systemd-resolved;
# openvpn runs as root, so its --up/--down child needs no entry of its own.
# the helper first: a rule pointing at a missing (or old) helper breaks connects
# Python -I imports only this root-owned package, never the user's backend.
sudo install -d -o root -g root -m 755 /usr/local/lib/omarchy-vpn /usr/local/lib/omarchy-vpn/incy /usr/local/lib/omarchy-vpn/vpn_dns
for name in "${!ROOT_MODULE[@]}"; do
target="/usr/local/lib/omarchy-vpn/$name"
printf %s "${ROOT_MODULE[$name]}" | sudo install -o root -g root -m 644 /dev/stdin "$target"
[[ $(sudo sha256sum "$target" | cut -d' ' -f1) == "${ROOT_MODULE_SHA[$name]}" ]] || {
echo "error: $target doesn't match the copy read before sudo" >&2
exit 1
}
done
install_helper omarchy-vpn-incy-network
install_helper omarchy-vpn-dns-bootstrap
install_helper omarchy-vpn-helper
echo "==> Writing sudoers rule..."
# the numeric uid, not $USER: an unusual valid name (e.g. ALL) would change the rule's meaning
echo "#$(id -u) ALL=(root) NOPASSWD: /usr/local/bin/omarchy-vpn-helper, /usr/local/bin/happ-killswitch, /usr/bin/sysctl -w net.ipv6.conf.all.disable_ipv6=1, /usr/bin/sysctl -w net.ipv6.conf.all.disable_ipv6=0, /usr/bin/sysctl -w net.ipv6.conf.default.disable_ipv6=1, /usr/bin/sysctl -w net.ipv6.conf.default.disable_ipv6=0" \
| sudo tee "$SUDOERS_FILE" > /dev/null
sudo chmod 440 "$SUDOERS_FILE"
sudo visudo -cf "$SUDOERS_FILE" > /dev/null && echo "==> sudoers rule validated"
# Imports refuse root hooks, but `up` still runs configs already on disk —
# some may predate the helper (the old rule let any process `cp` one there).
unsafe_configs=$(sudo /usr/local/bin/omarchy-vpn-helper audit)
if [[ -n $unsafe_configs ]]; then
echo "==> WARNING: these VPN configs have lines an import would refuse (root commands or file reads):"
echo "$unsafe_configs" | sed 's/^/ /'
echo " Remove those lines unless you put them there yourself."
fi
# ── killswitch script (root-owned, driven via the NOPASSWD sudoers rule) ─────
install_helper happ-killswitch
# Remove the user-writable copy if it exists (superseded by the root-owned one)
rm -f "$HOME/.local/bin/happ-killswitch"
install_helper openvpn-dns-updown
# ── /etc/wireguard permissions ────────────────────────────────────────────────
echo "==> Setting /etc/wireguard directory permissions..."
sudo mkdir -p /etc/wireguard
sudo chmod o+rx /etc/wireguard
# ── /etc/amnezia/amneziawg permissions (AmneziaWG, optional) ─────────────────
# Only wires up permissions; amneziawg-tools/amneziawg-dkms are not pulled in
# here (dkms needs matching linux-headers per kernel) — install them yourself
# if you use AmneziaWG, the provider is a no-op without awg-quick.
echo "==> Setting /etc/amnezia/amneziawg directory permissions..."
sudo mkdir -p /etc/amnezia/amneziawg
sudo chmod o+rx /etc/amnezia/amneziawg
# ── /etc/openvpn/client directory ─────────────────────────────────────────────
echo "==> Creating /etc/openvpn/client directory..."
sudo mkdir -p /etc/openvpn/client
sudo chmod 755 /etc/openvpn/client
# ── Backend ───────────────────────────────────────────────────────────────────
echo "==> Installing backend to $INSTALL_DIR..."
mkdir -p "$INSTALL_DIR"
# stop the live service before replacing its tree: Restart=on-failure would
# restart ExecStart against a half-copied src (tolerated on first install:
# no unit or user bus yet)
systemctl --user stop omarchy-vpn-backend.service 2>/dev/null || true
rm -rf "$INSTALL_DIR/src"
cp -r "$REPO_DIR/src" "$INSTALL_DIR/"
# the widget compares it with its plugin dir's HEAD after `omarchy plugin update`
git -C "$REPO_DIR" rev-parse HEAD > "$INSTALL_DIR/installed-commit" 2>/dev/null \
|| rm -f "$INSTALL_DIR/installed-commit"
# autostarted WireGuard tunnels come up before login: a drop-in turns IPv6 off
# first (⚙ IPv6 guard) — profiles whose autostart predates this release too
python3 "$INSTALL_DIR/src/vpn_manager.py" --ipv6-boot-sync || echo " (re-run later: python3 $INSTALL_DIR/src/vpn_manager.py --ipv6-boot-sync)"
# ── systemd user service (status backend) ─────────────────────────────────────
# Rootless per-user daemon serving --status/--servers over $XDG_RUNTIME_DIR.
# The unit copies only after the backend copy above is complete, so an upgrade
# never lets the old service start against a partial copy; daemon-reload →
# enable → restart is idempotent, the same on first install and upgrade.
# fail-stop, never a silent degrade: without its user service this feature is
# incomplete, so a lifecycle failure (e.g. no systemd user bus) must say so
backend_lifecycle() {
systemctl --user "$@" && return
echo "==> Setup failed: 'systemctl --user $*' did not run — is the systemd user bus" >&2
echo " available (loginctl session, dbus)? The status backend needs its user" >&2
echo " service; fix the bus and re-run setup." >&2
exit 1
}
echo "==> Installing omarchy-vpn-backend user service..."
mkdir -p "$HOME/.config/systemd/user"
cp "$REPO_DIR/systemd/omarchy-vpn-backend.service" "$HOME/.config/systemd/user/omarchy-vpn-backend.service"
backend_lifecycle daemon-reload
backend_lifecycle enable omarchy-vpn-backend.service
backend_lifecycle restart omarchy-vpn-backend.service
# ── omarchy-shell bar widget ──────────────────────────────────────────────────
# `omarchy plugin add` clones this repo into $PLUGIN_DIR and the panel's
# Finish setup runs this script from there: nothing to copy then.
if [[ "$REPO_DIR" -ef "$PLUGIN_DIR" ]]; then
echo "==> Bar widget: running from $PLUGIN_DIR (omarchy plugin add)"
else
echo "==> Installing bar widget to $PLUGIN_DIR..."
mkdir -p "$PLUGIN_DIR"
cp "$REPO_DIR/manifest.json" "$REPO_DIR"/*.qml "$PLUGIN_DIR/"
fi
omarchy-shell -q shell rescanPlugins
if ! omarchy plugin list | grep -qE "^${PLUGIN_ID}[[:space:]]+enabled"; then
omarchy plugin enable "$PLUGIN_ID" --before omarchy.network \
|| omarchy plugin enable "$PLUGIN_ID" --section right \
|| echo " could not enable it — run: omarchy plugin enable $PLUGIN_ID"
fi
# the hot reload keeps an already-built widget on its old code (new IPC methods missing)
if omarchy-shell shell ping >/dev/null 2>&1; then
omarchy restart shell >/dev/null || echo " restart the shell to load the new widget: omarchy restart shell"
fi
# ── Keybinding (Hyprland Lua config) ──────────────────────────────────────────
# Rewritten on every install: an older block opened the omarchy.menu menu.
BINDINGS="$HOME/.config/hypr/bindings.lua"
if [[ -f "$BINDINGS" ]]; then
echo "==> SUPER+Shift+V opens the VPN window ($BINDINGS)"
sed -i '/^-- >>> omarchy-vpn$/,/^-- <<< omarchy-vpn$/d' "$BINDINGS"
cat >> "$BINDINGS" <<EOF
-- >>> omarchy-vpn
o.bind("SUPER + SHIFT + V", "VPN window", "omarchy-shell -q $PLUGIN_ID window")
o.window({ class = "^org.quickshell$", title = "^VPN( Check)?$" }, { tag = "+floating-window" })
-- <<< omarchy-vpn
EOF
else
echo "==> bindings.lua missing, skipping the SUPER+Shift+V binding."
fi
# ── Legacy waybar install ─────────────────────────────────────────────────────
# A running Happ/Keys keeper was started from the old copy: leave it until
# nothing runs from there (reconnect once, then re-run make install).
if [[ -d "$LEGACY_DIR" ]]; then
if pgrep -f "$LEGACY_DIR/src/" >/dev/null; then
echo "==> $LEGACY_DIR is still in use by a running connection — kept."
echo " Reconnect from the bar panel, then run 'make install' again to remove it."
else
echo "==> Removing the old waybar install ($LEGACY_DIR)..."
rm -rf "$LEGACY_DIR"
rm -f "$HOME/.config/waybar/scripts/vpn-status.sh" "$HOME/.config/waybar/scripts/vpn-menu.sh"
fi
fi
# ── Final hints ───────────────────────────────────────────────────────────────
echo ""
echo "==> Done!"
echo " - bar widget: omarchy plugin enable/disable $PLUGIN_ID, move with omarchy bar move"
echo " - keybinding: SUPER+Shift+V opens the VPN window"
echo " - settings: the window's Settings button, or re-run this installer"
HINTS=$(python3 -B -c "
import sys
sys.path.insert(0, '$REPO_DIR/src')
import config
from installwizard import detect, hints
for line in hints(config.load_config(), detect()):
print(line)
" 2>/dev/null) || true
if [[ -n $HINTS ]]; then
echo ""
echo "$HINTS" | sed 's/^/ /'
fi
echo ""