diff --git a/README.md b/README.md index a830db6..e0c0d2b 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,10 @@ Applications are pinned to tested versions, which we try to keep up with. Pinned **Others:** not1mm (contest logger, installed with `uv`), and VARA HF, VARA FM, VARA Terminal and Winlink Express under Wine. The Windows installers need you to click through them, so they run only when one of these is missing and you're at the desktop. +### Downloading the VARA and Winlink installers yourself + +winlink.org only lets web browsers download its programs, so HamPack can't fetch VARA HF, VARA FM, VARA Terminal or Winlink Express itself. When one is missing, the update says which zips to get and from where. Download them in your browser, leave them in your Downloads folder, and update again: HamPack installs them from there. + ### Graywolf's web UI Graywolf's web UI is at http://localhost:8080 and, by default, can only be reached from the machine it runs on. To reach it from other machines, run `sudo systemctl edit graywolf` and override `ExecStart` with `-http 0.0.0.0:8080`. Changes made that way survive HamPack updates; edits to `/etc/systemd/system/graywolf.service` itself don't. diff --git a/install-windows-apps.sh b/install-windows-apps.sh index e06dffc..1cfb318 100755 --- a/install-windows-apps.sh +++ b/install-windows-apps.sh @@ -3,6 +3,7 @@ # 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" @@ -17,26 +18,48 @@ PRODUCTS=( "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 +# 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" +} - 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 +# 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 - 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" + 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 @@ -115,10 +138,17 @@ 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// /_}" - if download_product "$name" "$page" "$pattern" "$dir" && run_installer "$name" "$dir" "$glob" && [ -e "$check" ]; then + 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." @@ -126,4 +156,17 @@ for product in "${missing[@]}"; do 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 diff --git a/tests/installers.bats b/tests/installers.bats index db7cf03..847c390 100644 --- a/tests/installers.bats +++ b/tests/installers.bats @@ -8,6 +8,8 @@ setup() { setup_fake_home fake_coredesktop stub curl 'exit 1' + # So xdg-user-dir reads the fake home's (absent) settings, not the real ones + export XDG_CONFIG_HOME="$HOME/.config" } install_all_windows_apps() { @@ -30,10 +32,48 @@ install_all_windows_apps() { export DISPLAY=:0 run bash "$REPO/install-windows-apps.sh" [[ "$output" == *"VARA HF is already installed"* ]] - [[ "$output" == *"VARA Terminal was not installed"* ]] grep -q "^curl .*VARA%20Products" "$STUB_LOG" } +@test "windows apps: when winlink.org refuses the download, the user is asked to download it and the update isn't failed" { + install_all_windows_apps + rm "$HOME/.wine/drive_c/VARA/VARA Terminal.exe" + export DISPLAY=:0 + run bash "$REPO/install-windows-apps.sh" + [ "$status" -eq 0 ] + [[ "$output" == *"VARA Terminal, from https://downloads.winlink.org/VARA%20Products/"* ]] + [[ "$output" == *"Leave them in $HOME/Downloads"* ]] + [[ "$output" != *"VARA HF, from"* ]] + ! grep -q '^wine .*\.exe' "$STUB_LOG" +} + +@test "windows apps: a zip in the downloads folder is installed without downloading" { + install_all_windows_apps + rm "$HOME/.wine/drive_c/VARA/VARA Terminal.exe" + mkdir -p "$HOME/Downloads" "$BATS_TEST_TMPDIR/zip" + touch "$BATS_TEST_TMPDIR/zip/VARA Terminal setup.exe" + (cd "$BATS_TEST_TMPDIR/zip" && zip -q "$HOME/Downloads/VARA Terminal v1.2.3 setup.zip" "VARA Terminal setup.exe") + stub wine 'case "$1" in *.exe) touch "$HOME/.wine/drive_c/VARA/VARA Terminal.exe" ;; esac' + export DISPLAY=:0 + run bash "$REPO/install-windows-apps.sh" + [ "$status" -eq 0 ] + [[ "$output" == *"VARA Terminal installed."* ]] + grep -q '^wine .*VARA Terminal setup.exe' "$STUB_LOG" + ! grep -q '^curl ' "$STUB_LOG" +} + +@test "windows apps: a zip saved with underscores for spaces is found too" { + install_all_windows_apps + rm "$HOME/.wine/drive_c/VARA/VARA Terminal.exe" + mkdir -p "$HOME/Downloads" + echo "not a zip" > "$HOME/Downloads/VARA_Terminal_v1.2.3.zip" + export DISPLAY=:0 + run bash "$REPO/install-windows-apps.sh" + [[ "$output" == *"Using $HOME/Downloads/VARA_Terminal_v1.2.3.zip"* ]] + [ "$status" -eq 1 ] + [[ "$output" == *"VARA Terminal was not installed"* ]] +} + @test "windows apps: without a desktop session, nothing is downloaded and the update isn't failed" { run bash "$REPO/install-windows-apps.sh" [ "$status" -eq 0 ]