Ask for the VARA and Winlink zips when winlink.org won't serve them
downloads.winlink.org now puts a Cloudflare browser check in front of every page, so the installers' download fails with a 403 and updates ended with an error (report CD-NTEU79). Look for the zip in the user's Downloads folder first, and if it isn't there and the site refuses, list which zips to download and from where instead of failing the update. A zip that won't extract or an installer that doesn't finish is still an error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
354a4cbe03
commit
bb5c7900d5
+59
-16
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user