Files
HamPack/install-compiled.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

212 lines
6.1 KiB
Bash
Executable File

#!/bin/bash
#
# Purpose : Compile and install applications from compile.conf
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib.sh"
CONF_FILE="${HAMPACK_COMPILE_CONF:-$HAMPACK_DIR/compile.conf}"
APPLICATIONS_DIR="$HOME/.local/share/applications"
FAILED=()
# Check if an update is needed. Never asks: this runs unattended under `update`.
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, building 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
}
# Install the app's .desktop file with $HAMPACK_DIR and $HOME filled in. Done on
# every run, not just after a build, so its paths stay right if HamPack moves.
install_desktop() {
local desktop="$1"
[ -n "$desktop" ] || return 0
if [ ! -f "$desktop" ]; then
echo " Warning: desktop file $desktop not found, skipping."
return 0
fi
mkdir -p "$APPLICATIONS_DIR"
sed "s|\$HAMPACK_DIR|$HAMPACK_DIR|g; s|\$HOME|$HOME|g" "$desktop" \
> "$APPLICATIONS_DIR/$(basename "$desktop")"
}
# Find the tag for a version, named either "1.2.3" or "v1.2.3". Prints nothing
# if the repo has no tags at all; fails if it has tags but none for the version.
find_version_tag() {
local git_url="$1" version="$2" tags tag
tags=$(git ls-remote --tags --refs "$git_url" | sed 's|.*refs/tags/||') || return 1
[ -z "$tags" ] && return 0
for tag in "$version" "v$version"; do
if grep -qxF "$tag" <<< "$tags"; then
echo "$tag"
return 0
fi
done
return 1
}
# Fetch source via git or an archive download into SRC_DIR
fetch_source() {
local git_url="$1" wget_url="$2" version="$3" ref="$4" src_dir="$5"
rm -rf "$src_dir"
mkdir -p "$src_dir"
if [ -n "$git_url" ] && [ -n "$ref" ]; then
echo " Cloning $git_url at $ref..."
git clone --quiet "$git_url" "$src_dir" || return 1
git -C "$src_dir" -c advice.detachedHead=false checkout --quiet "$ref" || return 1
elif [ -n "$git_url" ]; then
local tag
if ! tag=$(find_version_tag "$git_url" "$version"); then
echo " Error: no tag $version or v$version in $git_url"
return 1
fi
if [ -n "$tag" ]; then
echo " Cloning $git_url at $tag..."
git -c advice.detachedHead=false clone --quiet --branch "$tag" "$git_url" "$src_dir" || return 1
else
echo " $git_url has no tags; cloning the default branch..."
git clone --quiet "$git_url" "$src_dir" || return 1
fi
elif [ -n "$wget_url" ]; then
local filename="${wget_url##*/}"
local filepath="$HAMPACK_TMP/$filename"
echo " Downloading $wget_url..."
curl -fsSL "$wget_url" -o "$filepath" || return 1
echo " Extracting $filename..."
case "$filename" in
*.zip)
unzip -q "$filepath" -d "$src_dir" || return 1
# If the zip extracted into a single subdirectory, flatten it
local entries=("$src_dir"/*)
if [ ${#entries[@]} -eq 1 ] && [ -d "${entries[0]}" ]; then
echo " Descending into $(basename "${entries[0]}")..."
mv "${entries[0]}" "$src_dir.inner" && rmdir "$src_dir" && mv "$src_dir.inner" "$src_dir" || return 1
fi
;;
*.tar.gz|*.tgz) tar -xzf "$filepath" -C "$src_dir" --strip-components=1 || return 1 ;;
*.tar.bz2) tar -xjf "$filepath" -C "$src_dir" --strip-components=1 || return 1 ;;
*.tar.xz) tar -xJf "$filepath" -C "$src_dir" --strip-components=1 || return 1 ;;
*)
echo " Error: unknown file type for $filename"
return 1
;;
esac
rm -f "$filepath"
else
echo " Error: no git= or wget= URL in compile.conf"
return 1
fi
}
# Run the comma-separated build steps from SRC_DIR, stopping at the first that
# fails. Steps run in this shell, so a `cd` in one carries on to the next.
run_steps() {
local steps="$1" src_dir="$2" step step_list
cd "$src_dir" || return 1
IFS=',' read -ra step_list <<< "$steps"
for step in "${step_list[@]}"; do
step="${step#"${step%%[![:space:]]*}"}"
step="${step%"${step##*[![:space:]]}"}"
echo " Running: $step"
if ! eval "$step" < /dev/null; then
echo " Error: step failed: $step"
return 1
fi
done
}
# Process the app in CONF (called by parse_conf for each section)
process_app() {
local app="${CONF[_name]}" version="${CONF[version]}"
local install_path desktop
install_path="$(expand_vars "${CONF[install]}")"
desktop="$(expand_vars "${CONF[desktop]}")"
echo ""
echo "=== $app ==="
if [ -z "$version" ] || [ -z "$install_path" ] || [ -z "${CONF[steps]}" ]; then
echo " Error: $app needs version=, install= and steps= in compile.conf, skipping."
FAILED+=("$app")
return
fi
if needs_update "$app" "$install_path" "$version"; then
local src_dir="$HAMPACK_TMP/$app"
if ! fetch_source "$(expand_vars "${CONF[git]}")" "$(expand_vars "${CONF[wget]}")" \
"$version" "${CONF[ref]}" "$src_dir"; then
echo " Error: could not fetch $app source, skipping."
FAILED+=("$app")
return
fi
echo " Building $app..."
local status=0
HAMPACK_APP="$app" run_steps "${CONF[steps]}" "$src_dir" || status=1
cd "$HOME" || true
rm -rf "$src_dir"
if (( status != 0 )); then
echo " Error: build of $app failed; it will be tried again on the next update."
FAILED+=("$app")
return
fi
save_installed_version "$app" "$version"
echo " $app $version installed."
fi
install_desktop "$desktop"
}
# --- Main ---
if [ ! -f "$CONF_FILE" ]; then
echo "Error: $CONF_FILE not found."
exit 1
fi
make_work_dir || exit 1
echo "Starting HamPack source builds..."
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