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
+39 -103
View File
@@ -1,34 +1,24 @@
#!/bin/bash
#
# Purpose: Check for available version updates in binaries.conf and compile.conf
# (a tool for HamPack maintainers; it changes nothing)
source "$(dirname "$(realpath "$0")")/lib.sh"
SCRIPT_DIR=$(dirname "$(realpath "$0")")
HAMPACK_DIR="${HAMPACK_DIR:-$SCRIPT_DIR}"
BINARIES_CONF="${HAMPACK_BINARIES_CONF:-$HAMPACK_DIR/binaries.conf}"
COMPILE_CONF="${HAMPACK_COMPILE_CONF:-$HAMPACK_DIR/compile.conf}"
# Extract "owner/repo" from a GitHub URL, or empty string if not GitHub
github_repo_from_url() {
local url="$1"
if [[ "$url" =~ github\.com/([^/]+)/([^/]+) ]]; then
echo "${BASH_REMATCH[1]}/${BASH_REMATCH[2]%.git}"
fi
}
# Fetch latest release tag via GitHub API, stripping leading "v"
github_latest() {
local repo="$1"
curl -sf "https://api.github.com/repos/$repo/releases/latest" \
| grep '"tag_name"' \
| sed 's/.*"tag_name": *"\([^"]*\)".*/\1/' \
curl -sf "https://api.github.com/repos/$1/releases/latest" \
| sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p' \
| sed 's/^v//'
}
# Latest release tag in a git repo, stripping leading "v". Only plain version
# tags count (1.2.3 or v1.2.3), not pre-releases like 1.8-beta1.
git_latest_tag() {
local url="$1"
git ls-remote --tags --refs "$url" 2>/dev/null \
git ls-remote --tags --refs "$1" 2> /dev/null \
| sed 's|.*refs/tags/||' \
| grep -E '^v?[0-9]+(\.[0-9]+)+$' \
| sed 's/^v//' \
@@ -36,106 +26,51 @@ git_latest_tag() {
| tail -n1
}
# Latest commit on a GitHub repo's default branch
github_head() {
git ls-remote "https://github.com/$1" HEAD 2> /dev/null | cut -f1
}
print_result() {
local app="$1"
local pinned="$2"
local latest="$3"
local manual_url="$4"
local source="${5:-GitHub API}"
local app="$1" pinned="$2" latest="$3" manual_url="$4" source="${5:-GitHub API}"
if [ -n "$manual_url" ]; then
printf " %-20s pinned=%-15s (manual check: %s)\n" "$app" "$pinned" "${manual_url%/*}"
printf " %-20s pinned=%-15s (manual check: %s)\n" "$app" "${pinned:0:15}" "${manual_url%/*}"
elif [ -z "$latest" ]; then
printf " %-20s pinned=%-15s (%s unavailable)\n" "$app" "$pinned" "$source"
printf " %-20s pinned=%-15s (%s unavailable)\n" "$app" "${pinned:0:15}" "$source"
elif [ "$pinned" = "$latest" ]; then
printf " %-20s up to date (%s)\n" "$app" "$pinned"
printf " %-20s up to date (%s)\n" "$app" "${pinned:0:15}"
else
printf " %-20s pinned=%-15s latest=%-15s ** UPDATE AVAILABLE **\n" "$app" "$pinned" "$latest"
printf " %-20s pinned=%-15s latest=%-15s ** UPDATE AVAILABLE **\n" "$app" "${pinned:0:15}" "${latest:0:15}"
fi
}
check_app() {
local app="$1"
local version="$2"
local url="$3" # git= or url= field (may be GitHub)
local fallback="$4" # wget= or non-GitHub url for manual check
# parse_conf callback for binaries.conf
check_binary() {
local app="${CONF[_name]}" version="${CONF[version]}" url="${CONF[url]}"
[ -n "$version" ] || return 0
[ -n "${CONF[sha256]}" ] || echo " $app has no sha256=, so its download isn't verified"
[ -z "$app" ] || [ -z "$version" ] && return
local gh_repo
gh_repo=$(github_repo_from_url "$url")
if [ -n "$gh_repo" ]; then
print_result "$app" "$version" "$(github_latest "$gh_repo")" ""
if [[ "$url" =~ ^https://raw\.githubusercontent\.com/([^/]+/[^/]+)/ ]]; then
print_result "$app" "$version" "$(github_head "${BASH_REMATCH[1]}")" "" "git"
elif [[ "$url" =~ github\.com/([^/]+)/([^/]+) ]]; then
print_result "$app" "$version" "$(github_latest "${BASH_REMATCH[1]}/${BASH_REMATCH[2]%.git}")" ""
else
print_result "$app" "$version" "" "${fallback:-$url}"
fi
}
check_binaries() {
echo "=== binaries.conf ==="
local app="" version="" url=""
while IFS= read -r line || [ -n "$line" ]; do
[[ -z "$line" || "$line" == \#* ]] && continue
if [[ "$line" =~ ^\[(.+)\]$ ]]; then
check_app "$app" "$version" "$url" ""
app="${BASH_REMATCH[1]}" version="" url=""
continue
fi
local key="${line%%=*}" value="${line#*=}"
case "$key" in
version) version="$value" ;;
url) url="$value" ;;
esac
done < "$BINARIES_CONF"
check_app "$app" "$version" "$url" ""
}
# compile.conf builds git= apps from the tag matching their version, so compare
# against the repo's tags rather than GitHub releases
check_compiled_app() {
local app="$1"
local version="$2"
local git_url="$3"
local wget_url="$4"
[ -z "$app" ] || [ -z "$version" ] && return
if [ -n "$git_url" ]; then
print_result "$app" "$version" "$(git_latest_tag "$git_url")" "" "version tags"
else
check_app "$app" "$version" "" "$wget_url"
print_result "$app" "$version" "" "$url"
fi
}
# parse_conf callback for compile.conf. git= apps are built from the tag
# matching their version, so compare against the repo's tags, not releases.
check_compiled() {
echo ""
echo "=== compile.conf ==="
local app="" name="" version="" git_url="" wget_url=""
local app="${CONF[name]:-${CONF[_name]}}" version="${CONF[version]}"
[ -n "$version" ] || return 0
while IFS= read -r line || [ -n "$line" ]; do
[[ -z "$line" || "$line" == \#* ]] && continue
if [[ "$line" =~ ^\[(.+)\]$ ]]; then
check_compiled_app "${name:-$app}" "$version" "$git_url" "$wget_url"
app="${BASH_REMATCH[1]}" name="" version="" git_url="" wget_url=""
continue
fi
local key="${line%%=*}" value="${line#*=}"
case "$key" in
name) name="$value" ;;
version) version="$value" ;;
git) git_url="$value" ;;
wget) wget_url="$value" ;;
esac
done < "$COMPILE_CONF"
check_compiled_app "${name:-$app}" "$version" "$git_url" "$wget_url"
if [ -n "${CONF[git]}" ]; then
print_result "$app" "$version" "$(git_latest_tag "${CONF[git]}")" "" "version tags"
else
print_result "$app" "$version" "" "${CONF[wget]}"
fi
}
# --- Main ---
@@ -148,7 +83,8 @@ for conf in "$BINARIES_CONF" "$COMPILE_CONF"; do
done
echo "Checking HamPack application versions..."
check_binaries
check_compiled
echo "=== binaries.conf ==="
parse_conf "$BINARIES_CONF" check_binary
echo ""
echo "Done."
echo "=== compile.conf ==="
parse_conf "$COMPILE_CONF" check_compiled