refactor(uninstall): drop repo uninstall.sh; init.sh generates the command

Remove the redundant repo-root uninstall.sh (it duplicated libreportal-uninstall).
init.sh now GENERATES the libreportal-uninstall launcher into the fixed footprint
(/usr/local/lib/libreportal/uninstall.sh + the /usr/local/bin symlink) — same
pattern as the CLI wrapper, so the on-box command survives without a separate repo
file. The launcher just runs the engine's uninstall ($script_dir/init.sh baked in,
/root/init.sh fallback).

This resolves the install/uninstall asymmetry: a bootstrap (install.sh) exists only
because install faces a bare box with no code yet; uninstall always runs the engine
that's already installed, so it needs no bootstrap — just a generated door into
init.sh. Repo root install/uninstall surface is now init.sh + install.sh.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
This commit is contained in:
librelad 2026-05-25 18:59:38 +01:00
parent 94d91ff551
commit f2c2b0485a
2 changed files with 16 additions and 42 deletions

21
init.sh
View File

@ -1468,13 +1468,22 @@ EOF
# Put it on $PATH via a symlink (replaces any older real file at this path).
sudo ln -sfn "$command_script" "$command_symlink"
# Install the uninstaller at the fixed footprint + put it on $PATH as
# `libreportal-uninstall` — a location-agnostic command (it resolves the real
# data roots from the systemd unit at run time), so users never type a data path.
if [[ -f "$script_dir/uninstall.sh" ]]; then
sudo install -m 0755 -o root -g root "$script_dir/uninstall.sh" "$lp_lib_dir/uninstall.sh"
# Generate the uninstall command at the fixed footprint + put it on $PATH as
# `libreportal-uninstall` (same idea as the CLI wrapper above — generated by
# init.sh, not a separate repo file). It just runs the engine's uninstall, so
# users never type a data path. $script_dir is baked in; /root/init.sh is a
# fallback if the install tree is already gone.
sudo tee "$lp_lib_dir/uninstall.sh" >/dev/null <<EOF
#!/usr/bin/env bash
# LibrePortal uninstall command — generated by init.sh. Runs the engine's uninstall.
[[ \$EUID -eq 0 ]] || { echo "libreportal-uninstall must run as root (try: sudo)"; exit 1; }
_init="$script_dir/init.sh"; [[ -f "\$_init" ]] || _init="/root/init.sh"
[[ -f "\$_init" ]] || { echo "Cannot find init.sh to run the uninstall."; exit 1; }
exec bash "\$_init" "\$@" uninstall
EOF
sudo chmod 0755 "$lp_lib_dir/uninstall.sh"
sudo chown root:root "$lp_lib_dir/uninstall.sh"
sudo ln -sfn "$lp_lib_dir/uninstall.sh" /usr/local/bin/libreportal-uninstall
fi
source $sudo_bashrc
}

View File

@ -1,35 +0,0 @@
#!/usr/bin/env bash
#
# LibrePortal uninstaller — convenience launcher.
#
# sudo ./uninstall.sh # remove everything
# sudo ./uninstall.sh --skip-docker-images # keep the rootless docker layer
#
# The real teardown lives in init.sh (runFullUninstall), which self-resolves the
# install's actual roots/manager from the baked systemd unit — so this just finds
# the installed init.sh and runs it. Works regardless of where LibrePortal was
# installed (custom --system-dir, etc.).
set -euo pipefail
[[ $EUID -eq 0 ]] || { echo "uninstall.sh must run as root (try: sudo)" >&2; exit 1; }
# Prefer the system root baked into the systemd unit; then common defaults; then
# the bootstrap copy in /root; then a sibling init.sh next to this script.
unit=/etc/systemd/system/libreportal.service
sysdir=""
[[ -f "$unit" ]] && sysdir=$(grep -oE 'LP_SYSTEM_DIR=\S+' "$unit" | head -1 | cut -d= -f2)
init=""
for cand in \
${sysdir:+"$sysdir/install/init.sh"} \
/libreportal-system/install/init.sh \
/docker/install/init.sh \
/root/init.sh \
"$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/init.sh"; do
[[ -n "$cand" && -f "$cand" ]] && { init="$cand"; break; }
done
[[ -n "$init" ]] || { echo "uninstall.sh: could not find init.sh to run the uninstall." >&2; exit 1; }
echo "Running uninstall via $init ..."
exec bash "$init" "$@" uninstall