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
+80 -223
View File
@@ -1,271 +1,128 @@
#!/bin/bash
#
# Purpose : Download latest VARA HF, FM, Terminal and Winlink Express from winlink.org
# Purpose : Install VARA HF, VARA FM, VARA Terminal and Winlink Express from
# winlink.org under Wine. Products already installed are left alone,
# so on most updates this downloads nothing and opens no windows.
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib.sh"
BASE_URL="https://downloads.winlink.org"
DOWNLOAD_DIR="/tmp/windowsapps"
WINE_C="${WINEPREFIX:-$HOME/.wine}/drive_c"
mkdir -p "$DOWNLOAD_DIR"
# Each product: name|program that shows it's installed|downloads page|zip name pattern|installer pattern
PRODUCTS=(
"VARA HF|$WINE_C/VARA/VARA.exe|VARA%20Products|VARA%20HF|VARA*.exe"
"VARA FM|$WINE_C/VARA FM/VARAFM.exe|VARA%20Products|VARA%20FM|VARA*.exe"
"VARA Terminal|$WINE_C/VARA/VARA Terminal.exe|VARA%20Products|VARA%20Terminal|VARA*.exe"
"Winlink Express|$WINE_C/RMS Express/RMS Express.exe|User%20Programs|Winlink_Express_install|Winlink_Express_install*.exe"
)
echo "Fetching VARA Products page..."
PAGE=$(curl -s "$BASE_URL/VARA%20Products/")
# Download a product's zip from its winlink.org page and extract it to DIR
download_product() {
local name="$1" page="$2" pattern="$3" dir="$4"
local listing href filename
if [ -z "$PAGE" ]; then
echo "Error: could not fetch VARA Products page."
exit 1
fi
# Download and extract a VARA product by pattern
download_vara() {
local pattern="$1"
# Match against URL encoded pattern
local encoded_pattern=$(echo "$pattern" | sed 's| |%20|g')
ENCODED=$(echo "$PAGE" | grep -oP 'HREF="\K[^"]+' | grep -i "$encoded_pattern")
if [ -z "$ENCODED" ]; then
echo "Error: could not find $pattern on page."
listing="$(curl -fsSL "$BASE_URL/$page/")" || { echo "Error: could not fetch $BASE_URL/$page/"; return 1; }
href="$(grep -oP 'HREF="\K[^"]+' <<< "$listing" | grep -i "$pattern" | grep -i '\.zip$' | head -n1)"
if [ -z "$href" ]; then
echo "Error: could not find $name on $BASE_URL/$page/"
return 1
fi
# Decode %20 to spaces for local filename
FILENAME=$(echo "$ENCODED" | sed 's|.*/||; s|%20| |g')
# Extract version number
VERSION=$(echo "$FILENAME" | grep -oP '\d+\.\d+[\.\d]*')
if [ -z "$VERSION" ]; then
echo "Error: could not determine version from filename: $FILENAME"
return 1
fi
echo "Found $pattern version: $VERSION"
echo "Filename: $FILENAME"
local DOWNLOAD_URL="$BASE_URL$ENCODED"
local FILEPATH="$DOWNLOAD_DIR/$FILENAME"
local EXTRACT_DIR="$DOWNLOAD_DIR/$(echo "$pattern" | sed 's| |_|g')"
echo "Downloading $FILENAME..."
wget -q "$DOWNLOAD_URL" -O "$FILEPATH"
if [ $? -ne 0 ]; then
echo "Error: download of $FILENAME failed."
return 1
fi
echo "Extracting to $EXTRACT_DIR..."
rm -rf "$EXTRACT_DIR"
mkdir -p "$EXTRACT_DIR"
unzip -q "$FILEPATH" -d "$EXTRACT_DIR"
if [ $? -eq 0 ]; then
echo "Extracted $pattern version $VERSION to $EXTRACT_DIR"
rm -f "$FILEPATH"
else
echo "Error: extraction of $FILENAME failed."
return 1
fi
}
# Download and extract Winlink Express
download_winlink() {
local page
page=$(curl -s "https://downloads.winlink.org/User%20Programs/")
if [ -z "$page" ]; then
echo "Error: could not fetch Winlink User Programs page."
return 1
fi
local encoded
encoded=$(echo "$page" | grep -oP 'HREF="\K[^"]+' | grep -i "Winlink_Express_install")
if [ -z "$encoded" ]; then
echo "Error: could not find Winlink Express install zip on page."
return 1
fi
local filename
filename=$(echo "$encoded" | sed 's|.*/||; s|%20| |g')
local version
version=$(echo "$filename" | grep -oP '\d+[-\.\d]+' | head -n1)
echo "Found Winlink Express version: $version"
echo "Filename: $filename"
local download_url="https://downloads.winlink.org$encoded"
local filepath="$DOWNLOAD_DIR/$filename"
local extract_dir="$DOWNLOAD_DIR/Winlink_Express"
filename="$(sed 's|.*/||; s|%20| |g' <<< "$href")"
echo "Downloading $filename..."
wget -q "$download_url" -O "$filepath"
curl -fsSL "$BASE_URL$href" -o "$HAMPACK_TMP/download.zip" || { echo "Error: download of $filename failed."; return 1; }
if [ $? -ne 0 ]; then
echo "Error: download of $filename failed."
return 1
fi
echo "Extracting to $extract_dir..."
rm -rf "$extract_dir"
mkdir -p "$extract_dir"
unzip -q "$filepath" -d "$extract_dir"
if [ $? -eq 0 ]; then
echo "Extracted Winlink Express version $version to $extract_dir"
rm -f "$filepath"
else
echo "Error: extraction of $filename failed."
return 1
fi
rm -rf "$dir"
mkdir -p "$dir"
unzip -q "$HAMPACK_TMP/download.zip" -d "$dir" || { echo "Error: extraction of $filename failed."; return 1; }
rm -f "$HAMPACK_TMP/download.zip"
}
# Wait for a Wine window to appear and raise it to the front
raise_wine_window() {
for i in $(seq 1 20); do
local _
for _ in $(seq 1 20); do
sleep 1
xdotool search --class Wine windowfocus windowraise 2>/dev/null && return 0
xdotool search --class Wine windowfocus windowraise 2> /dev/null && return 0
done
}
# Install a VARA product using Wine
install_vara() {
local pattern="$1"
local wine_dir="$2"
local extract_dir="$DOWNLOAD_DIR/$(echo "$pattern" | sed 's| |_|g')"
# Check if already installed
if [ -d "$wine_dir" ]; then
echo " $pattern is already installed, skipping."
return 0
fi
if [ ! -d "$extract_dir" ]; then
echo "Error: directory $extract_dir not found, skipping."
return 1
fi
# Find the VARA exe file in the extracted directory
local exe
exe=$(find "$extract_dir" -maxdepth 1 -iname "VARA*.exe" | head -n1)
# Run a product's installer and wait for the user to finish it
run_installer() {
local name="$1" dir="$2" glob="$3" exe
exe="$(find "$dir" -maxdepth 1 -iname "$glob" | head -n1)"
if [ -z "$exe" ]; then
echo "Error: no VARA*.exe found in $extract_dir, skipping."
echo "Error: no $glob found for $name."
return 1
fi
local exe_name=$(basename "$exe")
echo ""
echo "=== Installing $exe_name ==="
echo "=== Installing $name ==="
echo "Please complete the installation in the Wine window."
echo "The script will continue once the installer is closed."
echo "This will continue once the installer is closed."
echo ""
wine "$exe" &
local wine_pid=$!
raise_wine_window &
wait "$wine_pid"
echo "$exe_name installation complete."
}
# Install Winlink Express using Wine
install_winlink() {
local wine_dir="$HOME/.wine/drive_c/RMS Express"
local extract_dir="$DOWNLOAD_DIR/Winlink_Express"
# Check if already installed
if [ -d "$wine_dir" ]; then
echo " Winlink Express is already installed, skipping."
return 0
# Create the Wine prefix and install the runtimes VARA and Winlink need
prepare_wine() {
if [ ! -d "${WINEPREFIX:-$HOME/.wine}" ]; then
echo "Initializing Wine..."
wineboot --init || return 1
# hampackremove offers to remove a prefix HamPack made
touch "$HAMPACK_STATE/wine-prefix-created"
fi
if [ ! -d "$extract_dir" ]; then
echo "Error: directory $extract_dir not found, skipping."
return 1
if [ ! -f "$HAMPACK_STATE/wine-deps-installed" ]; then
echo "Installing Wine dependencies..."
winetricks -q vb6run pdh_nt4 sound=alsa || { echo "Error: winetricks failed."; return 1; }
touch "$HAMPACK_STATE/wine-deps-installed"
fi
local exe
exe=$(find "$extract_dir" -maxdepth 1 -iname "Winlink_Express_install*.exe" | head -n1)
if [ -z "$exe" ]; then
echo "Error: no Winlink Express exe found in $extract_dir, skipping."
return 1
fi
local exe_name=$(basename "$exe")
echo ""
echo "=== Installing $exe_name ==="
echo "Please complete the installation in the Wine window."
echo "The script will continue once the installer is closed."
echo ""
wine "$exe" &
local wine_pid=$!
raise_wine_window &
wait "$wine_pid"
echo "$exe_name installation complete."
# No window decorations: VARA and Winlink draw their own
wine reg add 'HKCU\Software\Wine\X11 Driver' /v Decorated /t REG_SZ /d N /f > /dev/null 2>&1
}
# Download all products
download_vara "VARA HF"
download_vara "VARA FM"
download_vara "VARA Terminal"
download_winlink
# --- Main ---
# Initialize Wine if not already done
if [ ! -d "$HOME/.wine" ]; then
echo "Initializing Wine..."
wineboot --init
echo "Wine initialized."
fi
# Update Wine registry to disable window decorations
USER_REG="$HOME/.wine/user.reg"
if [ ! -f "$USER_REG" ]; then
echo "Warning: $USER_REG not found, skipping registry update."
else
echo "Updating Wine registry..."
if grep -q '"Decorated"="Y"' "$USER_REG"; then
sed -i 's/"Decorated"="Y"/"Decorated"="N"/' "$USER_REG"
elif grep -q '"Decorated"' "$USER_REG"; then
sed -i 's/"Decorated"=.*/"Decorated"="N"/' "$USER_REG"
missing=()
for product in "${PRODUCTS[@]}"; do
IFS='|' read -r name check _ <<< "$product"
if [ -e "$check" ]; then
echo "$name is already installed."
else
echo '"Decorated"="N"' >> "$USER_REG"
missing+=("$product")
fi
echo "Set Decorated=N in $USER_REG"
done
[ ${#missing[@]} -eq 0 ] && exit 0
# The installers are Windows GUI programs; without a desktop there's nothing to show them on
if [ -z "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
echo "Not installing Windows applications without a desktop session; they'll be installed on a later update."
exit 0
fi
echo ""
echo "All products downloaded and extracted to $DOWNLOAD_DIR"
mkdir -p "$HAMPACK_STATE"
make_work_dir || exit 1
prepare_wine || exit 1
# Install Wine dependencies
echo ""
echo "Installing Wine dependencies..."
winetricks -q vb6run pdh_nt4 sound=alsa
status=0
for product in "${missing[@]}"; do
IFS='|' read -r name check page pattern glob <<< "$product"
dir="$HAMPACK_TMP/${name// /_}"
if download_product "$name" "$page" "$pattern" "$dir" && run_installer "$name" "$dir" "$glob" && [ -e "$check" ]; then
echo "$name installed."
else
echo "$name was not installed; it will be tried again on the next update."
status=1
fi
done
if [ $? -ne 0 ]; then
echo "Error: winetricks failed, aborting."
exit 1
fi
echo "Wine dependencies installed successfully."
# Install all products
echo ""
echo "Starting installations..."
install_vara "VARA HF" "$HOME/.wine/drive_c/VARA"
install_vara "VARA FM" "$HOME/.wine/drive_c/VARA FM"
install_vara "VARA Terminal" "$HOME/.wine/drive_c/VARA"
install_winlink
echo ""
echo "Updating desktop database..."
update-desktop-database "$HOME/.local/share/applications/"
echo ""
echo "All installations complete."
exit $status