Add install/uninstall scripts and rewrite the README around them
install.sh sets up a private virtualenv, the udev rule (group picked automatically), and optionally a systemd user service (--service) and LAN access with a subnet-limited firewalld/ufw rule (--lan). It records what it changed so uninstall.sh can undo exactly that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Executable
+64
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
# Remove everything install.sh set up: the service, firewall rule, udev rule,
|
||||
# the commands and the virtualenv. Mic settings are left as they are.
|
||||
set -euo pipefail
|
||||
|
||||
APP=dgm20-linux
|
||||
DATA=${XDG_DATA_HOME:-$HOME/.local/share}/$APP
|
||||
BIN=$HOME/.local/bin
|
||||
UNIT=${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user/dgm20-web.service
|
||||
STATE=$DATA/install.state
|
||||
DRY=0
|
||||
|
||||
case ${1:-} in
|
||||
--dry-run) DRY=1 ;;
|
||||
-h|--help) echo "Usage: ./uninstall.sh [--dry-run]"; exit 0 ;;
|
||||
"") ;;
|
||||
*) echo "unknown option: $1" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
say() { printf '\033[1m==>\033[0m %s\n' "$*"; }
|
||||
run() { if [ $DRY = 1 ]; then printf ' [dry-run] %s\n' "$*"; else "$@"; fi; }
|
||||
|
||||
[ "$(id -u)" != 0 ] || { echo "run this as your normal user, not root" >&2; exit 1; }
|
||||
|
||||
if [ -f "$STATE" ]; then
|
||||
while IFS= read -r entry; do
|
||||
kind=${entry%% *}
|
||||
arg=${entry#* }
|
||||
case $kind in
|
||||
service)
|
||||
say "Stopping the background service"
|
||||
run systemctl --user disable --now "$arg" || true
|
||||
run rm -f "$UNIT"
|
||||
run systemctl --user daemon-reload
|
||||
;;
|
||||
firewalld)
|
||||
say "Removing the firewalld rule"
|
||||
run sudo firewall-cmd --permanent --remove-rich-rule="$arg" || true
|
||||
run sudo firewall-cmd --reload
|
||||
;;
|
||||
ufw)
|
||||
read -r subnet port <<<"$arg"
|
||||
say "Removing the ufw rule"
|
||||
run sudo ufw delete allow from "$subnet" to any port "$port" proto tcp || true
|
||||
;;
|
||||
udev)
|
||||
say "Removing the udev rule, sudo needed"
|
||||
run sudo rm -f "$arg"
|
||||
run sudo udevadm control --reload
|
||||
;;
|
||||
esac
|
||||
done < <(tac "$STATE")
|
||||
else
|
||||
echo "No install record found in $STATE; removing the program files only."
|
||||
fi
|
||||
|
||||
say "Removing the program"
|
||||
for cmd in dgm20ctl dgm20-web; do
|
||||
if [ -L "$BIN/$cmd" ] && [[ $(readlink "$BIN/$cmd") == "$DATA"/* ]]; then
|
||||
run rm -f "$BIN/$cmd"
|
||||
fi
|
||||
done
|
||||
run rm -rf "$DATA"
|
||||
say "Done."
|
||||
Reference in New Issue
Block a user