#!/bin/bash # # Purpose : Keep HamPackServer current (run by MiniServer's `update`, and by install.sh) SELF="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" MINISERVER="$HOME/.local/share/MiniServer" source "$MINISERVER/utils.sh" # Scripts and the check tool find files in this repo through $HAMPACKSERVER_DIR export HAMPACKSERVER_DIR="$SELF" 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 } remove_stale_files() { # Replaced by MiniServer's `update` and `sibling add` rm -f "$HOME/.local/bin/hampackserverupdate" "$HOME/.local/bin/hampackserverrefresh" } install_tools() { mkdir -p "$HOME/.local/bin" install_script "$SELF/hampackservercheck" "$HOME/.local/bin/hampackservercheck" } install_hampackserver_packages() { source "$SELF/packages.conf" install_packages "${SERVERS[@]}" && install_packages "${UTILITIES[@]}" } # Install the hamclock system service, restarting hamclock if the service or # the binary changed install_hamclock_service() { local unit=/etc/systemd/system/hamclock.service local rendered changed=false # Remove old user-level service if present if [ -f "$HOME/.config/systemd/user/hamclock.service" ]; then systemctl --user disable --now hamclock 2>/dev/null || true rm "$HOME/.config/systemd/user/hamclock.service" systemctl --user daemon-reload fi mkdir -p "$HOME/.local/share/hamclock" rendered=$(sed -e "s/__HAMCLOCK_USER__/$USER/g" -e "s|__HAMCLOCK_HOME__|$HOME|g" \ "$SELF/servicefiles/hamclock.service") || return 1 if [ "$rendered" != "$(cat "$unit" 2>/dev/null)" ]; then echo "$rendered" | sudo tee "$unit" > /dev/null || return 1 sudo systemctl daemon-reload || return 1 changed=true fi enable_services hamclock || return 1 bash "$SELF/scripts/hamclock-cleanup.sh" || return 1 if [ "$changed" = true ] || [ "$(hamclock_mtime)" != "$HAMCLOCK_MTIME" ]; then echo "Restarting hamclock..." sudo systemctl restart hamclock fi } hamclock_mtime() { stat -c %Y "$HOME/.local/bin/hamclock" 2>/dev/null } # --- Main --- echo "Updating HamPackServer..." HAMCLOCK_MTIME=$(hamclock_mtime) step "Removing stale HamPackServer files" remove_stale_files step "Installing HamPackServer tools" install_tools step "Installing HamPackServer packages" install_hampackserver_packages step "Installing compiled servers" bash "$SELF/install-compiled.sh" step "Installing hamclock service" install_hamclock_service step "Installing openhamclock" bash "$SELF/install-openhamclock.sh" if (( ${#FAILED[@]} > 0 )); then echo "HamPackServer updated, with errors in: ${FAILED[*]}" exit 1 fi echo "✓ HamPackServer updated."