Harden install, update and uninstall; add shared lib and tests
Updates - install-compiled.sh never prompts: unknown versions rebuild, a missing version= fails - Detect VARA Terminal by "VARA Terminal.exe" in drive_c/VARA, not by the folder VARA HF also uses - install-windows-apps.sh checks first: nothing is downloaded and winetricks doesn't run unless a product is missing, and installers only run with a desktop session - Flatpaks install system-wide from flathub and honor skip-packages - Rewrite desktop files on every run so icon paths stay right; add the missing QtTermTCP desktop file - Build steps can't read the rest of the conf through stdin Uninstall - update.sh records the packages and Flatpaks HamPack itself installed; hampackremove removes only those that nothing else needs, and lists the rest - Read package lists from packages.conf instead of copies, remove files from install manifests, conf install paths and older builds, and revert the Wine Decorated setting Security - Replace the NOPASSWD sudoers file with a sudo keepalive, and delete a leftover /etc/sudoers.d/hampack - Verify binaries.conf downloads against sha256=; pin dx.py to a commit - Graywolf's web UI listens on 127.0.0.1; update.sh manages its unit - Install direwolf and kiwix through a staging directory with install_staged, so nothing in ~/.local ends up owned by root; hand back any root-owned files left by older builds - Use private temp directories instead of fixed /tmp paths Code quality - Shared lib.sh: conf parser, variable expansion, version records, install tracking, staged installs, sudo keepalive - bats tests covering first install and update paths, Makefile with lint/test/hooks, pre-commit hook - patch-potacat.sh uses jq; drop stale kiwix version entries README: fill in what gets installed, uninstall and graywolf notes, development section, typo and Matrix link fixes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ebda32d567
commit
0b471c9771
+212
-144
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash -i
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : HamPack uninstaller
|
||||
|
||||
@@ -20,174 +20,242 @@ print_logo() {
|
||||
EOF
|
||||
}
|
||||
|
||||
COREDESKTOP="$HOME/.local/share/coredesktop"
|
||||
APPLICATIONS_DIR="$HOME/.local/share/applications"
|
||||
BIN="$HOME/.local/bin"
|
||||
|
||||
# Print the path of the HamPack clone that `sibling add` made
|
||||
find_hampack_dir() {
|
||||
local dir
|
||||
for dir in "$HOME"/.local/share/siblings/*/; do
|
||||
[ -d "$dir/.git" ] || continue
|
||||
if [[ "$(git -C "$dir" remote get-url origin 2> /dev/null)" =~ /[Hh]am[Pp]ack(\.git)?/?$ ]]; then
|
||||
echo "${dir%/}"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# Remove a file, with sudo if it's outside your home
|
||||
remove_file() {
|
||||
if [[ "$1" == "$HOME"/* ]]; then
|
||||
rm -f "$1"
|
||||
else
|
||||
sudo rm -f "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# Remove the files install_staged recorded for each app it installed
|
||||
remove_manifests() {
|
||||
local manifest file
|
||||
for manifest in "$HAMPACK_STATE"/manifests/*; do
|
||||
[ -f "$manifest" ] || continue
|
||||
while IFS= read -r file; do
|
||||
[ -n "$file" ] && remove_file "$file"
|
||||
done < "$manifest"
|
||||
done
|
||||
}
|
||||
|
||||
# parse_conf callbacks: remove each app's binary and desktop file
|
||||
remove_binary_app() {
|
||||
rm -f "$(expand_vars "${CONF[install]}")"
|
||||
[ "${CONF[gui]}" = "true" ] && rm -f "$APPLICATIONS_DIR/${CONF[_name]}.desktop"
|
||||
return 0
|
||||
}
|
||||
remove_compiled_app() {
|
||||
rm -f "$(expand_vars "${CONF[install]}")"
|
||||
[ -n "${CONF[desktop]}" ] && rm -f "$APPLICATIONS_DIR/$(basename "${CONF[desktop]}")"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Files from builds made before HamPack recorded what builds install
|
||||
remove_unrecorded_build_files() {
|
||||
local name
|
||||
# direwolf
|
||||
for name in direwolf decode_aprs text2tt tt2text ll2utm utm2ll aclients log2gpx gen_packets \
|
||||
atest ttcalc kissutil tnctest appserver cm108 dwespeak.sh telem-balloon.pl telem-bits.pl \
|
||||
telem-data.pl telem-data91.pl telem-eqns.pl telem-parm.pl telem-seq.sh telem-unit.pl telem-volts.py; do
|
||||
rm -f "$BIN/$name"
|
||||
done
|
||||
rm -f "$BIN"/direwolf-*
|
||||
for name in direwolf decode_aprs kissutil aclients atest gen_packets ll2utm log2gpx text2tt tt2text utm2ll; do
|
||||
rm -f "$HOME/.local/share/man/man1/$name.1"
|
||||
done
|
||||
rm -rf "$HOME/.local/share/direwolf" "$HOME/.local/share/doc/direwolf"
|
||||
rm -f "$APPLICATIONS_DIR/direwolf.desktop" "$HOME/.local/share/pixmaps/direwolf_icon.png"
|
||||
sudo rm -f /etc/udev/rules.d/99-direwolf-cmedia.rules
|
||||
# kiwix-desktop and kiwix-tools
|
||||
rm -f "$BIN"/kiwix-desktop "$BIN"/kiwix-serve "$BIN"/kiwix-manage "$BIN"/kiwix-search "$BIN"/kiwix-lib
|
||||
rm -f "$HOME"/.local/share/man/man1/kiwix-*.1 "$HOME"/.local/share/man/*/man1/kiwix-*.1
|
||||
rm -f "$APPLICATIONS_DIR/org.kiwix.desktop.desktop" "$HOME/.local/share/metainfo/org.kiwix.desktop.appdata.xml"
|
||||
rm -f "$HOME"/.local/share/icons/hicolor/*/apps/kiwix-desktop.* "$HOME"/.local/share/icons/hicolor/*/mimetypes/org.kiwix.desktop.*
|
||||
rm -f "$HOME/.local/share/mime/packages/org.kiwix.desktop-mime.xml"
|
||||
# graywolf, yaac, paracon
|
||||
rm -f "$BIN/graywolf-modem"
|
||||
rm -rf "$HOME/.local/share/graywolf" "$BIN/yaac"
|
||||
rm -f "$BIN"/paracon_*.pyz
|
||||
return 0
|
||||
}
|
||||
|
||||
remove_graywolf_service() {
|
||||
[ -f /etc/systemd/system/graywolf.service ] || return 0
|
||||
sudo systemctl disable --now graywolf
|
||||
sudo rm -f /etc/systemd/system/graywolf.service
|
||||
sudo systemctl daemon-reload
|
||||
}
|
||||
|
||||
remove_wine_apps() {
|
||||
local prefix="${WINEPREFIX:-$HOME/.wine}"
|
||||
[ -d "$prefix" ] || return 0
|
||||
|
||||
rm -rf "$prefix/drive_c/VARA" "$prefix/drive_c/VARA FM" "$prefix/drive_c/RMS Express"
|
||||
rm -f "$HAMPACK_STATE/wine-deps-installed"
|
||||
|
||||
if [ -f "$HAMPACK_STATE/wine-prefix-created" ]; then
|
||||
read -rp "HamPack created the Wine prefix $prefix. Remove it, with anything else installed in it? [y/N] " answer
|
||||
if [[ "$answer" =~ ^[yY] ]]; then
|
||||
rm -rf "$prefix"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
if command -v wine &> /dev/null; then
|
||||
wine reg delete 'HKCU\Software\Wine\X11 Driver' /v Decorated /f &> /dev/null
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# Remove the packages HamPack installed. They're marked as dependencies and
|
||||
# only those nothing else needs are removed, so removing HamPack can't break
|
||||
# other software. Any kept now go once nothing needs them.
|
||||
remove_recorded_packages() {
|
||||
local recorded=() installed=() orphans=() pkg
|
||||
|
||||
mapfile -t recorded < <(recorded_installs installed-packages)
|
||||
for pkg in "${recorded[@]}"; do
|
||||
[ "$(pacman -Qq "$pkg" 2> /dev/null)" = "$pkg" ] && installed+=("$pkg")
|
||||
done
|
||||
if [ ${#installed[@]} -eq 0 ]; then
|
||||
echo "No packages to remove."
|
||||
return 0
|
||||
fi
|
||||
|
||||
sudo pacman -D --asdeps "${installed[@]}" > /dev/null
|
||||
while :; do
|
||||
mapfile -t orphans < <(comm -12 <(pacman -Qdtq | sort) <(printf '%s\n' "${installed[@]}" | sort))
|
||||
[ ${#orphans[@]} -eq 0 ] && break
|
||||
echo "Removing packages: ${orphans[*]}"
|
||||
sudo pacman -Rns --noconfirm "${orphans[@]}" || break
|
||||
done
|
||||
|
||||
local kept=()
|
||||
for pkg in "${installed[@]}"; do
|
||||
pacman -Qq "$pkg" &> /dev/null && kept+=("$pkg")
|
||||
done
|
||||
[ ${#kept[@]} -eq 0 ] ||
|
||||
echo "Kept because other software needs them: ${kept[*]}"
|
||||
}
|
||||
|
||||
remove_recorded_flatpaks() {
|
||||
local recorded=()
|
||||
mapfile -t recorded < <(recorded_installs installed-flatpaks)
|
||||
[ ${#recorded[@]} -eq 0 ] || remove_flatpaks "${recorded[@]}"
|
||||
}
|
||||
|
||||
# Tell the user about packages and Flatpaks from HamPack's lists that are still
|
||||
# installed but weren't recorded as installed by HamPack: they were there
|
||||
# before HamPack, or installed before it kept records, so they're left alone
|
||||
report_unrecorded() {
|
||||
local pkg leftover=() leftover_flatpaks=() coredesktop_pkgs
|
||||
|
||||
coredesktop_pkgs="$(sed -nE 's/^[[:space:]]+([a-z0-9@._+-]+).*/\1/p' "$COREDESKTOP/packages.conf" 2> /dev/null)"
|
||||
for pkg in "${UTILITIES[@]}" "${APPLICATIONS[@]}"; do
|
||||
[ "$(pacman -Qq "$pkg" 2> /dev/null)" = "$pkg" ] || continue
|
||||
grep -qxF "$pkg" <<< "$coredesktop_pkgs" && continue
|
||||
leftover+=("$pkg")
|
||||
done
|
||||
for pkg in "${FLATPAKS[@]}"; do
|
||||
flatpak info "$pkg" &> /dev/null && leftover_flatpaks+=("$pkg")
|
||||
done
|
||||
|
||||
if [ ${#leftover[@]} -gt 0 ] || [ ${#leftover_flatpaks[@]} -gt 0 ]; then
|
||||
echo ""
|
||||
echo "These are on HamPack's list but were left in place, because HamPack has no"
|
||||
echo "record of installing them (you had them already, or they were installed"
|
||||
echo "before HamPack kept records). Remove any you don't need yourself:"
|
||||
[ ${#leftover[@]} -eq 0 ] || echo " sudo pacman -Rns ${leftover[*]}"
|
||||
[ ${#leftover_flatpaks[@]} -eq 0 ] || echo " sudo flatpak uninstall ${leftover_flatpaks[*]}"
|
||||
fi
|
||||
}
|
||||
|
||||
# --- Main ---
|
||||
|
||||
clear
|
||||
print_logo
|
||||
|
||||
echo "This will remove all packages and files installed by HamPack."
|
||||
if ! HAMPACK_DIR="$(find_hampack_dir)"; then
|
||||
echo "Couldn't find HamPack in ~/.local/share/siblings, so there's nothing to remove."
|
||||
echo "If it's installed elsewhere, run its hampackremove from there."
|
||||
exit 1
|
||||
fi
|
||||
export HAMPACK_DIR
|
||||
source "$HAMPACK_DIR/lib.sh"
|
||||
source "$COREDESKTOP/utils.sh"
|
||||
source "$HAMPACK_DIR/packages.conf"
|
||||
|
||||
echo "This will remove HamPack, the applications it installed, and the packages it"
|
||||
echo "installed that nothing else needs."
|
||||
echo ""
|
||||
read -rp "Are you sure you want to continue? [y/N] " confirm
|
||||
[[ "$confirm" =~ ^[yY] ]] || { echo "Aborted."; exit 0; }
|
||||
echo ""
|
||||
|
||||
# Stop and remove graywolf systemd service
|
||||
start_sudo_keepalive || exit 1
|
||||
|
||||
echo "Removing graywolf systemd service..."
|
||||
if systemctl is-active --quiet graywolf 2>/dev/null; then
|
||||
sudo systemctl disable --now graywolf
|
||||
fi
|
||||
if [ -f /etc/systemd/system/graywolf.service ]; then
|
||||
sudo rm -f /etc/systemd/system/graywolf.service
|
||||
sudo systemctl daemon-reload
|
||||
fi
|
||||
remove_graywolf_service
|
||||
|
||||
# Remove compiled binaries
|
||||
echo "Removing compiled binaries..."
|
||||
rm -f ~/.local/bin/direwolf
|
||||
rm -f ~/.local/bin/direwolf-*
|
||||
rm -f ~/.local/bin/QtTermTCP
|
||||
rm -f ~/.local/bin/kiwix-desktop
|
||||
rm -f ~/.local/bin/kiwix-lib
|
||||
rm -f ~/.local/bin/kiwix-serve
|
||||
rm -f ~/.local/bin/kiwix-search
|
||||
rm -f ~/.local/bin/kiwix-manage
|
||||
rm -rf ~/.local/bin/yaac
|
||||
rm -f ~/.local/bin/POTACAT.AppImage
|
||||
rm -f ~/.local/bin/JS8Call
|
||||
rm -f ~/.local/bin/dump1090
|
||||
rm -f ~/.local/bin/graywolf
|
||||
rm -f ~/.local/bin/graywolf-modem
|
||||
rm -rf ~/.local/share/graywolf
|
||||
rm -f ~/.local/bin/ardopcf_amd64_Linux_64
|
||||
rm -f ~/.local/bin/paracon.pyz ~/.local/bin/paracon_*.pyz
|
||||
echo "Removing installed applications..."
|
||||
remove_manifests
|
||||
parse_conf "$HAMPACK_DIR/binaries.conf" remove_binary_app
|
||||
parse_conf "$HAMPACK_DIR/compile.conf" remove_compiled_app
|
||||
remove_unrecorded_build_files
|
||||
sudo udevadm control --reload-rules
|
||||
|
||||
# Remove HamPack scripts and binaries
|
||||
echo "Removing HamPack scripts and binaries..."
|
||||
rm -f ~/.local/bin/hampackrefresh
|
||||
rm -f ~/.local/bin/hampackupdate
|
||||
rm -f ~/.local/bin/hampackcheck
|
||||
rm -f ~/.local/bin/hampackremove
|
||||
rm -f ~/.local/bin/hampack
|
||||
rm -f ~/.local/bin/dx.py
|
||||
echo "Removing HamPack scripts..."
|
||||
rm -f "$BIN"/hampackrefresh "$BIN"/hampackupdate "$BIN"/hampackcheck "$BIN"/hampack
|
||||
|
||||
# Uninstall not1mm
|
||||
echo "Uninstalling not1mm..."
|
||||
if command -v uv &>/dev/null; then
|
||||
uv tool uninstall not1mm 2>/dev/null || true
|
||||
if command -v uv &> /dev/null; then
|
||||
uv tool uninstall not1mm 2> /dev/null
|
||||
fi
|
||||
rm -f "$APPLICATIONS_DIR/k6gte-not1mm.desktop" "$HOME"/.local/share/icons/hicolor/*/apps/k6gte-not1mm.png
|
||||
|
||||
# Remove Flatpak applications
|
||||
echo "Removing Flatpak applications..."
|
||||
FLATPAKS=(
|
||||
"io.sourceforge.wsjt.wsjtx"
|
||||
"io.github.foldynl.QLog"
|
||||
)
|
||||
for pak in "${FLATPAKS[@]}"; do
|
||||
if flatpak list 2>/dev/null | grep -qi "$pak"; then
|
||||
flatpak uninstall --noninteractive "$pak"
|
||||
fi
|
||||
done
|
||||
|
||||
# Remove system packages
|
||||
echo "Removing system packages..."
|
||||
UTILITIES=(
|
||||
alsa-utils
|
||||
aria2
|
||||
at-spi2-core
|
||||
base-devel
|
||||
boost
|
||||
boost-libs
|
||||
cmake
|
||||
docopt
|
||||
fldigi
|
||||
flrig
|
||||
gpds
|
||||
gpsbabel
|
||||
gtk4
|
||||
hamlib
|
||||
jdk-openjdk
|
||||
libappindicator-gtk3
|
||||
libkiwix
|
||||
libtorrent-rasterbar
|
||||
libnotify
|
||||
libsecret
|
||||
libxcrypt-compat
|
||||
libxtst
|
||||
libzim
|
||||
meson
|
||||
ninja
|
||||
nss
|
||||
pat-bin
|
||||
python-yattag
|
||||
qgis
|
||||
qt6-base
|
||||
qt6-tools
|
||||
qt6-webengine
|
||||
splat
|
||||
util-linux-libs
|
||||
voacapl
|
||||
wine
|
||||
winetricks
|
||||
xdg-utils
|
||||
zim-tools
|
||||
zimwriterfs
|
||||
)
|
||||
|
||||
APPLICATIONS=(
|
||||
chattervox-bin
|
||||
chirp-next
|
||||
gridtracker2
|
||||
)
|
||||
|
||||
PACKAGES_TO_REMOVE=()
|
||||
for pkg in "${UTILITIES[@]}" "${APPLICATIONS[@]}"; do
|
||||
if pacman -Qi "$pkg" &>/dev/null; then
|
||||
PACKAGES_TO_REMOVE+=("$pkg")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#PACKAGES_TO_REMOVE[@]} -gt 0 ]; then
|
||||
echo "Removing packages: ${PACKAGES_TO_REMOVE[*]}"
|
||||
sudo pacman -Rns --noconfirm "${PACKAGES_TO_REMOVE[@]}" 2>/dev/null || \
|
||||
echo "Warning: some packages could not be removed (may be required by other software)."
|
||||
else
|
||||
echo "No system packages to remove."
|
||||
fi
|
||||
|
||||
# Remove Wine applications
|
||||
# Before packages, while Wine is still installed
|
||||
echo "Removing Wine applications..."
|
||||
rm -rf "$HOME/.wine/drive_c/VARA"
|
||||
rm -rf "$HOME/.wine/drive_c/VARA FM"
|
||||
rm -rf "$HOME/.wine/drive_c/VARA Terminal"
|
||||
rm -rf "$HOME/.wine/drive_c/RMS Express"
|
||||
remove_wine_apps
|
||||
|
||||
echo "Removing Flatpak applications..."
|
||||
remove_recorded_flatpaks
|
||||
|
||||
echo "Removing system packages..."
|
||||
remove_recorded_packages
|
||||
|
||||
# Remove desktop files
|
||||
echo "Removing desktop files..."
|
||||
rm -f ~/.local/share/applications/js8call.desktop
|
||||
rm -f ~/.local/share/applications/yaac.desktop
|
||||
rm -f ~/.local/share/applications/potacat.desktop
|
||||
rm -f ~/.local/share/applications/qttermtcp.desktop
|
||||
rm -f ~/.local/share/applications/paracon.desktop
|
||||
rm -f ~/.local/share/applications/hampack.desktop
|
||||
rm -f ~/.local/share/applications/k6gte-not1mm.desktop
|
||||
rm -f ~/.local/share/icons/hicolor/*/apps/k6gte-not1mm.png
|
||||
rm -f ~/.local/share/icons/hicolor/*/apps/computer.young.HamPack.png
|
||||
rm -f "$APPLICATIONS_DIR/hampack.desktop" "$HOME"/.local/share/icons/hicolor/*/apps/computer.young.HamPack.png
|
||||
update-desktop-database "$APPLICATIONS_DIR" 2> /dev/null
|
||||
update-mime-database "$HOME/.local/share/mime" &> /dev/null
|
||||
|
||||
update-desktop-database "$HOME/.local/share/applications/" 2>/dev/null || true
|
||||
report_unrecorded
|
||||
|
||||
# Remove HamPack state and data
|
||||
echo ""
|
||||
echo "Removing HamPack state and data..."
|
||||
rm -rf ~/.local/state/HamPack
|
||||
rm -rf ~/.local/share/HamPack
|
||||
rm -f ~/.local/share/coredesktop/updates.d/[0-9][0-9][0-9]-hampack-*
|
||||
rm -rf "$HAMPACK_STATE" "$HOME/.local/share/HamPack"
|
||||
rm -f "$COREDESKTOP"/updates.d/[0-9][0-9][0-9]-hampack-*
|
||||
rm -f "$BIN/hampackremove"
|
||||
|
||||
# Remove the sibling clone, so CoreDesktop's `update` stops updating HamPack
|
||||
for dir in ~/.local/share/siblings/*/; do
|
||||
[ -d "$dir/.git" ] || continue
|
||||
if [[ "$(git -C "$dir" remote get-url origin 2>/dev/null)" =~ /[Hh]am[Pp]ack(\.git)?/?$ ]]; then
|
||||
rm -rf "$dir"
|
||||
fi
|
||||
done
|
||||
rm -rf "$HAMPACK_DIR"
|
||||
|
||||
echo ""
|
||||
echo "HamPack has been removed."
|
||||
|
||||
Reference in New Issue
Block a user