Files
HamPack/install-binaries.sh
T
David YoungandClaude Opus 5.5 0b471c9771 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>
2026-11-08 09:55:13 -07:00

136 lines
3.5 KiB
Bash
Executable File

#!/bin/bash
#
# Purpose: Download and install pre-built binaries from binaries.conf
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib.sh"
CONF_FILE="${HAMPACK_BINARIES_CONF:-$HAMPACK_DIR/binaries.conf}"
APPLICATIONS_DIR="$HOME/.local/share/applications"
FAILED=()
# Check if an update is needed
needs_update() {
local app="$1" install_path="$2" latest="$3" installed
if [ ! -e "$install_path" ]; then
echo " $app is not installed."
return 0
fi
installed="$(get_recorded_version "$app")"
if [ -z "$installed" ]; then
echo " Installed version of $app is unknown, reinstalling version $latest."
return 0
fi
if [ "$installed" = "$latest" ]; then
echo " $app $installed is up to date."
return 1
fi
echo " Updating $app from $installed to $latest."
return 0
}
# Download a binary, check it against its SHA-256 if one is given, and put it
# at the install path. A failed download or check leaves the old binary alone.
download_binary() {
local url="$1" install_path="$2" sha256="$3"
local tmp_file="$HAMPACK_TMP/download"
echo " Downloading $url..."
if ! curl -fsSL "$url" -o "$tmp_file"; then
echo " Error: download of $url failed."
return 1
fi
if [ -n "$sha256" ]; then
if ! echo "$sha256 $tmp_file" | sha256sum -c --status; then
echo " Error: $url doesn't match its sha256 in binaries.conf."
echo " Expected $sha256"
echo " Got $(sha256sum "$tmp_file" | cut -d' ' -f1)"
return 1
fi
else
echo " Warning: no sha256 in binaries.conf, so the download isn't verified."
fi
mkdir -p "$(dirname "$install_path")" &&
chmod +x "$tmp_file" &&
mv -f "$tmp_file" "$install_path" &&
echo " Installed to $install_path"
}
# Write the app's .desktop file. Done on every run, not just after a download,
# so paths in it (like icons in $HAMPACK_DIR) stay right if HamPack moves.
install_desktop() {
local app="$1" exec_cmd="$2" comment="$3" icon="$4" categories="$5"
mkdir -p "$APPLICATIONS_DIR"
cat > "$APPLICATIONS_DIR/$app.desktop" << EOF
[Desktop Entry]
Type=Application
Name=$app
Exec=$exec_cmd
Comment=$comment
Icon=$icon
Categories=$categories
EOF
}
# Process the app in CONF (called by parse_conf for each section)
process_app() {
local app="${CONF[_name]}"
local url install_path version="${CONF[version]}" sha256="${CONF[sha256]}"
url="$(expand_vars "${CONF[url]}")"
install_path="$(expand_vars "${CONF[install]}")"
echo ""
echo "=== $app ==="
if [ -z "$url" ] || [ -z "$install_path" ] || [ -z "$version" ]; then
echo " Error: $app needs url=, install= and version= in binaries.conf, skipping."
FAILED+=("$app")
return
fi
if needs_update "$app" "$install_path" "$version"; then
if ! download_binary "$url" "$install_path" "$sha256"; then
FAILED+=("$app")
return
fi
save_installed_version "$app" "$version"
echo " $app $version installed."
fi
if [ "${CONF[gui]}" = "true" ]; then
install_desktop "$app" \
"$(expand_vars "${CONF[exec]:-$install_path}")" \
"$(expand_vars "${CONF[comment]}")" \
"$(expand_vars "${CONF[icon]}")" \
"${CONF[categories]:-HamRadio;}"
fi
}
# --- Main ---
if [ ! -f "$CONF_FILE" ]; then
echo "Error: $CONF_FILE not found."
exit 1
fi
make_work_dir || exit 1
mkdir -p "$HOME/.local/bin"
echo "Starting HamPack binary installs..."
parse_conf "$CONF_FILE" process_app
mkdir -p "$APPLICATIONS_DIR"
update-desktop-database "$APPLICATIONS_DIR" 2> /dev/null
if (( ${#FAILED[@]} > 0 )); then
echo ""
echo "Failed to install: ${FAILED[*]}"
exit 1
fi