Files
HamPack/tests/hampackremove.bats
T
David YoungandClaude Opus 5.5 0b471c9771 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>
2026-11-08 09:55:13 -07:00

94 lines
3.1 KiB
Bash

#!/usr/bin/env bats
load helpers
setup() {
setup_fake_home
fake_coredesktop
stub uv 'exit 0'
stub clear 'exit 0'
# hampackremove finds HamPack by the sibling clone's origin, and deletes it
SIBLING="$HOME/.local/share/siblings/HamPack"
mkdir -p "$SIBLING"
cp "$REPO"/{lib.sh,packages.conf,binaries.conf,compile.conf,hampackremove} "$SIBLING"/
git init -q "$SIBLING"
git -C "$SIBLING" remote add origin https://gitea.example/david/HamPack.git
}
remove() {
run bash "$REPO/hampackremove" <<< "${1:-y}"
}
@test "removes only the packages HamPack recorded, and keeps ones others need" {
mark_installed hamlib fldigi wine cmake
mkdir -p "$HAMPACK_STATE"
printf 'fldigi\nhamlib\n' > "$HAMPACK_STATE/installed-packages"
echo hamlib > "$FAKE_PACMAN_DB/.required" # something else needs hamlib
remove
[ "$status" -eq 0 ]
[ ! -e "$FAKE_PACMAN_DB/fldigi" ]
[ -e "$FAKE_PACMAN_DB/hamlib" ]
[ -e "$FAKE_PACMAN_DB/wine" ]
[ -e "$FAKE_PACMAN_DB/cmake" ]
[[ "$output" == *"Kept because other software needs them: hamlib"* ]]
[[ "$output" == *"sudo pacman -Rns"*"wine"* ]]
}
@test "removes recorded Flatpaks only" {
touch "$FAKE_FLATPAKS/io.github.foldynl.QLog" "$FAKE_FLATPAKS/io.sourceforge.wsjt.wsjtx"
mkdir -p "$HAMPACK_STATE"
echo io.github.foldynl.QLog > "$HAMPACK_STATE/installed-flatpaks"
remove
[ ! -e "$FAKE_FLATPAKS/io.github.foldynl.QLog" ]
[ -e "$FAKE_FLATPAKS/io.sourceforge.wsjt.wsjtx" ]
}
@test "removes files from manifests, conf install paths and older builds" {
mkdir -p "$HAMPACK_STATE/manifests" "$HOME/.local/share/applications" "$HOME/.local/share/doc/direwolf"
touch "$HOME/.local/bin/staged-file" "$HOME/.local/bin/paracon.pyz" "$HOME/.local/bin/QtTermTCP" \
"$HOME/.local/bin/decode_aprs" "$HOME/.local/share/applications/qttermtcp.desktop"
printf '%s\n/etc/udev/rules.d/99-x.rules\n' "$HOME/.local/bin/staged-file" > "$HAMPACK_STATE/manifests/x"
remove
[ "$status" -eq 0 ]
[ ! -e "$HOME/.local/bin/staged-file" ]
grep -qx "sudo rm -f /etc/udev/rules.d/99-x.rules" "$STUB_LOG"
[ ! -e "$HOME/.local/bin/paracon.pyz" ]
[ ! -e "$HOME/.local/bin/QtTermTCP" ]
[ ! -e "$HOME/.local/share/applications/qttermtcp.desktop" ]
[ ! -e "$HOME/.local/bin/decode_aprs" ]
[ ! -e "$HOME/.local/share/doc/direwolf" ]
}
@test "removes Wine apps but keeps a Wine prefix HamPack didn't create" {
mkdir -p "$HOME/.wine/drive_c/VARA" "$HOME/.wine/drive_c/Other"
remove
[ ! -e "$HOME/.wine/drive_c/VARA" ]
[ -d "$HOME/.wine/drive_c/Other" ]
}
@test "offers to remove a Wine prefix HamPack created" {
mkdir -p "$HOME/.wine/drive_c" "$HAMPACK_STATE"
touch "$HAMPACK_STATE/wine-prefix-created"
run bash "$REPO/hampackremove" <<< $'y\ny'
[ ! -e "$HOME/.wine" ]
}
@test "removes graywolf's service, its state and the sibling clone" {
mkdir -p "$HAMPACK_STATE"
remove
[ "$status" -eq 0 ]
[ ! -e "$HAMPACK_STATE" ]
[ ! -e "$SIBLING" ]
}
@test "does nothing unless confirmed" {
mark_installed fldigi
mkdir -p "$HAMPACK_STATE"
echo fldigi > "$HAMPACK_STATE/installed-packages"
remove n
[ -e "$FAKE_PACMAN_DB/fldigi" ]
[ -d "$SIBLING" ]
}