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
+93
View File
@@ -0,0 +1,93 @@
#!/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" ]
}
+108
View File
@@ -0,0 +1,108 @@
# Shared setup for HamPack's bats tests. Each test gets a fake $HOME, and
# commands that would touch the system (sudo, pacman, flatpak, systemctl...) are
# replaced by stubs that log their arguments to $STUB_LOG.
REPO="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)"
setup_fake_home() {
export HOME="$BATS_TEST_TMPDIR/home"
export USER="${USER:-tester}"
export TMPDIR="$BATS_TEST_TMPDIR/tmp"
export HAMPACK_DIR="$REPO"
export HAMPACK_STATE="$HOME/.local/state/HamPack"
export STUB_DIR="$BATS_TEST_TMPDIR/stubs"
export STUB_LOG="$BATS_TEST_TMPDIR/stub.log"
# Fake pacman database: one file per installed package; a file containing
# "dep" means it was installed as a dependency
export FAKE_PACMAN_DB="$BATS_TEST_TMPDIR/pacman-db"
export FAKE_FLATPAKS="$BATS_TEST_TMPDIR/flatpaks"
unset DISPLAY WAYLAND_DISPLAY WINEPREFIX
mkdir -p "$HOME/.local/bin" "$TMPDIR" "$STUB_DIR" "$FAKE_PACMAN_DB" "$FAKE_FLATPAKS"
: > "$STUB_LOG"
PATH="$STUB_DIR:$PATH"
# Commands that just log and succeed
local cmd
for cmd in systemctl udevadm groupadd yay update-desktop-database update-mime-database \
xdg-icon-resource xdg-desktop-menu wine wineboot winetricks xdotool; do
stub "$cmd" 'exit 0'
done
# sudo runs stubbed commands and only logs the rest, so tests never change the system
stub sudo '
case "$1" in -v|-n) exit 0 ;; esac
if [ -x "$STUB_DIR/$1" ]; then "$@"; else exit 0; fi'
stub pacman '
case "$1" in
-Qi|-Q|-Qq)
shift; status=0
for p in "$@"; do
if [ -f "$FAKE_PACMAN_DB/$p" ]; then [ "$1" = -Qi ] || echo "$p"; else status=1; fi
done
exit $status ;;
-Qg) exit 1 ;;
-Qdq)
shift; for p in "$@"; do grep -qx dep "$FAKE_PACMAN_DB/$p" 2>/dev/null && echo "$p"; done; exit 0 ;;
-Qdtq)
for f in "$FAKE_PACMAN_DB"/*; do
[ -f "$f" ] || continue
p="$(basename "$f")"
grep -qx dep "$f" && ! grep -qx "$p" "$FAKE_PACMAN_DB"/.required 2>/dev/null && echo "$p"
done; exit 0 ;;
-D)
mode="$2"; shift 2
for p in "$@"; do
if [ "$mode" = --asdeps ]; then echo dep > "$FAKE_PACMAN_DB/$p"; else : > "$FAKE_PACMAN_DB/$p"; fi
done ;;
-Rns)
shift; for p in "$@"; do [ "$p" = --noconfirm ] || rm -f "$FAKE_PACMAN_DB/$p"; done ;;
esac
exit 0'
stub flatpak '
case "$1" in
info) [ -f "$FAKE_FLATPAKS/$2" ] ;;
install) for p in "$@"; do :; done; touch "$FAKE_FLATPAKS/$p" ;;
uninstall) for p in "$@"; do rm -f "$FAKE_FLATPAKS/$p"; done ;;
esac'
}
# Create a stub command: stub NAME BODY. Every call is logged as "NAME ARGS".
stub() {
printf '#!/bin/bash\necho "%s $*" >> "$STUB_LOG"\n%s\n' "$1" "$2" > "$STUB_DIR/$1"
chmod +x "$STUB_DIR/$1"
}
# A minimal CoreDesktop: the utils.sh functions HamPack uses, backed by the fake pacman
fake_coredesktop() {
local cd="$HOME/.local/share/coredesktop"
mkdir -p "$cd"
printf 'SYSTEM_UTILS=(\n coredesktop-pkg\n)\n' > "$cd/packages.conf"
cat > "$cd/utils.sh" << 'EOF'
is_installed() { [ -f "$FAKE_PACMAN_DB/$1" ]; }
without_skipped() { printf '%s\n' "$@"; }
install_packages() {
local p
for p in "$@"; do
[ -f "$FAKE_PACMAN_DB/$p" ] || { echo "yay -S $p" >> "$STUB_LOG"; : > "$FAKE_PACMAN_DB/$p"; }
done
}
enable_services() { echo "enable_services $*" >> "$STUB_LOG"; }
install_script() { cp "$1" "$2" && chmod 755 "$2"; }
remove_flatpaks() { local p; for p in "$@"; do echo "remove_flatpaks $p" >> "$STUB_LOG"; rm -f "$FAKE_FLATPAKS/$p"; done; }
EOF
}
mark_installed() {
local p
for p in "$@"; do : > "$FAKE_PACMAN_DB/$p"; done
}
# All packages and Flatpaks in packages.conf
all_hampack_packages() {
(source "$REPO/packages.conf"; printf '%s\n' "${UTILITIES[@]}" "${APPLICATIONS[@]}")
}
all_hampack_flatpaks() {
(source "$REPO/packages.conf"; printf '%s\n' "${FLATPAKS[@]}")
}
+88
View File
@@ -0,0 +1,88 @@
#!/usr/bin/env bats
load helpers
setup() {
setup_fake_home
SRC="$BATS_TEST_TMPDIR/src"
mkdir -p "$SRC"
echo "v1" > "$SRC/tool"
SHA="$(sha256sum "$SRC/tool" | cut -d' ' -f1)"
export HAMPACK_BINARIES_CONF="$BATS_TEST_TMPDIR/binaries.conf"
}
write_conf() {
cat > "$HAMPACK_BINARIES_CONF" << EOF
[tool]
version=$1
url=file://$SRC/tool
sha256=$2
install=\$HOME/.local/bin/tool
gui=true
comment=A test tool
icon=\$HAMPACK_DIR/desktop/icons/paracon.png
EOF
}
@test "first install downloads, verifies, records the version and writes the desktop file" {
write_conf 1.0 "$SHA"
run bash "$REPO/install-binaries.sh"
[ "$status" -eq 0 ]
[ -x "$HOME/.local/bin/tool" ]
[ "$(cat "$HAMPACK_STATE/.installed_versions")" = "tool=1.0" ]
grep -qx "Categories=HamRadio;" "$HOME/.local/share/applications/tool.desktop"
grep -qx "Icon=$REPO/desktop/icons/paracon.png" "$HOME/.local/share/applications/tool.desktop"
}
@test "a download that doesn't match its sha256 isn't installed" {
write_conf 1.0 0000000000000000000000000000000000000000000000000000000000000000
run bash "$REPO/install-binaries.sh"
[ "$status" -eq 1 ]
[[ "$output" == *"doesn't match its sha256"* ]]
[ ! -e "$HOME/.local/bin/tool" ]
[ -z "$(grep tool= "$HAMPACK_STATE/.installed_versions" 2> /dev/null)" ]
}
@test "a failed update keeps the installed binary" {
write_conf 1.0 "$SHA"
bash "$REPO/install-binaries.sh"
write_conf 2.0 0000000000000000000000000000000000000000000000000000000000000000
run bash "$REPO/install-binaries.sh"
[ "$status" -eq 1 ]
[ "$(cat "$HOME/.local/bin/tool")" = "v1" ]
grep -qx "tool=1.0" "$HAMPACK_STATE/.installed_versions"
}
@test "update with nothing new downloads nothing but refreshes the desktop file" {
write_conf 1.0 "$SHA"
bash "$REPO/install-binaries.sh"
rm "$SRC/tool" "$HOME/.local/share/applications/tool.desktop"
run bash "$REPO/install-binaries.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"up to date"* ]]
[ -f "$HOME/.local/share/applications/tool.desktop" ]
}
@test "update with a new version downloads it" {
write_conf 1.0 "$SHA"
bash "$REPO/install-binaries.sh"
echo "v2" > "$SRC/tool"
write_conf 2.0 "$(sha256sum "$SRC/tool" | cut -d' ' -f1)"
run bash "$REPO/install-binaries.sh"
[ "$status" -eq 0 ]
[ "$(cat "$HOME/.local/bin/tool")" = "v2" ]
grep -qx "tool=2.0" "$HAMPACK_STATE/.installed_versions"
}
@test "an installed binary with no recorded version is reinstalled" {
write_conf 1.0 "$SHA"
echo stale > "$HOME/.local/bin/tool"
run bash "$REPO/install-binaries.sh"
[ "$status" -eq 0 ]
[ "$(cat "$HOME/.local/bin/tool")" = "v1" ]
}
@test "binaries.conf entries all have a sha256" {
run grep -c '^sha256=' "$REPO/binaries.conf"
[ "$output" -eq "$(grep -c '^\[' "$REPO/binaries.conf")" ]
}
+127
View File
@@ -0,0 +1,127 @@
#!/usr/bin/env bats
load helpers
setup() {
setup_fake_home
export HAMPACK_COMPILE_CONF="$BATS_TEST_TMPDIR/compile.conf"
REPO_URL="file://$BATS_TEST_TMPDIR/upstream"
git init -q "$BATS_TEST_TMPDIR/upstream"
git -C "$BATS_TEST_TMPDIR/upstream" -c user.email=t@t -c user.name=t commit -q --allow-empty -m init
}
@test "first install builds each app and records its version" {
cat > "$HAMPACK_COMPILE_CONF" << EOF
[app]
version=1.0
git=$REPO_URL
install=\$HOME/.local/bin/app
gui=true
desktop=\$HAMPACK_DIR/desktop/yaac.desktop
steps=mkdir sub, cd sub, touch \$HOME/.local/bin/app
EOF
run bash "$REPO/install-compiled.sh"
[ "$status" -eq 0 ]
[ -f "$HOME/.local/bin/app" ]
grep -qx "app=1.0" "$HAMPACK_STATE/.installed_versions"
grep -q "Icon=$REPO/desktop/icons/yaaclogo.png" "$HOME/.local/share/applications/yaac.desktop"
}
@test "a failing step stops that build, records nothing, and later apps still build" {
cat > "$HAMPACK_COMPILE_CONF" << EOF
[bad]
version=1.0
git=$REPO_URL
install=\$HOME/.local/bin/bad
steps=true, false, touch \$HOME/.local/bin/bad
[good]
version=2.0
git=$REPO_URL
install=\$HOME/.local/bin/good
steps=touch \$HOME/.local/bin/good
EOF
run bash "$REPO/install-compiled.sh"
[ "$status" -eq 1 ]
[[ "$output" == *"step failed: false"* ]]
[[ "$output" == *"Failed to install: bad"* ]]
[ ! -e "$HOME/.local/bin/bad" ]
[ -f "$HOME/.local/bin/good" ]
! grep -q "^bad=" "$HAMPACK_STATE/.installed_versions"
}
@test "update skips up-to-date apps without fetching, but refreshes desktop files" {
cat > "$HAMPACK_COMPILE_CONF" << EOF
[app]
version=1.0
git=file:///nonexistent
install=\$HOME/.local/bin/app
desktop=\$HAMPACK_DIR/desktop/yaac.desktop
steps=false
EOF
touch "$HOME/.local/bin/app"
mkdir -p "$HAMPACK_STATE"
echo "app=1.0" > "$HAMPACK_STATE/.installed_versions"
run bash "$REPO/install-compiled.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"up to date"* ]]
[ -f "$HOME/.local/share/applications/yaac.desktop" ]
}
@test "update rebuilds when the version changes or isn't recorded, without asking" {
cat > "$HAMPACK_COMPILE_CONF" << EOF
[changed]
version=2.0
git=$REPO_URL
install=\$HOME/.local/bin/changed
steps=echo built > \$HOME/.local/bin/changed
[unrecorded]
version=1.0
git=$REPO_URL
install=\$HOME/.local/bin/unrecorded
steps=echo built > \$HOME/.local/bin/unrecorded
EOF
touch "$HOME/.local/bin/changed" "$HOME/.local/bin/unrecorded"
mkdir -p "$HAMPACK_STATE"
echo "changed=1.0" > "$HAMPACK_STATE/.installed_versions"
run bash "$REPO/install-compiled.sh" < /dev/null
[ "$status" -eq 0 ]
[ "$(cat "$HOME/.local/bin/changed")" = built ]
[ "$(cat "$HOME/.local/bin/unrecorded")" = built ]
grep -qx "changed=2.0" "$HAMPACK_STATE/.installed_versions"
}
@test "a step that reads stdin doesn't eat the rest of compile.conf" {
cat > "$HAMPACK_COMPILE_CONF" << EOF
[first]
version=1.0
git=$REPO_URL
install=\$HOME/.local/bin/first
steps=cat, touch \$HOME/.local/bin/first
[second]
version=1.0
git=$REPO_URL
install=\$HOME/.local/bin/second
steps=touch \$HOME/.local/bin/second
EOF
run bash "$REPO/install-compiled.sh"
[ "$status" -eq 0 ]
[ -f "$HOME/.local/bin/second" ]
}
@test "an app missing version= fails instead of prompting" {
printf '[app]\ngit=%s\ninstall=$HOME/x\nsteps=true\n' "$REPO_URL" > "$HAMPACK_COMPILE_CONF"
run bash "$REPO/install-compiled.sh" < /dev/null
[ "$status" -eq 1 ]
[[ "$output" == *"needs version="* ]]
}
@test "the build directory is private and removed afterwards" {
printf '[app]\nversion=1\ngit=%s\ninstall=$HOME/.local/bin/app\nsteps=pwd > $HOME/dir, touch $HOME/.local/bin/app\n' "$REPO_URL" > "$HAMPACK_COMPILE_CONF"
run bash "$REPO/install-compiled.sh"
[ "$status" -eq 0 ]
[[ "$(cat "$HOME/dir")" == "$TMPDIR"/hampack.* ]]
[ ! -e "$(cat "$HOME/dir")" ]
}
+85
View File
@@ -0,0 +1,85 @@
#!/usr/bin/env bats
#
# install-windows-apps.sh, install-flatpaks.sh and patch-potacat.sh
load helpers
setup() {
setup_fake_home
fake_coredesktop
stub curl 'exit 1'
}
install_all_windows_apps() {
local c="$HOME/.wine/drive_c"
mkdir -p "$c/VARA" "$c/VARA FM" "$c/RMS Express"
touch "$c/VARA/VARA.exe" "$c/VARA/VARA Terminal.exe" "$c/VARA FM/VARAFM.exe" "$c/RMS Express/RMS Express.exe"
}
@test "windows apps: when all are installed, nothing is downloaded or run" {
install_all_windows_apps
export DISPLAY=:0
run bash "$REPO/install-windows-apps.sh"
[ "$status" -eq 0 ]
! grep -qE '^(curl|winetricks|wine) ' "$STUB_LOG"
}
@test "windows apps: VARA Terminal is installed even when VARA HF is" {
install_all_windows_apps
rm "$HOME/.wine/drive_c/VARA/VARA Terminal.exe"
export DISPLAY=:0
run bash "$REPO/install-windows-apps.sh"
[[ "$output" == *"VARA HF is already installed"* ]]
[[ "$output" == *"VARA Terminal was not installed"* ]]
grep -q "^curl .*VARA%20Products" "$STUB_LOG"
}
@test "windows apps: without a desktop session, nothing is downloaded and the update isn't failed" {
run bash "$REPO/install-windows-apps.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"without a desktop session"* ]]
! grep -q '^curl ' "$STUB_LOG"
}
@test "windows apps: winetricks runs only once" {
export DISPLAY=:0
mkdir -p "$HOME/.wine"
bash "$REPO/install-windows-apps.sh" || true
bash "$REPO/install-windows-apps.sh" || true
[ "$(grep -c '^winetricks ' "$STUB_LOG")" -eq 1 ]
}
@test "flatpaks: installs missing ones from flathub and records only those" {
local first second
first="$(all_hampack_flatpaks | sed -n 1p)"
second="$(all_hampack_flatpaks | sed -n 2p)"
touch "$FAKE_FLATPAKS/$first"
run bash "$REPO/install-flatpaks.sh"
[ "$status" -eq 0 ]
grep -qx "flatpak install --system --noninteractive flathub $second" "$STUB_LOG"
[ "$(cat "$HAMPACK_STATE/installed-flatpaks")" = "$second" ]
}
@test "flatpaks: update with everything installed installs nothing" {
local pak
for pak in $(all_hampack_flatpaks); do touch "$FAKE_FLATPAKS/$pak"; done
run bash "$REPO/install-flatpaks.sh"
[ "$status" -eq 0 ]
! grep -q '^flatpak install' "$STUB_LOG"
}
@test "patch-potacat removes deb and rpm targets in both forms" {
local pkg="$BATS_TEST_TMPDIR/package.json"
echo '{"build":{"linux":{"target":["AppImage","deb",{"target":"rpm"}],"category":"Utility"}}}' > "$pkg"
run bash "$REPO/patch-potacat.sh" "$pkg"
[ "$status" -eq 0 ]
[ "$(jq -c '.build.linux' "$pkg")" = '{"target":["AppImage"],"category":"Utility"}' ]
}
@test "patch-potacat leaves a package.json without targets alone" {
local pkg="$BATS_TEST_TMPDIR/package.json"
echo '{"name":"x"}' > "$pkg"
run bash "$REPO/patch-potacat.sh" "$pkg"
[ "$status" -eq 0 ]
[ "$(jq -c . "$pkg")" = '{"name":"x"}' ]
}
+105
View File
@@ -0,0 +1,105 @@
#!/usr/bin/env bats
load helpers
setup() {
setup_fake_home
source "$REPO/lib.sh"
}
@test "expand_vars replaces only HOME, HAMPACK_DIR and USER" {
run expand_vars 'python $HOME/x.pyz; $HAMPACK_DIR/icon.png $USER'
[ "$output" = "python $HOME/x.pyz; $REPO/icon.png $USER" ]
}
@test "expand_vars keeps semicolons, quotes and spacing" {
run expand_vars "HamRadio;Utility;"
[ "$output" = "HamRadio;Utility;" ]
run expand_vars "it's (two spaces) & \$OTHER"
[ "$output" = "it's (two spaces) & \$OTHER" ]
}
collect() { SEEN+=("${CONF[_name]}:${CONF[version]}:${CONF[url]}"); }
@test "parse_conf calls back once per section, including the last, skipping comments" {
cat > "$BATS_TEST_TMPDIR/t.conf" << 'EOF'
# a comment
[one]
version=1
url=https://a/b?c=d=e
# an indented comment
[two]
version=2
EOF
SEEN=()
parse_conf "$BATS_TEST_TMPDIR/t.conf" collect
[ "${#SEEN[@]}" -eq 2 ]
[ "${SEEN[0]}" = "one:1:https://a/b?c=d=e" ]
[ "${SEEN[1]}" = "two:2:" ]
}
uses_regex() { [[ "x" =~ (x) ]]; SEEN+=("${CONF[_name]}"); }
@test "parse_conf section names survive callbacks that use =~" {
printf '[a]\n[b]\n[c]\n' > "$BATS_TEST_TMPDIR/t.conf"
SEEN=()
parse_conf "$BATS_TEST_TMPDIR/t.conf" uses_regex
[ "${SEEN[*]}" = "a b c" ]
}
swallow_stdin() { cat > /dev/null; SEEN+=("${CONF[_name]}"); }
@test "parse_conf callbacks can't swallow the rest of the file through stdin" {
printf '[a]\nx=1\n[b]\nx=2\n[c]\nx=3\n' > "$BATS_TEST_TMPDIR/t.conf"
SEEN=()
parse_conf "$BATS_TEST_TMPDIR/t.conf" swallow_stdin < /dev/null
[ "${SEEN[*]}" = "a b c" ]
}
@test "versions are saved, replaced and forgotten by exact name" {
save_installed_version dx.py abc
save_installed_version dxApy other
save_installed_version dx.py def
[ "$(get_recorded_version dx.py)" = "def" ]
[ "$(get_recorded_version dxApy)" = "other" ]
[ "$(grep -c '^dx\.py=' "$VERSION_FILE")" -eq 1 ]
forget_version dx.py
[ -z "$(get_recorded_version dx.py)" ]
[ "$(get_recorded_version dxApy)" = "other" ]
}
@test "get_recorded_version prints nothing without a version file" {
run get_recorded_version anything
[ "$status" -eq 0 ]
[ -z "$output" ]
}
@test "record_installed keeps a sorted list without duplicates" {
record_installed installed-packages b a
record_installed installed-packages a c
record_installed installed-packages
[ "$(recorded_installs installed-packages | tr '\n' ' ')" = "a b c " ]
}
@test "install_staged copies home files as the user, uses sudo outside home, and writes a manifest" {
local stage="$BATS_TEST_TMPDIR/stage"
mkdir -p "$stage$HOME/.local/bin" "$stage/etc/udev/rules.d"
echo new > "$stage$HOME/.local/bin/tool"
echo rule > "$stage/etc/udev/rules.d/99-test.rules"
echo old > "$HOME/.local/bin/tool"
HAMPACK_APP=testapp install_staged "$stage"
[ "$(cat "$HOME/.local/bin/tool")" = "new" ]
grep -qx "sudo cp -P --remove-destination $stage/etc/udev/rules.d/99-test.rules /etc/udev/rules.d/99-test.rules" "$STUB_LOG"
grep -qx "$HOME/.local/bin/tool" "$HAMPACK_STATE/manifests/testapp"
grep -qx "/etc/udev/rules.d/99-test.rules" "$HAMPACK_STATE/manifests/testapp"
}
@test "install_staged needs HAMPACK_APP" {
mkdir -p "$BATS_TEST_TMPDIR/stage"
unset HAMPACK_APP
run install_staged "$BATS_TEST_TMPDIR/stage"
[ "$status" -ne 0 ]
}
+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"
}