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
+56
-179
@@ -2,125 +2,72 @@
|
||||
#
|
||||
# Purpose: Download and install pre-built binaries from binaries.conf
|
||||
|
||||
HAMPACK_DIR="${HAMPACK_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"
|
||||
export HAMPACK_DIR
|
||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib.sh"
|
||||
|
||||
CONF_FILE="${HAMPACK_BINARIES_CONF:-$HAMPACK_DIR/binaries.conf}"
|
||||
TMP_DIR="/tmp/hampack-build"
|
||||
VERSION_FILE="$HOME/.local/state/HamPack/.installed_versions"
|
||||
APPLICATIONS_DIR="$HOME/.local/share/applications"
|
||||
FAILED=()
|
||||
|
||||
# Expand $HOME, $HAMPACK_DIR and $USER in a config value. Unlike `eval echo`,
|
||||
# this leaves everything else (semicolons, quotes, spacing) untouched.
|
||||
expand_vars() {
|
||||
local v="$1"
|
||||
v="${v//\$HAMPACK_DIR/"$HAMPACK_DIR"}"
|
||||
v="${v//\$HOME/"$HOME"}"
|
||||
v="${v//\$USER/"$USER"}"
|
||||
printf '%s\n' "$v"
|
||||
}
|
||||
|
||||
# Get the installed version of an app
|
||||
get_installed_version() {
|
||||
local app="$1"
|
||||
|
||||
if [ -f "$VERSION_FILE" ]; then
|
||||
local stored
|
||||
stored=$(grep "^$app=" "$VERSION_FILE" | cut -d'=' -f2)
|
||||
if [ -n "$stored" ]; then
|
||||
echo "$stored"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "unknown"
|
||||
}
|
||||
|
||||
# Save installed version to version file
|
||||
save_installed_version() {
|
||||
local app="$1"
|
||||
local version="$2"
|
||||
|
||||
touch "$VERSION_FILE"
|
||||
|
||||
if grep -q "^$app=" "$VERSION_FILE"; then
|
||||
sed -i "s/^$app=.*/$app=$version/" "$VERSION_FILE"
|
||||
else
|
||||
echo "$app=$version" >> "$VERSION_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check if an update is needed
|
||||
needs_update() {
|
||||
local app="$1"
|
||||
local install_path="$2"
|
||||
local latest="$3"
|
||||
local app="$1" install_path="$2" latest="$3" installed
|
||||
|
||||
if [ ! -f "$install_path" ]; then
|
||||
if [ ! -e "$install_path" ]; then
|
||||
echo " $app is not installed."
|
||||
return 0
|
||||
fi
|
||||
|
||||
local installed
|
||||
installed=$(get_installed_version "$app")
|
||||
|
||||
if [ "$installed" = "unknown" ]; then
|
||||
installed="$(get_recorded_version "$app")"
|
||||
if [ -z "$installed" ]; then
|
||||
echo " Installed version of $app is unknown, reinstalling version $latest."
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo " Installed version : $installed"
|
||||
echo " Latest version : $latest"
|
||||
|
||||
if [ "$installed" = "$latest" ]; then
|
||||
echo " $app is up to date, skipping."
|
||||
echo " $app $installed is up to date."
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo " Update available for $app."
|
||||
echo " Updating $app from $installed to $latest."
|
||||
return 0
|
||||
}
|
||||
|
||||
# Download binary and place it at the install path
|
||||
# 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 app="$1"
|
||||
local url="$2"
|
||||
local install_path="$3"
|
||||
|
||||
local filename="${url##*/}"
|
||||
local tmp_file="$TMP_DIR/$filename"
|
||||
local url="$1" install_path="$2" sha256="$3"
|
||||
local tmp_file="$HAMPACK_TMP/download"
|
||||
|
||||
echo " Downloading $url..."
|
||||
if ! wget -q "$url" -O "$tmp_file"; then
|
||||
if ! curl -fsSL "$url" -o "$tmp_file"; then
|
||||
echo " Error: download of $url failed."
|
||||
rm -f "$tmp_file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname "$install_path")"
|
||||
mv "$tmp_file" "$install_path"
|
||||
chmod +x "$install_path"
|
||||
echo " Installed to $install_path"
|
||||
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"
|
||||
}
|
||||
|
||||
# Generate and install a .desktop file
|
||||
# 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"
|
||||
local install_path="$2"
|
||||
local exec_cmd="$3"
|
||||
local comment="$4"
|
||||
local icon="$5"
|
||||
local categories="$6"
|
||||
local app="$1" exec_cmd="$2" comment="$3" icon="$4" categories="$5"
|
||||
|
||||
[ -z "$categories" ] && categories="HamRadio;"
|
||||
[ -z "$exec_cmd" ] && exec_cmd="$install_path"
|
||||
|
||||
local desktop_dir="$HOME/.local/share/applications"
|
||||
mkdir -p "$desktop_dir"
|
||||
|
||||
local desktop_file="$desktop_dir/$app.desktop"
|
||||
|
||||
echo " Generating desktop file $desktop_file..."
|
||||
cat > "$desktop_file" <<EOF
|
||||
mkdir -p "$APPLICATIONS_DIR"
|
||||
cat > "$APPLICATIONS_DIR/$app.desktop" << EOF
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=$app
|
||||
@@ -129,102 +76,39 @@ Comment=$comment
|
||||
Icon=$icon
|
||||
Categories=$categories
|
||||
EOF
|
||||
|
||||
chmod +x "$desktop_file"
|
||||
echo " Desktop file installed."
|
||||
}
|
||||
|
||||
# Process a single app
|
||||
# Process the app in CONF (called by parse_conf for each section)
|
||||
process_app() {
|
||||
local app="$1"
|
||||
local url="$2"
|
||||
local install_path="$3"
|
||||
local version="$4"
|
||||
local gui="$5"
|
||||
local exec_cmd="$6"
|
||||
local comment="$7"
|
||||
local icon="$8"
|
||||
local categories="$9"
|
||||
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" ]; then
|
||||
echo " Error: no url specified for $app, skipping."
|
||||
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 [ -z "$install_path" ]; then
|
||||
echo " Error: no install path specified for $app, skipping."
|
||||
FAILED+=("$app")
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -f "$install_path" ]; then
|
||||
if [ -z "$version" ]; then
|
||||
echo " $app is already installed, skipping."
|
||||
if needs_update "$app" "$install_path" "$version"; then
|
||||
if ! download_binary "$url" "$install_path" "$sha256"; then
|
||||
FAILED+=("$app")
|
||||
return
|
||||
fi
|
||||
if ! needs_update "$app" "$install_path" "$version"; then
|
||||
return
|
||||
fi
|
||||
else
|
||||
echo " $app is not installed."
|
||||
fi
|
||||
|
||||
if ! download_binary "$app" "$url" "$install_path"; then
|
||||
FAILED+=("$app")
|
||||
return
|
||||
fi
|
||||
|
||||
if [ "$gui" = "true" ]; then
|
||||
install_desktop "$app" "$install_path" "$exec_cmd" "$comment" "$icon" "$categories"
|
||||
fi
|
||||
|
||||
if [ -n "$version" ]; then
|
||||
save_installed_version "$app" "$version"
|
||||
echo " $app $version installed."
|
||||
fi
|
||||
|
||||
echo " $app installed successfully."
|
||||
}
|
||||
|
||||
# Parse binaries.conf and process each app
|
||||
process_conf() {
|
||||
local app="" url="" install_path="" version="" gui="" exec_cmd="" comment="" icon="" categories=""
|
||||
|
||||
while IFS= read -r line || [ -n "$line" ]; do
|
||||
[[ -z "$line" || "$line" == \#* ]] && continue
|
||||
|
||||
if [[ "$line" =~ ^\[(.+)\]$ ]]; then
|
||||
if [ -n "$app" ]; then
|
||||
process_app "$app" "$url" "$install_path" "$version" "$gui" "$exec_cmd" "$comment" "$icon" "$categories"
|
||||
fi
|
||||
app="${BASH_REMATCH[1]}"
|
||||
url="" install_path="" version="" gui="" exec_cmd="" comment="" icon="" categories=""
|
||||
continue
|
||||
fi
|
||||
|
||||
local key="${line%%=*}"
|
||||
local value="${line#*=}"
|
||||
value=$(expand_vars "$value")
|
||||
|
||||
case "$key" in
|
||||
url) url="$value" ;;
|
||||
install) install_path="$value" ;;
|
||||
version) version="$value" ;;
|
||||
gui) gui="$value" ;;
|
||||
exec) exec_cmd="$value" ;;
|
||||
comment) comment="$value" ;;
|
||||
icon) icon="$value" ;;
|
||||
categories) categories="$value" ;;
|
||||
esac
|
||||
|
||||
done < "$CONF_FILE"
|
||||
|
||||
# Process the last app in the file
|
||||
if [ -n "$app" ]; then
|
||||
process_app "$app" "$url" "$install_path" "$version" "$gui" "$exec_cmd" "$comment" "$icon" "$categories"
|
||||
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
|
||||
}
|
||||
|
||||
@@ -235,24 +119,17 @@ if [ ! -f "$CONF_FILE" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$TMP_DIR"
|
||||
mkdir -p "$HOME/.local/state/HamPack"
|
||||
make_work_dir || exit 1
|
||||
mkdir -p "$HOME/.local/bin"
|
||||
|
||||
echo "Starting HamPack binary installs..."
|
||||
process_conf
|
||||
parse_conf "$CONF_FILE" process_app
|
||||
|
||||
echo ""
|
||||
echo "Updating desktop database..."
|
||||
update-desktop-database "$HOME/.local/share/applications/"
|
||||
|
||||
echo ""
|
||||
echo "Cleaning up..."
|
||||
rm -rf "$TMP_DIR"
|
||||
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
|
||||
|
||||
echo "All done."
|
||||
|
||||
Reference in New Issue
Block a user