Set up a radio radio knows when it's plugged in, with radio configure --auto
check / lint-and-test (push) Successful in 3m57s
check / packages (push) Successful in 24s

A udev rule starts the hampack-radio-plugged user service when a USB serial
port appears, and it runs `radio configure --auto`. That sets up a radio
recognised by its USB serial number, unless the radio set up already is
plugged in, and says what it did in a desktop notification. It never asks a
radio what it is, since that may key the transmitter, and never asks for
sudo, so a running Graywolf is skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-28 16:32:05 -07:00
co-authored by Claude Opus 5.5
parent f2e29ab46d
commit 8d15d2c81e
11 changed files with 309 additions and 18 deletions
+2 -3
View File
@@ -8,9 +8,8 @@ keeps the record. Checks that need real radios are in `TEST.md`.
Find the radios plugged into USB and set up HamPack's programs for them. 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. control a radio, with rigctld started when the radio is plugged in, and
`radio configure --auto` when a radio it knows is plugged in.
- [ ] 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
- [ ] Later: run `radio configure` when a known radio is plugged in (a udev
rule starting a systemd user unit)
+2
View File
@@ -73,6 +73,8 @@ It also gives WSJT-X, JS8Call, fldigi, Dire Wolf, not1mm's voice keyer and POTAC
A radio with no CAT can be set up too, on an interface that keys it: rigctld then runs Hamlib's Dummy radio, which only keys the radio, and the programs reach it as before. A sound card with no serial port (an AIOC, a CM108 cable, a SignaLink) is numbered after the radios in `radio`'s list: `radio configure 2` keys the radio through its CM108 PTT pin if it has one, or leaves it to the radio's VOX. For an interface with a serial port, such as a Digirig on a handheld, say how it keys the radio: `radio configure --no-cat --ptt rts` (or `dtr`, `cm108` or `vox`). A radio with no CAT can be set up too, on an interface that keys it: rigctld then runs Hamlib's Dummy radio, which only keys the radio, and the programs reach it as before. A sound card with no serial port (an AIOC, a CM108 cable, a SignaLink) is numbered after the radios in `radio`'s list: `radio configure 2` keys the radio through its CM108 PTT pin if it has one, or leaves it to the radio's VOX. For an interface with a serial port, such as a Digirig on a handheld, say how it keys the radio: `radio configure --no-cat --ptt rts` (or `dtr`, `cm108` or `vox`).
A radio `radio` recognises by its USB serial number (most Icoms) is set up by itself when you plug it in, as if you'd run `radio configure`, unless the radio set up already is plugged in. A notification says what it did, and `journalctl --user -u hampack-radio-plugged` has the details. Programs that are running are skipped, as is Graywolf if it's running, since stopping it needs sudo; run `radio configure` for those afterwards. Radios it would have to ask what they are, and interfaces with no CAT, are left for you to set up, since asking raises the port's DTR and RTS lines, which may key the transmitter while nobody's there. A udev rule, `/etc/udev/rules.d/70-hampack-radio.rules`, starts the `hampack-radio-plugged` user service when a USB serial port appears. To turn it off, run `systemctl --user mask hampack-radio-plugged`.
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.
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.
+31
View File
@@ -168,6 +168,37 @@ With a Digirig, an AIOC or another CM108-family interface plugged in, after
|------|--------|-----------|-----|----------------|-------| |------|--------|-----------|-----|----------------|-------|
| 2026-11-28 | 1cccdcd | C-Media USB Audio Device, 0d8c:0012, no radio attached | Yes, but from another rule (60-xara-ptt.rules); HamPack's rule not yet installed here | Not tried | Steps 1, 3 and 5 pass: `radio` lists it as "PTT through CM108 on /dev/hidraw3" and leaves out a Logitech BRIO webcam; Dire Wolf's `cm108` marks it `**`. Hamlib 4.7.2 `rigctl -m 1 -p /dev/input/by-id/...-if03-hidraw -P CM108 T 0` opens the by-id link, detects it as CM108-compatible and sets GPIO3, with no error. Getting PTT state (`t`) gives "Feature not implemented", which is Hamlib's CM108 support, and doesn't matter to the programs | | 2026-11-28 | 1cccdcd | C-Media USB Audio Device, 0d8c:0012, no radio attached | Yes, but from another rule (60-xara-ptt.rules); HamPack's rule not yet installed here | Not tried | Steps 1, 3 and 5 pass: `radio` lists it as "PTT through CM108 on /dev/hidraw3" and leaves out a Logitech BRIO webcam; Dire Wolf's `cm108` marks it `**`. Hamlib 4.7.2 `rigctl -m 1 -p /dev/input/by-id/...-if03-hidraw -P CM108 T 0` opens the by-id link, detects it as CM108-compatible and sets GPIO3, with no error. Getting PTT state (`t`) gives "Feature not implemented", which is Hamlib's CM108 support, and doesn't matter to the programs |
## Setting up a radio when it's plugged in
After `update` has installed `/etc/udev/rules.d/70-hampack-radio.rules` and
`~/.config/systemd/user/hampack-radio-plugged.service`, with an Icom that
`radio` recognises by its USB serial number (an IC-7300, say), on a dummy
load or an antenna:
1. Move `~/.local/state/HamPack/radio` aside, if it's there, so no radio is
set up. Quit WSJT-X and the rest, and plug the radio in. Within a few
seconds a notification says "HamPack set up the Icom IC-7300", and
`journalctl --user -u hampack-radio-plugged` shows `radio configure`'s
output, including the radio's sound card by PipeWire's name. If it says
PipeWire didn't list the card, note it: it waited up to 10 seconds.
2. `systemctl --user status hampack-rigctld` is running, and WSJT-X's
"Test CAT" works.
3. Unplug the radio and plug it in again: the journal says it stays set up,
and there's no notification.
4. With WSJT-X running, and Graywolf running, move the state file aside and
plug in again: the notification says WSJT-X and Graywolf were skipped, and
nothing asked for a password.
5. Plug in a Yaesu or a Digirig instead: nothing is set up, and the radio's
TX indicator never lights.
6. Log in with the radio plugged in and not set up: note whether it's set up
at login, too (systemd may only act on the rule when the port appears).
7. `systemctl --user mask hampack-radio-plugged`, then plug in: nothing
happens. `systemctl --user unmask hampack-radio-plugged` afterwards.
| Date | Commit | Radio | Set up | Notification | Left alone when set up | 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.
+13 -3
View File
@@ -266,11 +266,21 @@ if [ -f "$RIGCTLD_UNIT" ]; then
systemctl --user daemon-reload 2> /dev/null systemctl --user daemon-reload 2> /dev/null
fi fi
# The service update.sh installed to set up a radio when it's plugged in
RADIO_SERVICE="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user/hampack-radio-plugged.service"
if [ -f "$RADIO_SERVICE" ]; then
rm -f "$RADIO_SERVICE"
systemctl --user daemon-reload 2> /dev/null
fi
# The udev rules update.sh installed # The udev rules update.sh installed
UDEV_RULES="${HAMPACK_UDEV_RULES_DIR:-/etc/udev/rules.d}/70-hampack-cm108.rules" UDEV_RULES=()
if [ -e "$UDEV_RULES" ]; then for rules in "${HAMPACK_UDEV_RULES_DIR:-/etc/udev/rules.d}"/70-hampack-{cm108,radio}.rules; do
[ ! -e "$rules" ] || UDEV_RULES+=("$rules")
done
if [ ${#UDEV_RULES[@]} -gt 0 ]; then
echo "Removing HamPack's udev rules..." echo "Removing HamPack's udev rules..."
sudo rm -f "$UDEV_RULES" && sudo udevadm control --reload-rules sudo rm -f "${UDEV_RULES[@]}" && sudo udevadm control --reload-rules
fi fi
# The flrig autostart entry `radio configure --flrig` added, marked as HamPack's # The flrig autostart entry `radio configure --flrig` added, marked as HamPack's
+97
View File
@@ -7,6 +7,7 @@
# Usage : radio [detect] [--probe] # Usage : radio [detect] [--probe]
# 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 help # radio help
SELF="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" SELF="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
@@ -19,6 +20,10 @@ SYSFS="${RADIO_SYSFS:-/sys}"
DEVDIR="${RADIO_DEV:-/dev}" DEVDIR="${RADIO_DEV:-/dev}"
PROC="${RADIO_PROC:-/proc}" PROC="${RADIO_PROC:-/proc}"
LOCKDIR="${RADIO_LOCKDIR:-/run/lock}" LOCKDIR="${RADIO_LOCKDIR:-/run/lock}"
# How long radio configure --auto waits for PipeWire to list a radio just
# plugged in, in seconds
AUTO_WAIT="${RADIO_AUTO_WAIT:-10}"
AUTO=0
# CAT baud rates to try, most likely first # CAT baud rates to try, most likely first
BAUDS=(38400 115200 19200 9600 4800) BAUDS=(38400 115200 19200 9600 4800)
@@ -79,6 +84,11 @@ Usage: radio [detect] [--probe]
PTT pin), rts or dtr (its serial port's lines), or vox PTT pin), rts or dtr (its serial port's lines), or vox
(the radio keys itself on the audio). A sound card is (the radio keys itself on the audio). A sound card is
cm108 if it can be, and vox otherwise cm108 if it can be, and vox otherwise
configure --auto
What runs when a USB serial port appears: set up a radio
radio recognises by its USB serial number, without asking
it, unless the radio set up already is plugged in. Stop it
with \`systemctl --user mask hampack-radio-plugged\`
EOF EOF
} }
@@ -1494,6 +1504,10 @@ configure_graywolf() {
if [ "$added" = 1 ] || [[ "$changed" =~ ^[1-9][0-9]*$ ]]; then if [ "$added" = 1 ] || [[ "$changed" =~ ^[1-9][0-9]*$ ]]; then
# It runs as a system service, and reads its settings when it starts # It runs as a system service, and reads its settings when it starts
if systemctl is-active --quiet graywolf 2> /dev/null; then if systemctl is-active --quiet graywolf 2> /dev/null; then
if (( AUTO )); then
report Graywolf "skipped: it's running, and stopping it to change its settings needs sudo. Run \`radio configure\` to set it up"
return
fi
if ! sudo systemctl stop graywolf; then if ! sudo systemctl stop graywolf; then
report Graywolf "skipped: couldn't stop it to change its settings. Instead, $manual" report Graywolf "skipped: couldn't stop it to change its settings. Instead, $manual"
return return
@@ -1575,6 +1589,11 @@ configure() {
local number="" model="" radio="" sound_card="" sound_dev="" was_running=0 name port="" baud="" card card_sys local number="" model="" radio="" sound_card="" sound_dev="" was_running=0 name port="" baud="" card card_sys
local flrig_name="" flrig_port=12345 no_cat=0 ptt="" ptt_type="" ptt_device="" ptt_text="" sound_only total local flrig_name="" flrig_port=12345 no_cat=0 ptt="" ptt_type="" ptt_device="" ptt_text="" sound_only total
FORCE=0 BACKUPS=() USE_FLRIG=0 FORCE=0 BACKUPS=() USE_FLRIG=0
if [ "${1:-}" = --auto ]; then
[ $# -eq 1 ] || { usage >&2; return 2; }
auto_configure
return
fi
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
--force) FORCE=1 ;; --force) FORCE=1 ;;
@@ -1804,6 +1823,84 @@ configure() {
[ ${#BACKUPS[@]} -eq 0 ] || { echo "The settings were backed up first, to:"; printf ' %s\n' "${BACKUPS[@]}"; } [ ${#BACKUPS[@]} -eq 0 ] || { echo "The settings were backed up first, to:"; printf ' %s\n' "${BACKUPS[@]}"; }
} }
# Whether the radio radio configure set up last is plugged in: its serial
# port is there, or for a sound card with none, the card is
set_up_radio_present() {
local state="$HAMPACK_STATE/radio" port card c
[ -f "$state" ] || return 1
port="$(sed -n 's/^port=//p' "$state")"
card="$(sed -n 's/^card=hw:CARD=//p' "$state")"
if [ -n "$port" ]; then
[ -e "$DEVDIR/${port#/dev/}" ]
return
fi
[ -n "$card" ] || return 1
for c in "$SYSFS"/class/sound/card*; do
[ "$(attr "$c" id)" = "$card" ] && return 0
done
return 1
}
# Show a desktop notification, if there's something to show it with
notify() {
command -v notify-send > /dev/null && notify-send --app-name=HamPack "$1" "$2" 2> /dev/null
return 0
}
# radio configure --auto, which the hampack-radio-plugged user service runs
# when a USB serial port appears (udev/70-hampack-radio.rules): set up the
# radio just plugged in, if radio recognises it by its USB serial number,
# and the radio set up already isn't plugged in. Radios it would have to ask
# what they are are left for you to set up: asking raises the port's DTR and
# RTS lines, which may key the transmitter, and nobody may be there.
# Graywolf is left alone while it runs, since stopping it needs sudo
auto_configure() {
local i known=() name="" card_sys out status tries=0 skipped
# The radio's sound card may come up after its serial port
udevadm settle --timeout=10 > /dev/null 2>&1
find_radios
for i in "${!RADIOS[@]}"; do
identify "${RADIOS[i]}" never
if [ -n "$ID_MODELS" ] && [ "$(wc -l <<< "$ID_MODELS")" -eq 1 ]; then
known+=("$i")
name="${ID_MODELS%|*}"
fi
done
if [ ${#known[@]} -eq 0 ]; then
echo "No radio that radio recognises by its USB serial number is plugged in: run \`radio configure\` to set one up."
return 0
elif [ ${#known[@]} -gt 1 ]; then
echo "${#known[@]} radios that radio recognises are plugged in: run \`radio configure N\` to set one up."
return 0
fi
if set_up_radio_present; then
echo "The radio set up already, the $(sed -n 's/^name=//p' "$HAMPACK_STATE/radio"), is plugged in, so it stays set up."
return 0
fi
# Wait for PipeWire to list its sound card, for the programs that use PipeWire's names
card_sys="$(card_of "${RADIOS[known[0]]}")"
while [ -n "$card_sys" ] && ! find_pipewire_nodes "${card_sys#card}" && (( tries++ < AUTO_WAIT )); do
sleep 1
done
AUTO=1
out="$(configure "$((known[0] + 1))" 2>&1)"
status=$?
printf '%s\n' "$out"
local details="\`journalctl --user -u hampack-radio-plugged\` says what changed."
if (( status != 0 )); then
notify "HamPack couldn't set up the $name" "Run \`radio configure\` to see why."
return "$status"
fi
skipped="$(sed -n 's/^ \([^ :][^:]*\): *skipped.*/\1/p' <<< "$out" | paste -sd, - | sed 's/,/, /g')"
if [ -n "$skipped" ]; then
notify "HamPack set up the $name" "Skipped: $skipped. Run \`radio configure\` to see why, and set them up. $details"
else
notify "HamPack set up the $name" "HamPack's programs reach it through rigctld. $details"
fi
}
case "${1:-detect}" in case "${1:-detect}" in
detect) shift; detect "$@" ;; detect) shift; detect "$@" ;;
probe) shift; probe "$@" ;; probe) shift; probe "$@" ;;
@@ -0,0 +1,10 @@
# Started by udev/70-hampack-radio.rules when a USB serial port appears.
# HamPack's update installs it, with HAMPACK_DIR filled in
[Unit]
Description=Set up a radio HamPack knows when it's plugged in (radio configure --auto)
# radio gives the programs the radio's sound card as PipeWire names it
After=pipewire.service pipewire-pulse.service wireplumber.service
[Service]
Type=oneshot
ExecStart=HAMPACK_DIR/radio configure --auto
+6 -3
View File
@@ -130,12 +130,15 @@ remove() {
[ -e "$HOME/.config/autostart/my-flrig.desktop" ] [ -e "$HOME/.config/autostart/my-flrig.desktop" ]
} }
@test "removes HamPack's udev rule" { @test "removes HamPack's udev rules, and the service that sets up a radio when it's plugged in" {
mkdir -p "$HAMPACK_UDEV_RULES_DIR" mkdir -p "$HAMPACK_UDEV_RULES_DIR" "$HOME/.config/systemd/user"
echo rule > "$HAMPACK_UDEV_RULES_DIR/70-hampack-cm108.rules" echo rule > "$HAMPACK_UDEV_RULES_DIR/70-hampack-cm108.rules"
echo rule > "$HAMPACK_UDEV_RULES_DIR/70-hampack-radio.rules"
echo unit > "$HOME/.config/systemd/user/hampack-radio-plugged.service"
remove remove
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
grep -qx "sudo rm -f $HAMPACK_UDEV_RULES_DIR/70-hampack-cm108.rules" "$STUB_LOG" grep -qx "sudo rm -f $HAMPACK_UDEV_RULES_DIR/70-hampack-cm108.rules $HAMPACK_UDEV_RULES_DIR/70-hampack-radio.rules" "$STUB_LOG"
[ ! -e "$HOME/.config/systemd/user/hampack-radio-plugged.service" ]
} }
@test "does nothing unless confirmed" { @test "does nothing unless confirmed" {
+91
View File
@@ -1495,3 +1495,94 @@ digirig() {
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
[[ "$output" == *"no CM108 PTT pin"* ]] [[ "$output" == *"no CM108 PTT pin"* ]]
} }
# --- setting up a radio when it's plugged in ---
# radio configure --auto, as the hampack-radio-plugged service runs it, with
# desktop notifications logged
auto() {
stub notify-send 'exit 0'
RADIO_AUTO_WAIT=0 run bash "$REPO/radio" configure --auto
}
@test "--auto sets up a radio it knows by its USB serial number, and says so" {
configurable
auto
[ "$status" -eq 0 ]
[[ "$output" == *"Setting up the Icom IC-7300 (Hamlib model 3073)"* ]]
grep -qx "hamlib=3073" "$HAMPACK_STATE/radio"
grep -qx "systemctl --user restart hampack-rigctld" "$STUB_LOG"
grep -q "^notify-send --app-name=HamPack HamPack set up the Icom IC-7300 " "$STUB_LOG"
}
@test "--auto leaves Graywolf alone while it runs, rather than ask for sudo, and says what it skipped" {
configurable
FAKE_RUNNING=fldigi auto
[ "$status" -eq 0 ]
[[ "$output" == *"Graywolf: skipped: it's running, and stopping it to change its settings needs sudo. Run \`radio configure\` to set it up"* ]]
! grep -q "^sudo" "$STUB_LOG"
grep -q "^notify-send .* Skipped: fldigi, Graywolf. Run \`radio configure\` to see why" "$STUB_LOG"
}
@test "--auto doesn't ask a radio what it is" {
configurable
rm -r "$RADIO_SYSFS/class/tty/ttyUSB0" "$RADIO_SYSFS/class/sound/card1"
yaesu 1-3
answers ttyUSB0 "38400 cat_id 0670"
: > "$STUB_LOG"
auto
[ "$status" -eq 0 ]
[[ "$output" == "No radio that radio recognises by its USB serial number is plugged in"* ]]
! grep -q "^python3" "$STUB_LOG"
! grep -q "^notify-send" "$STUB_LOG"
[ ! -e "$HAMPACK_STATE/radio" ]
}
@test "--auto leaves the radio set up already, while it's plugged in" {
configurable
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
: > "$STUB_LOG"
auto
[ "$status" -eq 0 ]
[ "$output" = "The radio set up already, the Icom IC-7300, is plugged in, so it stays set up." ]
! grep -q "reenable" "$STUB_LOG"
! grep -q "^notify-send" "$STUB_LOG"
# A sound card with no serial port, set up with no CAT, counts while it's there
printf 'name=radio on the AIOC\nport=\ncard=hw:CARD=CODEC\n' > "$HAMPACK_STATE/radio"
auto
[[ "$output" == *"stays set up"* ]]
}
@test "--auto sets up a radio in place of one that isn't plugged in" {
configurable
mkdir -p "$HAMPACK_STATE"
printf 'name=Yaesu FT-991A\nport=/dev/serial/by-id/usb-gone-if00-port0\ncard=hw:CARD=Gone\n' > "$HAMPACK_STATE/radio"
auto
[ "$status" -eq 0 ]
grep -qx "name=Icom IC-7300" "$HAMPACK_STATE/radio"
}
@test "--auto leaves it to you when two radios it knows are plugged in" {
configurable
usb 1-5 10c4:ea60 "Silicon Labs" "CP2102 USB to UART Bridge Controller" "IC-705 12345678"
port 1-5 ttyUSB2
auto
[ "$status" -eq 0 ]
[ "$output" = "2 radios that radio recognises are plugged in: run \`radio configure N\` to set one up." ]
[ ! -e "$HAMPACK_STATE/radio" ]
}
@test "--auto says when it couldn't set the radio up" {
configurable
rm "$FAKE_RADIOS/ttyUSB0"
auto
[ "$status" -eq 1 ]
grep -qx "notify-send --app-name=HamPack HamPack couldn't set up the Icom IC-7300 Run \`radio configure\` to see why." "$STUB_LOG"
}
@test "--auto takes no other options" {
run bash "$REPO/radio" configure --auto --force
[ "$status" -eq 2 ]
}
+19
View File
@@ -84,6 +84,25 @@ setup() {
grep -q "^sudo install -m 644 .*70-hampack-cm108.rules" "$STUB_LOG" grep -q "^sudo install -m 644 .*70-hampack-cm108.rules" "$STUB_LOG"
} }
@test "installs the udev rule and user service that set up a radio when it's plugged in" {
run bash "$REPO/update.sh"
[ "$status" -eq 0 ]
grep -qx "sudo install -m 644 $REPO/udev/70-hampack-radio.rules $HAMPACK_UDEV_RULES_DIR/70-hampack-radio.rules" "$STUB_LOG"
local unit="$HOME/.config/systemd/user/hampack-radio-plugged.service"
grep -qx "ExecStart=$REPO/radio configure --auto" "$unit"
grep -qx "systemctl --user daemon-reload" "$STUB_LOG"
# Only the CM108 rule needs applying to devices plugged in already
mkdir -p "$HAMPACK_UDEV_RULES_DIR"
cp "$REPO/udev/70-hampack-cm108.rules" "$HAMPACK_UDEV_RULES_DIR/"
: > "$STUB_LOG"
run bash "$REPO/update.sh"
grep -q "^sudo install -m 644 .*70-hampack-radio.rules" "$STUB_LOG"
grep -qx "udevadm control --reload-rules" "$STUB_LOG"
! grep -q "udevadm trigger" "$STUB_LOG"
! grep -q "daemon-reload" "$STUB_LOG"
}
@test "update leaves alone a radio command that isn't HamPack's" { @test "update leaves alone a radio command that isn't HamPack's" {
echo "theirs" > "$HOME/.local/bin/radio" echo "theirs" > "$HOME/.local/bin/radio"
run bash "$REPO/update.sh" run bash "$REPO/update.sh"
+8
View File
@@ -0,0 +1,8 @@
# Set up a radio when it's plugged in. Each USB serial port that appears
# starts the hampack-radio-plugged systemd user service (which HamPack's
# update installs), and it runs `radio configure --auto`. That sets up only a
# radio `radio` recognises by its USB serial number, and only if the radio
# set up already isn't plugged in. To turn it off:
# systemctl --user mask hampack-radio-plugged
ACTION=="add", SUBSYSTEM=="tty", KERNEL=="ttyUSB[0-9]*|ttyACM[0-9]*", TAG+="systemd", ENV{SYSTEMD_USER_WANTS}+="hampack-radio-plugged.service"
+30 -9
View File
@@ -90,18 +90,38 @@ join_serial_group() {
echo " Added you to the uucp group, so programs can control your radio. Log out and back in for it to take effect." echo " Added you to the uucp group, so programs can control your radio. Log out and back in for it to take effect."
} }
# Let you key a radio through a CM108-family sound card's PTT pin (Digirig, # Install the rules in udev/, each again when it changes:
# AIOC), which programs reach through its hidraw device. Reinstalled when # 70-hampack-cm108.rules lets you key a radio through a CM108-family sound
# udev/70-hampack-cm108.rules changes # card's PTT pin (Digirig, AIOC), which programs reach through its hidraw
# device; 70-hampack-radio.rules sets up a radio when it's plugged in
install_udev_rules() { install_udev_rules() {
local rules="${HAMPACK_UDEV_RULES_DIR:-/etc/udev/rules.d}/70-hampack-cm108.rules" local dir="${HAMPACK_UDEV_RULES_DIR:-/etc/udev/rules.d}" rules name changed=()
cmp -s "$SELF/udev/70-hampack-cm108.rules" "$rules" && return 0 for rules in "$SELF"/udev/*.rules; do
echo "Installing $rules..." name="${rules##*/}"
sudo install -m 644 "$SELF/udev/70-hampack-cm108.rules" "$rules" && cmp -s "$rules" "$dir/$name" && continue
sudo udevadm control --reload-rules && echo "Installing $dir/$name..."
sudo install -m 644 "$rules" "$dir/$name" || return 1
changed+=("$name")
done
[ ${#changed[@]} -gt 0 ] || return 0
sudo udevadm control --reload-rules || return 1
# Apply the CM108 rule to cards plugged in already
[[ " ${changed[*]} " != *" 70-hampack-cm108.rules "* ]] ||
sudo udevadm trigger --subsystem-match=hidraw --action=change sudo udevadm trigger --subsystem-match=hidraw --action=change
} }
# The user service udev/70-hampack-radio.rules starts when a USB serial port
# appears, to run `radio configure --auto`. Reinstalled when it changes
install_radio_service() {
local dir="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user" rendered
local unit="$dir/hampack-radio-plugged.service"
rendered="$(sed "s|HAMPACK_DIR|$SELF|g" "$SELF/systemd/user/hampack-radio-plugged.service")"
[ "$(cat "$unit" 2> /dev/null)" = "$rendered" ] && return 0
mkdir -p "$dir" && printf '%s\n' "$rendered" > "$unit" || return 1
systemctl --user daemon-reload 2> /dev/null
return 0
}
# Install the packages in packages.conf, and record the ones that weren't # Install the packages in packages.conf, and record the ones that weren't
# already installed, so hampackremove removes those and nothing the user had before # already installed, so hampackremove removes those and nothing the user had before
install_hampack_packages() { install_hampack_packages() {
@@ -175,7 +195,8 @@ fi
step "Removing stale HamPack files" remove_stale_files step "Removing stale HamPack files" remove_stale_files
step "Installing HamPack tools" install_tools step "Installing HamPack tools" install_tools
step "Adding you to the uucp group, for radios' serial ports" join_serial_group step "Adding you to the uucp group, for radios' serial ports" join_serial_group
step "Installing udev rules, for PTT through a CM108 sound card" install_udev_rules step "Installing udev rules, for PTT through a CM108 sound card and setting up radios when plugged in" install_udev_rules
step "Installing the service that sets up a radio when it's plugged in" install_radio_service
step "Installing HamPack packages" install_hampack_packages step "Installing HamPack packages" install_hampack_packages
step "Installing Flatpak applications" bash "$SELF/install-flatpaks.sh" step "Installing Flatpak applications" bash "$SELF/install-flatpaks.sh"
step "Installing pre-built binaries" bash "$SELF/install-binaries.sh" step "Installing pre-built binaries" bash "$SELF/install-binaries.sh"