Files
HamPack/install-windows-apps.sh
T
David YoungandClaude Opus 5.5 6bf0565917 Correct the comment on Wine's Decorated setting
Decorated=N makes Wine draw its own Windows-style frames instead of the
window manager's; it doesn't remove decorations, and VARA and Winlink
don't draw their own.

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

130 lines
4.3 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.
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"
)
# 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
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
filename="$(sed 's|.*/||; s|%20| |g' <<< "$href")"
echo "Downloading $filename..."
curl -fsSL "$BASE_URL$href" -o "$HAMPACK_TMP/download.zip" || { echo "Error: download of $filename failed."; return 1; }
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() {
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
# 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
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
exit $status