#!/bin/bash # # Purpose : Download latest VARA HF, FM, Terminal and Winlink Express from winlink.org BASE_URL="https://downloads.winlink.org" DOWNLOAD_DIR="/tmp/windowsapps" mkdir -p "$DOWNLOAD_DIR" echo "Fetching VARA Products page..." PAGE=$(curl -s "$BASE_URL/VARA%20Products/") 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." 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" 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 Winlink Express version $version to $extract_dir" rm -f "$filepath" else echo "Error: extraction of $filename failed." return 1 fi } # 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) if [ -z "$exe" ]; then echo "Error: no VARA*.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" 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 fi if [ ! -d "$extract_dir" ]; then echo "Error: directory $extract_dir not found, skipping." return 1 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" echo "$exe_name installation complete." } # Download all products download_vara "VARA HF" download_vara "VARA FM" download_vara "VARA Terminal" download_winlink # 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" else echo '"Decorated"="N"' >> "$USER_REG" fi echo "Set Decorated=N in $USER_REG" fi echo "" echo "All products downloaded and extracted to $DOWNLOAD_DIR" # Install Wine dependencies echo "" echo "Installing Wine dependencies..." winetricks -q vb6run pdh_nt4 sound=alsa 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."