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
+61 -17
View File
@@ -8,6 +8,7 @@ source "$COREDESKTOP/utils.sh"
# Config files and build steps refer to files in this repo through $HAMPACK_DIR
export HAMPACK_DIR="$SELF"
source "$SELF/lib.sh"
FAILED=()
@@ -36,6 +37,21 @@ remove_stale_files() {
rm -f "$HOME"/.local/bin/paracon_*.pyz
# Hooks from before HamPack was a sibling; 71-siblings.sh now runs this script
rm -f "$COREDESKTOP"/updates.d/[0-9][0-9][0-9]-hampack-*
# Versions recorded under app names HamPack no longer uses
forget_version Kiwix-Desktop
forget_version Kiwix-Tools
# Build directories from before builds used a private temporary directory
rm -rf /tmp/hampack-build /tmp/windowsapps 2> /dev/null
# The passwordless sudoers file the old installer used, if a killed install left it behind
sudo rm -f /etc/sudoers.d/hampack
# Builds used to run `sudo make install` into ~/.local, leaving files there owned by root
local dirs=() dir
for dir in bin lib include share/applications share/doc share/icons share/man share/metainfo share/direwolf; do
[ -d "$HOME/.local/$dir" ] && dirs+=("$HOME/.local/$dir")
done
[ ${#dirs[@]} -eq 0 ] ||
find "${dirs[@]}" -xdev -user root -print0 2> /dev/null | xargs -0 -r sudo chown -h "$USER:"
return 0
}
install_tools() {
@@ -43,24 +59,37 @@ install_tools() {
install_script "$SELF/hampackremove" "$HOME/.local/bin/hampackremove"
}
# Install the packages in packages.conf, and record the ones that weren't
# already installed, so hampackremove removes those and nothing the user had before
install_hampack_packages() {
source "$SELF/packages.conf"
install_packages "${UTILITIES[@]}" && install_packages "${APPLICATIONS[@]}"
local pkg missing=() added=() status=0
for pkg in "${UTILITIES[@]}" "${APPLICATIONS[@]}"; do
is_installed "$pkg" || missing+=("$pkg")
done
install_packages "${UTILITIES[@]}" && install_packages "${APPLICATIONS[@]}" || status=1
for pkg in "${missing[@]}"; do
is_installed "$pkg" && added+=("$pkg")
done
record_installed installed-packages "${added[@]}"
return $status
}
install_not1mm() {
if command -v uv &> /dev/null && uv tool list 2> /dev/null | grep -q '^not1mm '; then
if uv tool list 2> /dev/null | grep -q '^not1mm '; then
uv tool upgrade not1mm
else
curl -LsSf uvx.sh/not1mm/install.sh | sh
uv tool install not1mm
fi
}
# not1mm installs its own launcher only on first run, so install it up front
install_not1mm_desktop() {
local uv data
uv=$(command -v uv || echo "$HOME/.local/bin/uv")
data=$(echo "$("$uv" tool dir)"/not1mm/lib/python3*/site-packages/not1mm/data)
local data
data=$(echo "$(uv tool dir)"/not1mm/lib/python3*/site-packages/not1mm/data)
[ -f "$data/k6gte-not1mm.desktop" ] || return 1
for size in 32 64 128; do
xdg-icon-resource install --size "$size" --context apps --mode user \
@@ -69,33 +98,48 @@ install_not1mm_desktop() {
xdg-desktop-menu install --mode user "$data/k6gte-not1mm.desktop"
}
install_dxpy() {
wget -q https://raw.githubusercontent.com/HB9VQQ/dx.py/main/dx.py -O "$HOME/.local/bin/dx.py" &&
chmod +x "$HOME/.local/bin/dx.py"
}
# Install graywolf's systemd service once graywolf is built, and reinstall it
# when systemd/graywolf.service changes. To change how graywolf runs (e.g. to
# reach its web UI from other machines), use `sudo systemctl edit graywolf`:
# a drop-in survives updates, while edits to the unit file itself don't.
install_graywolf_service() {
[ -x "$HOME/.local/bin/graywolf" ] || return 0
install_desktop_files() {
mkdir -p "$HOME/.local/share/applications"
sed "s|\$HAMPACK_DIR|$SELF|g; s|\$HOME|$HOME|g" "$SELF/desktop/js8call.desktop" \
> "$HOME/.local/share/applications/js8call.desktop" &&
update-desktop-database "$HOME/.local/share/applications/"
local unit=/etc/systemd/system/graywolf.service rendered
rendered="$(sed "s|HAMPACK_USER|$USER|g; s|HAMPACK_HOME|$HOME|g" "$SELF/systemd/graywolf.service")"
mkdir -p "$HOME/.local/share/graywolf"
getent group dialout > /dev/null || sudo groupadd dialout || return 1
if [ "$(cat "$unit" 2> /dev/null)" != "$rendered" ]; then
echo "Installing $unit..."
printf '%s\n' "$rendered" | sudo tee "$unit" > /dev/null || return 1
sudo systemctl daemon-reload || return 1
sudo systemctl try-restart graywolf
fi
enable_services graywolf
}
# --- Main ---
echo "Updating HamPack..."
# Builds and package installs need sudo; ask now rather than partway through.
# Under CoreDesktop's `update`, sudo already has the password and doesn't ask.
if ! start_sudo_keepalive; then
echo "HamPack needs sudo to install packages and applications."
exit 1
fi
step "Removing stale HamPack files" remove_stale_files
step "Installing HamPack tools" install_tools
step "Installing HamPack packages" install_hampack_packages
step "Installing Flatpak applications" bash "$SELF/install-flatpaks.sh"
step "Installing pre-built binaries" bash "$SELF/install-binaries.sh"
step "Installing compiled applications" bash "$SELF/install-compiled.sh"
step "Installing graywolf service" install_graywolf_service
step "Installing Windows applications" bash "$SELF/install-windows-apps.sh"
step "Installing not1mm" install_not1mm
step "Installing not1mm desktop file" install_not1mm_desktop
step "Installing dx.py" install_dxpy
step "Installing desktop files" install_desktop_files
if (( ${#FAILED[@]} > 0 )); then
echo "HamPack updated, with errors in: ${FAILED[*]}"