Undo radio configure with radio unconfigure

Stop and remove the hampack-rigctld service and HamPack's flrig autostart,
and offer to put back each file radio configure backed up, from its oldest
backup. What's there now is backed up first, databases are copied through
SQLite, running programs are left alone, and --auto doesn't set a radio up
again until radio configure is run.

Backups made in the same second no longer overwrite each other.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-29 12:34:41 -07:00
co-authored by Claude Opus 5.5
parent 8096dcc97f
commit ad57b6b1a4
5 changed files with 295 additions and 7 deletions
+106
View File
@@ -1586,3 +1586,109 @@ auto() {
run bash "$REPO/radio" configure --auto --force
[ "$status" -eq 2 ]
}
# --- radio unconfigure ---
@test "unconfigure stops and removes rigctld and flrig's autostart, and stops --auto setting the radio up" {
configurable
run bash "$REPO/radio" configure --flrig
[ "$status" -eq 0 ]
: > "$STUB_LOG"
run bash "$REPO/radio" unconfigure < /dev/null
[ "$status" -eq 0 ]
[[ "$output" == *"rigctld: stopped, and the hampack-rigctld service removed"* ]]
[[ "$output" == *"flrig: no longer starts when you log in"* ]]
grep -qx "systemctl --user disable --now hampack-rigctld" "$STUB_LOG"
[ ! -e "$HOME/.config/systemd/user/hampack-rigctld.service" ]
[ ! -e "$(FLRIG_AUTOSTART)" ]
[ ! -e "$HAMPACK_STATE/radio" ]
auto
[ "$status" -eq 0 ]
[[ "$output" == *"until you run \`radio configure\`"* ]]
! grep -q "reenable" "$STUB_LOG"
# radio configure turns --auto back on
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[ ! -e "$HAMPACK_STATE/radio-unconfigured" ]
}
@test "unconfigure leaves an flrig autostart that isn't HamPack's" {
configurable
mkdir -p "$HOME/.config/autostart"
printf '[Desktop Entry]\nType=Application\nExec=flrig\n' > "$(FLRIG_AUTOSTART)"
run bash "$REPO/radio" unconfigure < /dev/null
[ -e "$(FLRIG_AUTOSTART)" ]
[[ "$output" == *"radio configure hasn't set anything up, so there's nothing to undo."* ]]
}
@test "unconfigure puts back the settings from before radio configure changed them, when you say yes" {
configurable
local pat="$HOME/.config/pat/config.json" pat_before contacts
pat_before="$(cat "$pat")"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
qlog_query "INSERT INTO contacts (callsign) VALUES ('K1ABC')"
run bash "$REPO/radio" unconfigure < <(yes y)
[ "$status" -eq 0 ]
[[ "$output" == *"Put back ~/.config/pat/config.json, as it was on "* ]]
[[ "$output" == *"Pat: put back. What was there is in $pat.bak-"* ]]
[ "$(cat "$pat")" = "$pat_before" ]
[ "$(stat -c %a "$pat")" = 600 ]
# QLog's log, through SQLite, with a warning about contacts logged since
[[ "$output" == *"QLog's log holds your contacts: any you've logged since "*" won't be in the log put back."* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM rig_profiles")" = 0 ]
[ "$(qlog_query "SELECT callsign FROM contacts")" = W1AW ]
# ...and the log as it was is kept
contacts="$(for b in "$(QLOG_DB)".bak-*; do qlog_query "SELECT COUNT(*) FROM contacts" "$b"; done | sort | tail -1)"
[ "$contacts" = 2 ]
[[ "$output" != *"may still use rigctld"* ]]
}
@test "unconfigure puts back the oldest backup of each file, and leaves the ones you say no to" {
configurable
local pat="$HOME/.config/pat/config.json" fldigi pat_set fldigi_set
fldigi="$(FLDIGI_XML)"
run bash "$REPO/radio" configure
pat_set="$(cat "$pat")"
fldigi_set="$(cat "$fldigi")"
echo '{"mycall": "OLDEST"}' > "$pat.bak-20200101-000000"
# Not one of radio configure's
echo '{"mycall": "MINE"}' > "$pat.bak-mine"
run bash "$REPO/radio" unconfigure < /dev/null
[ "$status" -eq 0 ]
[ "$(cat "$pat")" = "$pat_set" ]
[ "$(cat "$fldigi")" = "$fldigi_set" ]
[[ "$output" == *"Put back ~/.config/pat/config.json, as it was on 2020-01-01 at 00:00? [y/N] "* ]]
[[ "$output" == *"Later backups radio configure made are still there"* ]]
[[ "$output" == *"fldigi, "*"Pat"*" may still use rigctld on 127.0.0.1:4532, which isn't running now"* ]]
run bash "$REPO/radio" unconfigure < <(yes y)
[ "$(jq -r .mycall "$pat")" = OLDEST ]
}
@test "unconfigure leaves programs that are running, and stops Graywolf to put it back" {
configurable
run bash "$REPO/radio" configure
local fldigi_set
fldigi_set="$(cat "$(FLDIGI_XML)")"
stub systemctl '[ "$*" != "--user is-active --quiet hampack-rigctld" ] && [ "$*" != "is-active --quiet graywolf" ] || [ -f "$FAKE_RADIOS/rigctld-active" ]'
touch "$FAKE_RADIOS/rigctld-active"
: > "$STUB_LOG"
FAKE_RUNNING=fldigi run bash "$REPO/radio" unconfigure < <(yes y)
[ "$status" -eq 0 ]
[[ "$output" == *"fldigi: left as it is, because it's running. Quit it and run \`radio unconfigure\` again"* ]]
[ "$(cat "$(FLDIGI_XML)")" = "$fldigi_set" ]
grep -qx "systemctl stop graywolf" "$STUB_LOG"
grep -qx "systemctl start graywolf" "$STUB_LOG"
[[ "$output" == *"Graywolf: put back"* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM ptt_configs WHERE method = 'rigctld'" "$(GRAYWOLF_DB)")" = 0 ]
}
@test "unconfigure takes no options" {
run bash "$REPO/radio" unconfigure --force
[ "$status" -eq 2 ]
}