diff --git a/install.sh b/install.sh index ad54e77..5036408 100755 --- a/install.sh +++ b/install.sh @@ -71,9 +71,10 @@ cp "$HOME/.local/share/HamPackServer/scripts/start-hamclock.sh" "$HOME/.local/bi chmod +x "$HOME/.local/bin/start-hamclock.sh" mkdir -p "$HOME/.config/systemd/user" +mkdir -p "$HOME/.local/share/hamclock" cp "$HOME/.local/share/HamPackServer/servicefiles/hamclock.service" "$HOME/.config/systemd/user/" -systemctl --user daemon-reload -systemctl --user enable --now hamclock +systemctl --user enable hamclock +bash "$HOME/.local/share/HamPackServer/scripts/hamclock-cleanup.sh" cd ~/.local/share/HamPackServer diff --git a/scripts/hamclock-cleanup.sh b/scripts/hamclock-cleanup.sh new file mode 100755 index 0000000..7f60d31 --- /dev/null +++ b/scripts/hamclock-cleanup.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# +# Purpose : Migrate hamclock to updated working directory and restart the service. +# ESPHamClock web server stores config in its working directory; this +# moves those files from the old location (~/.local/bin/) to the new +# dedicated data dir (~/.local/share/hamclock/). + +OLD_DIR="$HOME/.local/bin" +NEW_DIR="$HOME/.local/share/hamclock" + +# ESPHamClock data files written to the working directory +HAMCLOCK_DATA_FILES=( + "hamclock.txt" + ".hamclock" +) + +echo "Stopping hamclock service..." +systemctl --user stop hamclock 2>/dev/null || true + +mkdir -p "$NEW_DIR" + +for f in "${HAMCLOCK_DATA_FILES[@]}"; do + if [ -f "$OLD_DIR/$f" ]; then + echo "Migrating $f to $NEW_DIR/" + mv "$OLD_DIR/$f" "$NEW_DIR/$f" + fi +done + +echo "Reloading hamclock service..." +systemctl --user daemon-reload +systemctl --user restart hamclock + +echo "hamclock cleanup done." diff --git a/scripts/start-hamclock.sh b/scripts/start-hamclock.sh deleted file mode 100755 index f48c561..0000000 --- a/scripts/start-hamclock.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -# Start HamClock - -HAMCLOCK="$HOME/.local/bin/hamclock" - -if [ ! -x "$HAMCLOCK" ]; then - echo "Error: hamclock not found or not executable at $HAMCLOCK" >&2 - exit 1 -fi - -"$HAMCLOCK" "$@" & diff --git a/servicefiles/hamclock.service b/servicefiles/hamclock.service index f7daeba..73a7aa7 100644 --- a/servicefiles/hamclock.service +++ b/servicefiles/hamclock.service @@ -4,7 +4,8 @@ After=network.target [Service] Type=simple -WorkingDirectory=%h/.local/bin/ +Environment=HOME=%h +WorkingDirectory=%h/.local/share/hamclock ExecStart=%h/.local/bin/hamclock Restart=on-failure RestartSec=5