Last active
February 8, 2026 03:51
-
-
Save haxwithaxe/a653091d0f341822723f85cd2aa326ff to your computer and use it in GitHub Desktop.
Download or query the list of WinLink RMS gateways
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # A script to help locate winlink gateways | |
| # Adapted from `findardop` and `getardoplist` by km4ack | |
| # License: GPL-3-only | |
| set -e -o pipefail | |
| CACHE_DIR="${HOME}/.cache/$(basename "$0")" | |
| ALL_RMS_FILE="${CACHE_DIR}/all.list" | |
| ######## USER CONFIG #################### | |
| PAT_CMD=pat-winlink # Debian 13 renames pat to pat-winlink | |
| ######### END USER CONFIG ################ | |
| print_usage() { | |
| echo "Show this message:" | |
| echo " $(basename "$0") [-h|--help]" | |
| echo "Download the RMS lists:" | |
| echo " $(basename "$0") [-d|--download]" | |
| echo "Search for RMS gateways on BAND in GRID" | |
| echo " $(basename "$0") -g|-t|--grid|--to-grid GRID -b|--band BAND -m|--mode MODE" | |
| echo "Valid values for GRID are Maidenhead Grid locators or portions of them up to 6 " | |
| echo " characters or a regular expression to match the desired grid." | |
| echo "Valid values for BAND are 10m, 12m, 15m, 17m, 20m, 30m, 40m, 80m, or 160m." | |
| echo "Valid values for MODE are the same as for the '--mode' option of " | |
| echo " '${PAT_CMD} rmslist' or a regular expression to match the desired mode." | |
| } | |
| download_rms_list() { | |
| if ! [[ -f "$CACHE_DIR" ]]; then | |
| mkdir -p "$CACHE_DIR" | |
| fi | |
| echo "Last downloaded $(date)" > "$ALL_RMS_FILE" | |
| "$PAT_CMD" rmslist --force-download | egrep -v '^[0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} [Dd]ownload' >> "$ALL_RMS_FILE" | |
| } | |
| get_entries_for_band() { | |
| local freqMHz="$1" | |
| cat - | egrep -i "^[A-Z0-9_/-]+[ \t]+\[[A-Z0-9]{6}\][ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[^ \t]+[ \t]+[0-9]+[ \t]+${freqMHz}[0-9.]* MHz[ \t]+[0-9]" | |
| } | |
| get_entries_for_grid() { | |
| local grid="$1" | |
| cat - | egrep -i "^[A-Z0-9_/-]+ +\[${grid}" | |
| } | |
| get_entries_for_mode() { | |
| local mode="$1" | |
| local version="$2" | |
| if [[ -n "$version" ]]; then | |
| mode="${mode} ${version}" | |
| fi | |
| cat - | egrep -i "^[A-Z0-9_/-]+ +\[[A-Z0-9]{6}\][ \t]+[0-9]+[ \t]+[0-9]+[ \t]+${mode}" | |
| } | |
| main() { | |
| to_grid='[A-Z]{2}[0-9]{2}[A-Z]{2}' | |
| mode='[^ \t]+' | |
| ARGS="$(getopt -o 'hg:t:b:m:d' --long 'help,grid:,to-grid:,band:,mode:,download' -- "$@")" || (print_usage && exit 1) | |
| eval set -- "$ARGS" | |
| while true; do | |
| case "$1" in | |
| -h|--help) | |
| print_usage | |
| exit 1 | |
| ;; | |
| -g|-t|--grid|--to-grid) | |
| to_grid="${2^^}" | |
| shift 2 | |
| ;; | |
| -b|--band) | |
| band="${2,,}" | |
| shift 2 | |
| ;; | |
| -m|--mode) | |
| mode="${2^^}" | |
| shift 2 | |
| while [[ -n "$1" ]] && [[ "$1" != "-" ]] && [[ "${1/-/}" == "$1" ]]; do | |
| mode="${mode} $1" | |
| shift 1 | |
| done | |
| ;; | |
| -d|--download) | |
| download_rms_list | |
| exit 0 | |
| ;; | |
| --) | |
| shift | |
| break | |
| ;; | |
| esac | |
| done | |
| # Check that the list has been downloaded already | |
| if ! [ -f "$ALL_RMS_FILE" ]; then | |
| echo RMS lists have not been downloaded. | |
| echo Run to download: | |
| echo " $(basename $0) --download" | |
| exit 1 | |
| fi | |
| case $band in | |
| 10m|10) | |
| freqMHz='2[8-9]' | |
| ;; | |
| 12m|12) | |
| freqMHz='24' | |
| ;; | |
| 15m|15) | |
| freqMHz='21' | |
| ;; | |
| 17m|17) | |
| freqMHz='18' | |
| ;; | |
| 20m|20) | |
| freqMHz='14' | |
| ;; | |
| 30m|30) | |
| freqMHz='10' | |
| ;; | |
| 40m|40) | |
| freqMHz=' 7' | |
| ;; | |
| 80m|80) | |
| freqMHz=' [3-4]' | |
| ;; | |
| 160m|160) | |
| freqMHz=' [1-2]' | |
| ;; | |
| all) | |
| freqMHz='[ 0-9][0-9]' | |
| ;; | |
| *) | |
| if [[ -z "$band" ]]; then | |
| freqMHz='[ 0-9][0-9]' | |
| else | |
| echo '"'$band'" is not a valid band.' | |
| print_usage | |
| exit 1 | |
| fi | |
| ;; | |
| esac | |
| head -n 2 "$ALL_RMS_FILE" | |
| cat "$ALL_RMS_FILE" | get_entries_for_grid "$to_grid" | get_entries_for_band "$freqMHz" | get_entries_for_mode "$mode" | |
| } | |
| main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment