Files
HamPack/install-windows-apps.sh
T
David YoungandClaude Opus 5.5 e8fbe256df
check / lint-and-test (push) Successful in 1m37s
check / packages (push) Successful in 23s
Add a smoketest, run on CoreDesktop's with coredesktop-dev
`coredesktop-dev smoketest run --with HamPack` installs HamPack on a VM with
CoreDesktop and checks a fresh install, an update with nothing to do, a
one-app rebuild, a failing build and hampackremove, with smoketest/health
checking every package, Flatpak and app is in place.

HAMPACK_SKIP_WINDOWS_APPS skips the Windows installers, which the test VMs'
desktop would start with no one to click through them; smoketest/setup sets
it in each VM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 10:15:11 -07:00

180 lines
6.0 KiB
Bash
Executable File

#!/bin/bash
#
# 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.
# Zips the user downloaded to their downloads folder are used first.
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib.sh"
BASE_URL="https://downloads.winlink.org"
WINE_C="${WINEPREFIX:-$HOME/.wine}/drive_c"
# 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"
)
# Where the user's browser saves downloads. xdg-user-dir answers $HOME when
# there's no Downloads folder set
downloads_dir() {
local dir
dir="$(xdg-user-dir DOWNLOAD 2> /dev/null)"
[ -n "$dir" ] && [ "$dir" != "$HOME" ] || dir="$HOME/Downloads"
echo "$dir"
}
# The newest zip in the downloads folder whose name matches PATTERN. Spaces in
# PATTERN are written %20, as on winlink.org; browsers save them as spaces, or
# sometimes as underscores.
find_downloaded_zip() {
local pattern="${1//%20/[ _]}"
find "$(downloads_dir)" -maxdepth 1 -type f -iname "*$pattern*.zip" -printf '%T@ %p\n' 2> /dev/null |
sort -rn | head -n1 | cut -d' ' -f2-
}
# Get a product's zip and extract it to DIR: from the downloads folder if the
# user downloaded it there, otherwise from its winlink.org page. winlink.org puts
# a browser check in front of its downloads, which scripts can't pass, so while
# that's in place the download fails; that returns 2, so the caller can ask the
# user to download the zip themselves.
get_product() {
local page="$1" pattern="$2" dir="$3"
local zip listing href
zip="$(find_downloaded_zip "$pattern")"
if [ -n "$zip" ]; then
echo "Using $zip"
else
listing="$(curl -fsSL "$BASE_URL/$page/" 2> /dev/null)" || return 2
href="$(grep -oP 'HREF="\K[^"]+' <<< "$listing" | grep -i "$pattern" | grep -i '\.zip$' | head -n1)"
[ -n "$href" ] || return 2
echo "Downloading $(sed 's|.*/||; s|%20| |g' <<< "$href")..."
zip="$HAMPACK_TMP/download.zip"
curl -fsSL "$BASE_URL$href" -o "$zip" 2> /dev/null || return 2
fi
rm -rf "$dir"
mkdir -p "$dir"
unzip -q "$zip" -d "$dir" || { echo "Error: could not extract $zip"; return 1; }
}
# Wait for a Wine window to appear and raise it to the front
raise_wine_window() {
local _
for _ in $(seq 1 20); do
sleep 1
xdotool search --class Wine windowfocus windowraise 2> /dev/null && return 0
done
}
# 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 $glob found for $name."
return 1
fi
echo ""
echo "=== Installing $name ==="
echo "Please complete the installation in the Wine window."
echo "This will continue once the installer is closed."
echo ""
wine "$exe" &
local wine_pid=$!
raise_wine_window &
wait "$wine_pid"
}
# 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 [ ! -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
# Have Wine draw its own Windows-style frames instead of letting the desktop's
# window manager decorate Wine windows (X11 driver only, which includes XWayland)
wine reg add 'HKCU\Software\Wine\X11 Driver' /v Decorated /t REG_SZ /d N /f > /dev/null 2>&1
}
# --- Main ---
missing=()
for product in "${PRODUCTS[@]}"; do
IFS='|' read -r name check _ <<< "$product"
if [ -e "$check" ]; then
echo "$name is already installed."
else
missing+=("$product")
fi
done
[ ${#missing[@]} -eq 0 ] && exit 0
# HamPack's smoketest sets this: its test machines have a desktop, but no one
# to click through the installers
if [ -n "${HAMPACK_SKIP_WINDOWS_APPS:-}" ]; then
echo "Not installing Windows applications: HAMPACK_SKIP_WINDOWS_APPS is set."
exit 0
fi
# 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
mkdir -p "$HAMPACK_STATE"
make_work_dir || exit 1
prepare_wine || exit 1
status=0
by_hand=()
for product in "${missing[@]}"; do
IFS='|' read -r name check page pattern glob <<< "$product"
dir="$HAMPACK_TMP/${name// /_}"
get_product "$page" "$pattern" "$dir"
case $? in
0) ;;
2) by_hand+=("$name|$page"); continue ;;
*) echo "$name was not installed; it will be tried again on the next update."; status=1; continue ;;
esac
if 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
# Not an error: nothing is wrong on this machine, the user just has to fetch
# these zips themselves
if [ ${#by_hand[@]} -gt 0 ]; then
echo ""
echo "winlink.org only lets web browsers download its programs, so please"
echo "download these zips in your browser:"
for entry in "${by_hand[@]}"; do
IFS='|' read -r name page <<< "$entry"
echo " $name, from $BASE_URL/$page/"
done
echo "Leave them in $(downloads_dir) and update again; HamPack installs them from there."
fi
exit $status