make in to sibling project
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : Keep HamPackServer 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"
|
||||
|
||||
# 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 CoreDesktop'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_pm2() {
|
||||
command -v pm2 &> /dev/null || npm install pm2 -g --prefix "$HOME/.local"
|
||||
}
|
||||
|
||||
enable_cockpit() {
|
||||
if ! systemctl is-enabled cockpit.socket &> /dev/null; then
|
||||
sudo systemctl enable --now cockpit.socket &&
|
||||
echo "Cockpit enabled. Access it at http://localhost:9090"
|
||||
fi
|
||||
}
|
||||
|
||||
# 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 pm2" install_pm2
|
||||
step "Enabling Cockpit" enable_cockpit
|
||||
step "Configuring networking" bash "$SELF/fix-networking.sh"
|
||||
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."
|
||||
Reference in New Issue
Block a user