`radio` lists each radio plugged into USB: its serial ports, the sound card that came with it (the same USB device, or behind the radio's own hub), and its model and Hamlib model number. Icoms are recognised by their USB serial number. `radio detect --probe` asks the others with the CAT ID; command or Icom's CI-V transceiver ID, at the usual baud rates, on ports no other program has open; `radio probe PORT` asks one port. It drops DTR and RTS as soon as a port opens. The radios it knows are in radios.conf. update.sh links ~/.local/bin/radio to the clone, unless a different radio is already there, and adds you to uucp, which owns serial ports on Arch. hampackremove removes the link, and takes you out of uucp only if HamPack put you in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
159 lines
5.4 KiB
Bash
159 lines
5.4 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
# Checks of HamPack's own config files, so a typo in one fails here rather than
|
|
# halfway through someone's update. Whether the packages in packages.conf
|
|
# exist upstream needs the network: `./hampackcheck packages` checks that.
|
|
|
|
load helpers
|
|
|
|
setup() {
|
|
setup_fake_home
|
|
source "$REPO/lib.sh"
|
|
PROBLEMS=()
|
|
}
|
|
|
|
# Report each problem; fail if there are any
|
|
no_problems() {
|
|
printf '%s\n' "${PROBLEMS[@]}"
|
|
[ ${#PROBLEMS[@]} -eq 0 ]
|
|
}
|
|
|
|
problem() { PROBLEMS+=("[${CONF[_name]}] $*"); }
|
|
|
|
# Fields with names not in the list given
|
|
check_keys() {
|
|
local key
|
|
for key in "${!CONF[@]}"; do
|
|
[ "$key" = _name ] || [[ " $* " == *" $key "* ]] || problem "unknown field $key="
|
|
done
|
|
}
|
|
|
|
check_required() {
|
|
local key
|
|
for key; do
|
|
[ -n "${CONF[$key]}" ] || problem "needs $key="
|
|
done
|
|
}
|
|
|
|
# A path under $HAMPACK_DIR must exist in the repo
|
|
check_repo_path() {
|
|
local value="${CONF[$1]}"
|
|
if [[ "$value" == '$HAMPACK_DIR/'* ]] && [ ! -e "$(expand_vars "$value")" ]; then
|
|
problem "$1=$value doesn't exist"
|
|
fi
|
|
}
|
|
|
|
check_compiled() {
|
|
check_keys name version git ref wget install steps gui desktop
|
|
check_required version install steps
|
|
if { [ -n "${CONF[git]}" ] && [ -n "${CONF[wget]}" ]; } || { [ -z "${CONF[git]}" ] && [ -z "${CONF[wget]}" ]; }; then
|
|
problem "needs exactly one of git= and wget="
|
|
fi
|
|
if [ -n "${CONF[ref]}" ]; then
|
|
[ -n "${CONF[git]}" ] || problem "ref= needs git="
|
|
[[ "${CONF[ref]}" =~ ^[0-9a-f]{40}$ ]] || problem "ref= should be a full commit hash"
|
|
fi
|
|
[ -z "${CONF[gui]}" ] || [ "${CONF[gui]}" = true ] || problem "gui= should be true or left out"
|
|
check_repo_path desktop
|
|
[[ "${CONF[install]}" == '$HOME/'* ]] || problem "install= should be under \$HOME"
|
|
}
|
|
|
|
check_binary() {
|
|
check_keys version url sha256 install exec gui comment icon categories
|
|
check_required version url sha256 install
|
|
[ -z "${CONF[sha256]}" ] || [[ "${CONF[sha256]}" =~ ^[0-9a-f]{64}$ ]] || problem "sha256= isn't a SHA-256"
|
|
[[ "${CONF[url]}" == https://* ]] || problem "url= should be https://"
|
|
[ -z "${CONF[gui]}" ] || [ "${CONF[gui]}" = true ] || [ "${CONF[gui]}" = false ] || problem "gui= should be true or false"
|
|
check_repo_path icon
|
|
[[ "${CONF[install]}" == '$HOME/'* ]] || problem "install= should be under \$HOME"
|
|
}
|
|
|
|
# Section names must be unique: the version record is keyed by them
|
|
check_unique_sections() {
|
|
local dup
|
|
dup="$(sed -n 's/^\[\(.*\)\]$/\1/p' "$1" | sort | uniq -d)"
|
|
[ -z "$dup" ] || PROBLEMS+=("$(basename "$1") lists $dup more than once")
|
|
}
|
|
|
|
@test "compile.conf: every app has the fields it needs and no unknown ones" {
|
|
parse_conf "$REPO/compile.conf" check_compiled
|
|
check_unique_sections "$REPO/compile.conf"
|
|
no_problems
|
|
}
|
|
|
|
@test "binaries.conf: every binary has a url, a SHA-256 and the fields it needs" {
|
|
parse_conf "$REPO/binaries.conf" check_binary
|
|
check_unique_sections "$REPO/binaries.conf"
|
|
no_problems
|
|
}
|
|
|
|
@test "the conf checks catch typos and missing fields" {
|
|
local conf="$BATS_TEST_TMPDIR/compile.conf"
|
|
cat > "$conf" << 'EOF'
|
|
[ok]
|
|
version=1
|
|
git=https://example.com/ok
|
|
install=$HOME/.local/bin/ok
|
|
steps=make
|
|
[broken]
|
|
verison=1
|
|
git=https://example.com/a
|
|
wget=https://example.com/a.zip
|
|
ref=main
|
|
install=/usr/bin/broken
|
|
desktop=$HAMPACK_DIR/desktop/nope.desktop
|
|
steps=make
|
|
EOF
|
|
parse_conf "$conf" check_compiled
|
|
run no_problems
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" != *"[ok]"* ]]
|
|
[[ "$output" == *"[broken] unknown field verison="* ]]
|
|
[[ "$output" == *"[broken] needs version="* ]]
|
|
[[ "$output" == *"[broken] needs exactly one of git= and wget="* ]]
|
|
[[ "$output" == *"[broken] ref= should be a full commit hash"* ]]
|
|
[[ "$output" == *"[broken] desktop=\$HAMPACK_DIR/desktop/nope.desktop doesn't exist"* ]]
|
|
[[ "$output" == *"[broken] install= should be under \$HOME"* ]]
|
|
}
|
|
|
|
check_radio() {
|
|
check_keys hamlib usb_serial cat_id civ
|
|
check_required hamlib
|
|
[[ "${CONF[hamlib]}" =~ ^[0-9]+$ ]] || problem "hamlib= should be a Hamlib model number"
|
|
[ -n "${CONF[usb_serial]}${CONF[cat_id]}${CONF[civ]}" ] || problem "needs usb_serial=, cat_id= or civ="
|
|
[ -z "${CONF[cat_id]}" ] || [[ "${CONF[cat_id]}" =~ ^[0-9]{3,4}$ ]] || problem "cat_id= should be 3 or 4 digits"
|
|
[ -z "${CONF[civ]}" ] || [[ "${CONF[civ]}" =~ ^[0-9A-F]{2}$ ]] || problem "civ= should be two hex digits, in capitals"
|
|
}
|
|
|
|
@test "radios.conf: every radio has a Hamlib model and a way to recognise it" {
|
|
parse_conf "$REPO/radios.conf" check_radio
|
|
check_unique_sections "$REPO/radios.conf"
|
|
no_problems
|
|
}
|
|
|
|
@test "packages.conf: names are valid, listed once, and the Flatpaks look like app IDs" {
|
|
local p
|
|
while IFS= read -r p; do
|
|
[[ "$p" =~ ^[a-z0-9@_+][a-z0-9@._+-]*$ ]] || PROBLEMS+=("bad package name: $p")
|
|
done < <(all_hampack_packages)
|
|
while IFS= read -r p; do
|
|
[[ "$p" =~ ^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+){2,}$ ]] || PROBLEMS+=("bad Flatpak ID: $p")
|
|
done < <(all_hampack_flatpaks)
|
|
p="$( { all_hampack_packages; all_hampack_flatpaks; } | sort | uniq -d)"
|
|
[ -z "$p" ] || PROBLEMS+=("listed more than once: $p")
|
|
no_problems
|
|
}
|
|
|
|
@test "desktop files: each has a Name= and an Exec=, and its icon is in the repo" {
|
|
local f icon
|
|
for f in "$REPO"/desktop/*.desktop; do
|
|
grep -q "^Exec=" "$f" || PROBLEMS+=("$(basename "$f") has no Exec=")
|
|
grep -q "^Name=" "$f" || PROBLEMS+=("$(basename "$f") has no Name=")
|
|
icon="$(sed -n 's/^Icon=//p' "$f")"
|
|
if [[ "$icon" == '$HAMPACK_DIR/'* ]] && [ ! -e "$(expand_vars "$icon")" ]; then
|
|
PROBLEMS+=("$(basename "$f"): $icon doesn't exist")
|
|
fi
|
|
done
|
|
no_problems
|
|
}
|