Files
HamPack/update.sh
T
David YoungandClaude Opus 5.5 8d15d2c81e
check / lint-and-test (push) Successful in 3m57s
check / packages (push) Successful in 24s
Set up a radio radio knows when it's plugged in, with radio configure --auto
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>
2026-11-28 16:32:05 -07:00

215 lines
8.6 KiB
Bash

#!/bin/bash
#
# Purpose : Keep HamPack current (run by CoreDesktop's `update`, and by install.sh)
SELF="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
COREDESKTOP="$HOME/.local/share/coredesktop"
source "$COREDESKTOP/utils.sh"
# Config files and build steps refer to files in this repo through $HAMPACK_DIR
export HAMPACK_DIR="$SELF"
source "$SELF/lib.sh"
FAILED=()
# Run one update step; a failure is reported but doesn't stop the later steps
step() {
local name="$1"
shift
echo "→ $name..."
if ! "$@"; then
echo "✗ $name failed."
FAILED+=("$name")
fi
}
# Rename a package in HamPack's record of packages it installed
rename_recorded_package() {
local list="$HAMPACK_STATE/installed-packages"
grep -qxF "$1" "$list" 2> /dev/null || return 0
grep -vxF "$1" "$list" > "$list.tmp"
mv -f "$list.tmp" "$list" && record_installed installed-packages "$2"
}
remove_stale_files() {
# The HamPack GUI app (a Go program) was removed, along with its source and build hook
rm -f "$HOME/.local/bin/hampack"
rm -f "$HOME/.local/share/applications/hampack.desktop"
rm -f "$HOME"/.local/share/icons/hicolor/*/apps/computer.young.HamPack.png
rm -rf "$HOME/.local/share/HamPack/hampack-src"
rm -rf "$HOME/.local/share/HamPack/desktop/icons/hicolor"
rm -f "$COREDESKTOP"/updates.d/*hampack-build*
# Replaced by CoreDesktop's `update` and `sibling add`
rm -f "$HOME/.local/bin/hampackupdate" "$HOME/.local/bin/hampackrefresh"
# Paracon is now installed without the version in its file name
rm -f "$HOME"/.local/bin/paracon_*.pyz
# Hooks from before HamPack was a sibling; 71-siblings.sh now runs this script
rm -f "$COREDESKTOP"/updates.d/[0-9][0-9][0-9]-hampack-*
# Versions recorded under app names HamPack no longer uses
forget_version Kiwix-Desktop
forget_version Kiwix-Tools
# Packages recorded under names only provided by another package, which
# hampackremove can't match with what's installed. zim-tools provides
# zimwriterfs, and was recorded with it
rename_recorded_package libappindicator-gtk3 libappindicator
rename_recorded_package zimwriterfs zim-tools
# Build directories from before builds used a private temporary directory
rm -rf /tmp/hampack-build /tmp/windowsapps 2> /dev/null
# The passwordless sudoers file the old installer used, if a killed install left it behind
sudo rm -f /etc/sudoers.d/hampack
# Builds used to run `sudo make install` into ~/.local, leaving files there owned by root
local dirs=() dir
for dir in bin lib include share/applications share/doc share/icons share/man share/metainfo share/direwolf; do
[ -d "$HOME/.local/$dir" ] && dirs+=("$HOME/.local/$dir")
done
[ ${#dirs[@]} -eq 0 ] ||
find "${dirs[@]}" -xdev -user root -print0 2> /dev/null | xargs -0 -r sudo chown -h "$USER:"
return 0
}
install_tools() {
mkdir -p "$HOME/.local/bin"
install_script "$SELF/hampackremove" "$HOME/.local/bin/hampackremove"
# A link, so radio finds radios.conf beside it and updates with HamPack. A
# radio that isn't HamPack's is left alone
local radio="$HOME/.local/bin/radio"
if [ -e "$radio" ] && [ "$(readlink -f "$radio")" != "$(readlink -f "$SELF/radio")" ]; then
echo " Not installing HamPack's radio command: $radio is something else. Run $SELF/radio instead"
else
ln -sfn "$SELF/radio" "$radio"
fi
}
# Radios' CAT ports, like all serial ports on Arch, belong to the uucp group,
# so you need to be in it to control a radio. It's recorded, so hampackremove
# takes you out again only if HamPack put you in.
join_serial_group() {
id -nG "$USER" | tr ' ' '\n' | grep -qx uucp && return 0
sudo usermod -aG uucp "$USER" || return 1
record_installed added-groups uucp
echo " Added you to the uucp group, so programs can control your radio. Log out and back in for it to take effect."
}
# Install the rules in udev/, each again when it changes:
# 70-hampack-cm108.rules lets you key a radio through a CM108-family sound
# 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() {
local dir="${HAMPACK_UDEV_RULES_DIR:-/etc/udev/rules.d}" rules name changed=()
for rules in "$SELF"/udev/*.rules; do
name="${rules##*/}"
cmp -s "$rules" "$dir/$name" && continue
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
}
# 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
# already installed, so hampackremove removes those and nothing the user had before
install_hampack_packages() {
source "$SELF/packages.conf"
local pkg missing=() added=() status=0
for pkg in "${UTILITIES[@]}" "${APPLICATIONS[@]}"; do
is_installed "$pkg" || missing+=("$pkg")
done
install_packages "${UTILITIES[@]}" && install_packages "${APPLICATIONS[@]}" || status=1
for pkg in "${missing[@]}"; do
is_installed "$pkg" && added+=("$pkg")
done
record_installed installed-packages "${added[@]}"
return $status
}
install_not1mm() {
if uv tool list 2> /dev/null | grep -q '^not1mm '; then
uv tool upgrade not1mm
else
uv tool install not1mm
fi
}
# not1mm installs its own launcher only on first run, so install it up front
install_not1mm_desktop() {
local data
data=$(echo "$(uv tool dir)"/not1mm/lib/python3*/site-packages/not1mm/data)
[ -f "$data/k6gte-not1mm.desktop" ] || return 1
for size in 32 64 128; do
xdg-icon-resource install --size "$size" --context apps --mode user \
"$data/k6gte.not1mm-$size.png" k6gte-not1mm || return 1
done
xdg-desktop-menu install --mode user "$data/k6gte-not1mm.desktop"
}
# Install graywolf's systemd service once graywolf is built, and reinstall it
# when systemd/graywolf.service changes. To change how graywolf runs (e.g. to
# reach its web UI from other machines), use `sudo systemctl edit graywolf`:
# a drop-in survives updates, while edits to the unit file itself don't.
install_graywolf_service() {
[ -x "$HOME/.local/bin/graywolf" ] || return 0
local unit=/etc/systemd/system/graywolf.service rendered
rendered="$(sed "s|HAMPACK_USER|$USER|g; s|HAMPACK_HOME|$HOME|g" "$SELF/systemd/graywolf.service")"
mkdir -p "$HOME/.local/share/graywolf"
if [ "$(cat "$unit" 2> /dev/null)" != "$rendered" ]; then
echo "Installing $unit..."
printf '%s\n' "$rendered" | sudo tee "$unit" > /dev/null || return 1
sudo systemctl daemon-reload || return 1
sudo systemctl try-restart graywolf
fi
enable_services graywolf
}
# --- Main ---
echo "Updating HamPack..."
# Builds and package installs need sudo; ask now rather than partway through.
# Under CoreDesktop's `update`, sudo already has the password and doesn't ask.
if ! start_sudo_keepalive; then
echo "HamPack needs sudo to install packages and applications."
exit 1
fi
step "Removing stale HamPack files" remove_stale_files
step "Installing HamPack tools" install_tools
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 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 Flatpak applications" bash "$SELF/install-flatpaks.sh"
step "Installing pre-built binaries" bash "$SELF/install-binaries.sh"
step "Installing compiled applications" bash "$SELF/install-compiled.sh"
step "Installing graywolf service" install_graywolf_service
step "Installing Windows applications" bash "$SELF/install-windows-apps.sh"
step "Installing not1mm" install_not1mm
step "Installing not1mm desktop file" install_not1mm_desktop
if (( ${#FAILED[@]} > 0 )); then
echo "HamPack updated, with errors in: ${FAILED[*]}"
exit 1
fi
echo "✓ HamPack updated."