#!/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." } # Let you key a radio through a CM108-family sound card's PTT pin (Digirig, # AIOC), which programs reach through its hidraw device. Reinstalled when # udev/70-hampack-cm108.rules changes install_udev_rules() { local rules="${HAMPACK_UDEV_RULES_DIR:-/etc/udev/rules.d}/70-hampack-cm108.rules" cmp -s "$SELF/udev/70-hampack-cm108.rules" "$rules" && return 0 echo "Installing $rules..." sudo install -m 644 "$SELF/udev/70-hampack-cm108.rules" "$rules" && sudo udevadm control --reload-rules && sudo udevadm trigger --subsystem-match=hidraw --action=change } # 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" getent group dialout > /dev/null || sudo groupadd dialout || return 1 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" install_udev_rules 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."