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:
David Young
2026-11-08 09:55:13 -07:00
co-authored by Claude Opus 5.5
parent ebda32d567
commit 0b471c9771
26 changed files with 1525 additions and 1015 deletions
+98
View File
@@ -0,0 +1,98 @@
#!/usr/bin/env bats
#
# update.sh as run on first install (by install.sh) and on later updates
# (by CoreDesktop's `update`)
load helpers
setup() {
setup_fake_home
fake_coredesktop
# No apps to download or build; those scripts have their own tests
export HAMPACK_BINARIES_CONF="$BATS_TEST_TMPDIR/empty.conf"
export HAMPACK_COMPILE_CONF="$BATS_TEST_TMPDIR/empty.conf"
: > "$HAMPACK_BINARIES_CONF"
local data="$BATS_TEST_TMPDIR/uv-tools/not1mm/lib/python3.13/site-packages/not1mm/data"
mkdir -p "$data"
touch "$data/k6gte-not1mm.desktop"
export UV_TOOL_DIR="$BATS_TEST_TMPDIR/uv-tools"
stub uv '
case "$1 $2" in
"tool list") [ -f "$HOME/not1mm" ] && echo "not1mm v1.0" ;;
"tool install") touch "$HOME/not1mm" ;;
"tool dir") echo "$UV_TOOL_DIR" ;;
esac
exit 0'
}
@test "first install records only the packages and Flatpaks it installed" {
mark_installed cmake wine
run bash "$REPO/update.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"HamPack updated."* ]]
# Everything on the list is installed now
local pkg
for pkg in $(all_hampack_packages); do [ -f "$FAKE_PACMAN_DB/$pkg" ]; done
# but what was there before isn't recorded as HamPack's
! grep -qx cmake "$HAMPACK_STATE/installed-packages"
! grep -qx wine "$HAMPACK_STATE/installed-packages"
grep -qx hamlib "$HAMPACK_STATE/installed-packages"
[ "$(wc -l < "$HAMPACK_STATE/installed-flatpaks")" -eq "$(all_hampack_flatpaks | wc -l)" ]
grep -qx "uv tool install not1mm" "$STUB_LOG"
[ -x "$HOME/.local/bin/hampackremove" ]
}
@test "a later update installs and records nothing new" {
bash "$REPO/update.sh"
cp "$HAMPACK_STATE/installed-packages" "$BATS_TEST_TMPDIR/before"
: > "$STUB_LOG"
run bash "$REPO/update.sh"
[ "$status" -eq 0 ]
! grep -q '^yay -S' "$STUB_LOG"
! grep -q '^flatpak install' "$STUB_LOG"
grep -qx "uv tool upgrade not1mm" "$STUB_LOG"
cmp "$HAMPACK_STATE/installed-packages" "$BATS_TEST_TMPDIR/before"
}
@test "an update after install from before records: existing packages aren't claimed" {
local pkg
for pkg in $(all_hampack_packages); do mark_installed "$pkg"; done
run bash "$REPO/update.sh"
[ "$status" -eq 0 ]
[ ! -s "$HAMPACK_STATE/installed-packages" ]
}
@test "update removes stale state from older HamPack versions" {
mkdir -p "$HAMPACK_STATE"
printf 'Kiwix-Desktop=2.75.1\nkiwix-desktop=2.5.1\nKiwix-Tools=3.8.2\n' > "$HAMPACK_STATE/.installed_versions"
touch "$HOME/.local/bin/hampackupdate"
run bash "$REPO/update.sh"
[ "$(cat "$HAMPACK_STATE/.installed_versions")" = "kiwix-desktop=2.5.1" ]
[ ! -e "$HOME/.local/bin/hampackupdate" ]
grep -qx "sudo rm -f /etc/sudoers.d/hampack" "$STUB_LOG"
}
@test "graywolf's service is installed and enabled once graywolf is built" {
run bash "$REPO/update.sh"
! grep -q "graywolf.service" "$STUB_LOG"
touch "$HOME/.local/bin/graywolf"
chmod +x "$HOME/.local/bin/graywolf"
: > "$STUB_LOG"
run bash "$REPO/update.sh"
[ "$status" -eq 0 ]
grep -qx "sudo tee /etc/systemd/system/graywolf.service" "$STUB_LOG"
grep -qx "enable_services graywolf" "$STUB_LOG"
}
@test "the graywolf web UI listens only on this machine" {
grep -q -- "-http 127.0.0.1:8080" "$REPO/systemd/graywolf.service"
}
@test "a failing step is reported and the rest still run" {
stub flatpak 'exit 1'
run bash "$REPO/update.sh"
[ "$status" -eq 1 ]
[[ "$output" == *"errors in: Installing Flatpak applications"* ]]
grep -qx "uv tool install not1mm" "$STUB_LOG"
}