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:
co-authored by
Claude Opus 5.5
parent
8096dcc97f
commit
ad57b6b1a4
@@ -9,7 +9,8 @@ Find the radios plugged into USB and set up HamPack's programs for them.
|
|||||||
Done: `radio detect` and `radio probe`, `radios.conf`, adding you to the uucp
|
Done: `radio detect` and `radio probe`, `radios.conf`, adding you to the uucp
|
||||||
group (6c76f94), and `radio configure` for each of HamPack's programs that
|
group (6c76f94), and `radio configure` for each of HamPack's programs that
|
||||||
control a radio, with rigctld started when the radio is plugged in, and
|
control a radio, with rigctld started when the radio is plugged in, and
|
||||||
`radio configure --auto` when a radio it knows is plugged in.
|
`radio configure --auto` when a radio it knows is plugged in, and `radio
|
||||||
|
unconfigure` to undo it.
|
||||||
|
|
||||||
- [ ] Run `TEST.md` against real radios, and mark the `radios.conf` values
|
- [ ] Run `TEST.md` against real radios, and mark the `radios.conf` values
|
||||||
they confirm `# verified`. Fix or remove the ones they don't
|
they confirm `# verified`. Fix or remove the ones they don't
|
||||||
@@ -26,6 +27,3 @@ control a radio, with rigctld started when the radio is plugged in, and
|
|||||||
(`/dev/input/by-path`), and their sound cards by ALSA card id, so they
|
(`/dev/input/by-path`), and their sound cards by ALSA card id, so they
|
||||||
stay right only while each stays in its socket. Find a name that
|
stay right only while each stays in its socket. Find a name that
|
||||||
follows the interface, or say so when you set one up
|
follows the interface, or say so when you set one up
|
||||||
- [ ] `radio unconfigure`: stop and remove the hampack-rigctld service and
|
|
||||||
the flrig autostart, and offer to put back the settings `radio
|
|
||||||
configure` backed up
|
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ A radio `radio` recognises by its USB serial number (most Icoms) is set up by it
|
|||||||
|
|
||||||
flrig can't reach a radio through rigctld, and the two can't share its port, so `radio configure` leaves flrig alone. If you'd rather flrig controlled the radio, run `radio configure --flrig`: flrig gets the radio, and rigctld passes the other programs through it, using Hamlib's FLRig support. flrig then starts when you log in (unless you have it starting already), so it's there before the other programs; leave it running. `radio configure` without --flrig gives the radio back to rigctld, and stops flrig starting at login. `radio configure` also says which sound card is the radio's.
|
flrig can't reach a radio through rigctld, and the two can't share its port, so `radio configure` leaves flrig alone. If you'd rather flrig controlled the radio, run `radio configure --flrig`: flrig gets the radio, and rigctld passes the other programs through it, using Hamlib's FLRig support. flrig then starts when you log in (unless you have it starting already), so it's there before the other programs; leave it running. `radio configure` without --flrig gives the radio back to rigctld, and stops flrig starting at login. `radio configure` also says which sound card is the radio's.
|
||||||
|
|
||||||
|
`radio unconfigure` undoes `radio configure`. It stops the `hampack-rigctld` service and removes it, and stops flrig starting when you log in, if HamPack set that up. Then it offers to put back each file `radio configure` backed up, from the oldest backup, which has your settings from before it first changed them. Anything you've changed in that program since is lost, so it asks about each one, and backs up what's there now first. QLog's log holds your contacts as well as its rig profiles, so putting it back loses contacts logged since; it's left as it is unless you say yes. Programs that are running are left alone. Afterwards, radios aren't set up when they're plugged in until you run `radio configure` again.
|
||||||
|
|
||||||
The radios it knows are in `radios.conf`. If your radio isn't recognised, or answers with something `radio` doesn't know, please open an issue with what `radio detect --probe` printed.
|
The radios it knows are in `radios.conf`. If your radio isn't recognised, or answers with something `radio` doesn't know, please open an issue with what `radio detect --probe` printed.
|
||||||
|
|
||||||
## Why CoreDesktop and/or Arch Linux?
|
## Why CoreDesktop and/or Arch Linux?
|
||||||
|
|||||||
@@ -199,6 +199,27 @@ load or an antenna:
|
|||||||
|------|--------|-------|--------|--------------|------------------------|-------|
|
|------|--------|-------|--------|--------------|------------------------|-------|
|
||||||
| | | | | | | |
|
| | | | | | | |
|
||||||
|
|
||||||
|
## radio unconfigure
|
||||||
|
|
||||||
|
After `radio configure` (and `radio configure --flrig`, to check the
|
||||||
|
autostart goes too), with the programs quit:
|
||||||
|
|
||||||
|
1. Run `radio unconfigure`, and answer y to some files and n to others.
|
||||||
|
`systemctl --user status hampack-rigctld` says there's no such unit, and
|
||||||
|
`~/.config/autostart/hampack-flrig.desktop` is gone.
|
||||||
|
2. Open each program you said y to: its rig and sound settings are as they
|
||||||
|
were before `radio configure`, and its other settings are as you left them.
|
||||||
|
QLog still opens its log, with the contacts it had then.
|
||||||
|
3. Graywolf (if you said y to it) is running again after `radio unconfigure`
|
||||||
|
stopped it with sudo, with its channels' PTT as before.
|
||||||
|
4. Unplug the radio and plug it in again: nothing is set up, and
|
||||||
|
`journalctl --user -u hampack-radio-plugged` says why. Run `radio
|
||||||
|
configure`, then unplug and plug in another radio it knows: that's set up.
|
||||||
|
|
||||||
|
| Date | Commit | Radio | rigctld removed | Settings put back | Not set up when plugged in | Notes |
|
||||||
|
|------|--------|-------|-----------------|-------------------|----------------------------|-------|
|
||||||
|
| | | | | | | |
|
||||||
|
|
||||||
## Pairing radios with sound cards
|
## Pairing radios with sound cards
|
||||||
|
|
||||||
- Two radios plugged in at once: each gets its own sound card.
|
- Two radios plugged in at once: each gets its own sound card.
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
# radio probe PORT
|
# radio probe PORT
|
||||||
# radio configure [--force] [--model N] [--flrig] [--no-cat --ptt HOW] [NUMBER]
|
# radio configure [--force] [--model N] [--flrig] [--no-cat --ptt HOW] [NUMBER]
|
||||||
# radio configure --auto
|
# radio configure --auto
|
||||||
|
# radio unconfigure
|
||||||
# radio help
|
# radio help
|
||||||
|
|
||||||
SELF="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
|
SELF="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
|
||||||
@@ -43,6 +44,9 @@ GRAYWOLF_DB="$HOME/.local/share/graywolf/graywolf.db"
|
|||||||
FLRIG_DIR="$HOME/.flrig"
|
FLRIG_DIR="$HOME/.flrig"
|
||||||
AUTOSTART_DIR="$CONFIG_HOME/autostart"
|
AUTOSTART_DIR="$CONFIG_HOME/autostart"
|
||||||
FLRIG_AUTOSTART="$AUTOSTART_DIR/hampack-flrig.desktop"
|
FLRIG_AUTOSTART="$AUTOSTART_DIR/hampack-flrig.desktop"
|
||||||
|
# Left by radio unconfigure, so radio configure --auto doesn't set a radio up
|
||||||
|
# again until you run radio configure
|
||||||
|
UNCONFIGURED="$HAMPACK_STATE/radio-unconfigured"
|
||||||
# flrig's baud rates; it saves the rate as its place in this list
|
# flrig's baud rates; it saves the rate as its place in this list
|
||||||
FLRIG_BAUDS=(300 600 1200 2400 4800 9600 19200 38400 57600 115200 230400 460800)
|
FLRIG_BAUDS=(300 600 1200 2400 4800 9600 19200 38400 57600 115200 230400 460800)
|
||||||
DIREWOLF_CONF="$HAMPACK_STATE/conf.d/direwolf.conf"
|
DIREWOLF_CONF="$HAMPACK_STATE/conf.d/direwolf.conf"
|
||||||
@@ -89,6 +93,11 @@ Usage: radio [detect] [--probe]
|
|||||||
radio recognises by its USB serial number, without asking
|
radio recognises by its USB serial number, without asking
|
||||||
it, unless the radio set up already is plugged in. Stop it
|
it, unless the radio set up already is plugged in. Stop it
|
||||||
with \`systemctl --user mask hampack-radio-plugged\`
|
with \`systemctl --user mask hampack-radio-plugged\`
|
||||||
|
unconfigure Undo radio configure: stop and remove the rigctld service
|
||||||
|
and flrig's autostart entry, and offer to put back each
|
||||||
|
program's settings from before radio configure changed
|
||||||
|
them. Radios aren't set up when they're plugged in again
|
||||||
|
until you next run radio configure
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -633,11 +642,21 @@ ini_set() {
|
|||||||
' "$1" > "$tmp" && chmod --reference="$1" "$tmp" && mv -f "$tmp" "$1"
|
' "$1" > "$tmp" && chmod --reference="$1" "$tmp" && mv -f "$tmp" "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Print a name for a backup of a file, FILE.bak-DATE-TIME, that isn't taken:
|
||||||
|
# two backups in a second get -2, -3...
|
||||||
|
backup_name() {
|
||||||
|
local name n=2
|
||||||
|
name="$1.bak-$(date +%Y%m%d-%H%M%S)"
|
||||||
|
local base="$name"
|
||||||
|
while [ -e "$name" ]; do name="$base-$((n++))"; done
|
||||||
|
echo "$name"
|
||||||
|
}
|
||||||
|
|
||||||
# Copy a file before changing it, and say so
|
# Copy a file before changing it, and say so
|
||||||
back_up() {
|
back_up() {
|
||||||
[ -f "$1" ] || return 0
|
[ -f "$1" ] || return 0
|
||||||
local copy
|
local copy
|
||||||
copy="$1.bak-$(date +%Y%m%d-%H%M%S)"
|
copy="$(backup_name "$1")"
|
||||||
cp -p "$1" "$copy" && BACKUPS+=("$copy")
|
cp -p "$1" "$copy" && BACKUPS+=("$copy")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1300,7 +1319,7 @@ configure_qlog() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
local backup
|
local backup
|
||||||
backup="$QLOG_DB.bak-$(date +%Y%m%d-%H%M%S)"
|
backup="$(backup_name "$QLOG_DB")"
|
||||||
result="$(qlog_profile "$backup")"
|
result="$(qlog_profile "$backup")"
|
||||||
case "$result" in
|
case "$result" in
|
||||||
added)
|
added)
|
||||||
@@ -1514,7 +1533,7 @@ configure_graywolf() {
|
|||||||
fi
|
fi
|
||||||
was_active=1
|
was_active=1
|
||||||
fi
|
fi
|
||||||
backup="$GRAYWOLF_DB.bak-$(date +%Y%m%d-%H%M%S)"
|
backup="$(backup_name "$GRAYWOLF_DB")"
|
||||||
result="$(graywolf_setup "$backup" "$device" "$2")"
|
result="$(graywolf_setup "$backup" "$device" "$2")"
|
||||||
(( ! was_active )) || sudo systemctl start graywolf
|
(( ! was_active )) || sudo systemctl start graywolf
|
||||||
read -r added changed kept <<< "$result"
|
read -r added changed kept <<< "$result"
|
||||||
@@ -1808,6 +1827,7 @@ configure() {
|
|||||||
configure_potacat "$name"
|
configure_potacat "$name"
|
||||||
configure_graywolf "$card" "$name"
|
configure_graywolf "$card" "$name"
|
||||||
|
|
||||||
|
rm -f "$UNCONFIGURED"
|
||||||
mkdir -p "$HAMPACK_STATE" &&
|
mkdir -p "$HAMPACK_STATE" &&
|
||||||
printf 'name=%s\nhamlib=%s\nport=%s\nbaud=%s\ncard=%s\ncontroller=%s\nptt=%s\n' "$name" "$model" "$port" "$baud" "$card" \
|
printf 'name=%s\nhamlib=%s\nport=%s\nbaud=%s\ncard=%s\ncontroller=%s\nptt=%s\n' "$name" "$model" "$port" "$baud" "$card" \
|
||||||
"$( (( USE_FLRIG )) && echo flrig || echo rigctld)" "${ptt:-cat}" > "$HAMPACK_STATE/radio"
|
"$( (( USE_FLRIG )) && echo flrig || echo rigctld)" "${ptt:-cat}" > "$HAMPACK_STATE/radio"
|
||||||
@@ -1856,6 +1876,10 @@ notify() {
|
|||||||
# Graywolf is left alone while it runs, since stopping it needs sudo
|
# Graywolf is left alone while it runs, since stopping it needs sudo
|
||||||
auto_configure() {
|
auto_configure() {
|
||||||
local i known=() name="" card_sys out status tries=0 skipped
|
local i known=() name="" card_sys out status tries=0 skipped
|
||||||
|
if [ -f "$UNCONFIGURED" ]; then
|
||||||
|
echo "\`radio unconfigure\` was run, so radios aren't set up when they're plugged in until you run \`radio configure\`."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
# The radio's sound card may come up after its serial port
|
# The radio's sound card may come up after its serial port
|
||||||
udevadm settle --timeout=10 > /dev/null 2>&1
|
udevadm settle --timeout=10 > /dev/null 2>&1
|
||||||
find_radios
|
find_radios
|
||||||
@@ -1901,10 +1925,147 @@ auto_configure() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Copy an SQLite database through SQLite, which takes in what's still in its
|
||||||
|
# write-ahead log, and leaves no stale log to be applied to the copy:
|
||||||
|
# copy_db FROM TO
|
||||||
|
copy_db() {
|
||||||
|
python3 -I -c 'import sqlite3, sys
|
||||||
|
src, dst = sqlite3.connect(sys.argv[1]), sqlite3.connect(sys.argv[2])
|
||||||
|
src.backup(dst)
|
||||||
|
dst.close()
|
||||||
|
src.close()' "$1" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
# The program a file radio configure changes belongs to, as NAME|PROCESS,
|
||||||
|
# with PROCESS "graywolf.service" for Graywolf's system service
|
||||||
|
program_of() {
|
||||||
|
case "$1" in
|
||||||
|
"$WSJTX_CONF") echo "WSJT-X|wsjtx" ;;
|
||||||
|
"$JS8CALL_CONF") echo "JS8Call|JS8Call" ;;
|
||||||
|
"$FLRIG_DIR"/*) echo "flrig|flrig" ;;
|
||||||
|
"$PAT_CONF") echo "Pat|pat" ;;
|
||||||
|
"$FLDIGI_CONF") echo "fldigi|fldigi" ;;
|
||||||
|
"$DIREWOLF_CONF") echo "Dire Wolf|direwolf" ;;
|
||||||
|
"$NOT1MM_CONF") echo "not1mm|not1mm" ;;
|
||||||
|
"$QLOG_DB") echo "QLog|qlog" ;;
|
||||||
|
"$POTACAT_DIR"/*) echo "POTACAT|potacat" ;;
|
||||||
|
"$GRAYWOLF_DB") echo "Graywolf|graywolf.service" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Put a file back from a backup radio configure made, backing up what's there
|
||||||
|
# now first. Prints the copy of what was there: restore_backup FILE BACKUP
|
||||||
|
restore_backup() {
|
||||||
|
local copy
|
||||||
|
copy="$(backup_name "$1")"
|
||||||
|
if [[ "$1" == *.db ]]; then
|
||||||
|
if [ -f "$1" ]; then copy_db "$1" "$copy" || return 1; else copy=""; fi
|
||||||
|
copy_db "$2" "$1" || return 1
|
||||||
|
else
|
||||||
|
if [ -f "$1" ]; then cp -p "$1" "$copy" || return 1; else copy=""; fi
|
||||||
|
mkdir -p "$(dirname "$1")" && cp -p "$2" "$1" || return 1
|
||||||
|
fi
|
||||||
|
echo "$copy"
|
||||||
|
}
|
||||||
|
|
||||||
|
# radio unconfigure: undo radio configure. Stop and remove the rigctld
|
||||||
|
# service and flrig's autostart entry, then offer to put back each program's
|
||||||
|
# settings from the oldest backup radio configure made of them, which is
|
||||||
|
# from before it first changed them. Backups are found by their names, next
|
||||||
|
# to the files they're of
|
||||||
|
unconfigure() {
|
||||||
|
[ $# -eq 0 ] || { usage >&2; return 2; }
|
||||||
|
local did=0 b file files=() name process when copy answer was_active kept=()
|
||||||
|
local -A oldest=() newer=()
|
||||||
|
|
||||||
|
if [ -f "$RIGCTLD_UNIT" ]; then
|
||||||
|
systemctl --user disable --now hampack-rigctld 2> /dev/null
|
||||||
|
rm -f "$RIGCTLD_UNIT"
|
||||||
|
systemctl --user daemon-reload 2> /dev/null
|
||||||
|
report rigctld "stopped, and the hampack-rigctld service removed"
|
||||||
|
did=1
|
||||||
|
fi
|
||||||
|
if remove_flrig_autostart; then
|
||||||
|
report flrig "no longer starts when you log in"
|
||||||
|
did=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for b in "$WSJTX_CONF".bak-* "$JS8CALL_CONF".bak-* "$FLRIG_DIR"/*.prefs.bak-* "$PAT_CONF".bak-* \
|
||||||
|
"$FLDIGI_CONF".bak-* "$DIREWOLF_CONF".bak-* "$NOT1MM_CONF".bak-* "$QLOG_DB".bak-* \
|
||||||
|
"$POTACAT_DIR"/settings.json.bak-* "$POTACAT_DIR"/profiles/*/settings.json.bak-* "$GRAYWOLF_DB".bak-*; do
|
||||||
|
[[ -f "$b" && "$b" =~ \.bak-[0-9]{8}-[0-9]{6}(-[0-9]+)?$ ]] || continue
|
||||||
|
file="${b%.bak-*}"
|
||||||
|
# Globs sort, so the first backup of each file is the oldest (-2 sorts
|
||||||
|
# after the backup it came the same second as)
|
||||||
|
if [ -z "${oldest[$file]:-}" ]; then
|
||||||
|
oldest[$file]="$b"
|
||||||
|
files+=("$file")
|
||||||
|
else
|
||||||
|
newer[$file]=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ${#files[@]} -gt 0 ]; then
|
||||||
|
did=1
|
||||||
|
echo
|
||||||
|
echo "radio configure backed up these settings before changing them. Putting them back loses anything you've changed since; what's there now is backed up first."
|
||||||
|
for file in "${files[@]}"; do
|
||||||
|
b="${oldest[$file]}"
|
||||||
|
IFS='|' read -r name process <<< "$(program_of "$file")"
|
||||||
|
when="${b##*.bak-}"
|
||||||
|
when="${when:0:4}-${when:4:2}-${when:6:2} at ${when:9:2}:${when:11:2}"
|
||||||
|
if [ "$process" != graywolf.service ] && running "$process"; then
|
||||||
|
report "$name" "left as it is, because it's running. Quit it and run \`radio unconfigure\` again"
|
||||||
|
kept+=("$name")
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
[ "$name" != QLog ] || echo " QLog's log holds your contacts: any you've logged since $when won't be in the log put back."
|
||||||
|
printf 'Put back %s, as it was on %s? [y/N] ' "${file/#$HOME/\~}" "$when"
|
||||||
|
answer=""
|
||||||
|
read -r answer || echo
|
||||||
|
if [[ ! "$answer" =~ ^[yY] ]]; then
|
||||||
|
kept+=("$name")
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
was_active=0
|
||||||
|
if [ "$process" = graywolf.service ] && systemctl is-active --quiet graywolf 2> /dev/null; then
|
||||||
|
if ! sudo systemctl stop graywolf; then
|
||||||
|
report "$name" "left as it is: couldn't stop it to put its settings back"
|
||||||
|
kept+=("$name")
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
was_active=1
|
||||||
|
fi
|
||||||
|
if copy="$(restore_backup "$file" "$b")"; then
|
||||||
|
report "$name" "put back${copy:+. What was there is in $copy}"
|
||||||
|
else
|
||||||
|
report "$name" "couldn't put back ${file/#$HOME/\~} from $b"
|
||||||
|
kept+=("$name")
|
||||||
|
fi
|
||||||
|
(( ! was_active )) || sudo systemctl start graywolf
|
||||||
|
done
|
||||||
|
[ -z "${newer[*]}" ] || echo "Later backups radio configure made are still there, next to each file."
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f "$HAMPACK_STATE/radio"
|
||||||
|
mkdir -p "$HAMPACK_STATE" && touch "$UNCONFIGURED"
|
||||||
|
echo
|
||||||
|
if (( ! did )); then
|
||||||
|
echo "radio configure hasn't set anything up, so there's nothing to undo."
|
||||||
|
elif [ ${#kept[@]} -gt 0 ]; then
|
||||||
|
local IFS='|' list
|
||||||
|
list="${kept[*]}"
|
||||||
|
list="$(sort -u <<< "${list//|/$'\n'}" | paste -sd '|')"
|
||||||
|
echo "${list//|/, } may still use rigctld on $RIGCTLD_ADDR, which isn't running now: set their rig control yourself, or run \`radio configure\` to set it up again."
|
||||||
|
fi
|
||||||
|
echo "Radios aren't set up when they're plugged in until you run \`radio configure\` again."
|
||||||
|
}
|
||||||
|
|
||||||
case "${1:-detect}" in
|
case "${1:-detect}" in
|
||||||
detect) shift; detect "$@" ;;
|
detect) shift; detect "$@" ;;
|
||||||
probe) shift; probe "$@" ;;
|
probe) shift; probe "$@" ;;
|
||||||
configure) shift; configure "$@" ;;
|
configure) shift; configure "$@" ;;
|
||||||
|
unconfigure) shift; unconfigure "$@" ;;
|
||||||
help | -h | --help) usage ;;
|
help | -h | --help) usage ;;
|
||||||
--probe) detect --probe ;;
|
--probe) detect --probe ;;
|
||||||
*) usage >&2; exit 2 ;;
|
*) usage >&2; exit 2 ;;
|
||||||
|
|||||||
@@ -1586,3 +1586,109 @@ auto() {
|
|||||||
run bash "$REPO/radio" configure --auto --force
|
run bash "$REPO/radio" configure --auto --force
|
||||||
[ "$status" -eq 2 ]
|
[ "$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 ]
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user