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
@@ -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[@]}")
|
||||
}
|
||||
Reference in New Issue
Block a user