Files
HamPackServer/scripts/hamclock-cleanup.sh
T

41 lines
1.1 KiB
Bash
Executable File

#!/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"
)
# Nothing to do once the files have been migrated
migrate=false
for f in "${HAMCLOCK_DATA_FILES[@]}"; do
[ -f "$OLD_DIR/$f" ] && migrate=true
done
[ "$migrate" = true ] || exit 0
echo "Stopping hamclock service..."
sudo systemctl 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..."
sudo systemctl daemon-reload
sudo systemctl restart hamclock
echo "hamclock cleanup done."