diff --git a/README.md b/README.md index 495c983..9102675 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,25 @@ The installation script automates the following steps: After installation is complete, the script will provide instructions to start the service manually or to run the application in its interactive terminal mode. +--- + +## 🔄 Updating + +If you installed TimeTurner by cloning the repository with `git`, you can use the `update.sh` script to easily update to the latest version. + +**Note**: This script will not work if you used the `curl` one-line command for installation, as that method does not create a Git repository. + +To run the update script, navigate to the `NTP-Timeturner-main` directory and run: +```bash +chmod +x update.sh && ./update.sh +``` + +The update script automates the following: +1. Pulls the latest code from the `main` branch on GitHub. +2. Rebuilds the application binary. +3. Copies the new binary to `/opt/timeturner/`. +4. Restarts the `timeturner` service to apply the changes. + --- ## 🕰️ Chrony NTP ```bash diff --git a/setup.sh b/setup.sh index 3dffd84..87f51c8 100644 --- a/setup.sh +++ b/setup.sh @@ -3,6 +3,43 @@ set -e echo "--- TimeTurner Setup ---" +# Check if TimeTurner is already installed. +INSTALL_DIR="/opt/timeturner" +if [ -f "${INSTALL_DIR}/timeturner" ]; then + echo "✅ TimeTurner is already installed." + # Ask the user what to do + read -p "Do you want to (U)pdate, (R)einstall, or (A)bort? [U/r/a] " choice + case "$choice" in + r|R ) + echo "Proceeding with full re-installation..." + # Stop the service to allow overwriting the binary, ignore errors if not running + echo "Stopping existing TimeTurner service..." + sudo systemctl stop timeturner.service || true + # The script will continue to the installation steps below. + ;; + a|A ) + echo "Aborting setup." + exit 0 + ;; + * ) # Default to Update + echo "Attempting to run the update script..." + # Ensure we are in a git repository and the update script exists + if [ -d ".git" ] && [ -f "update.sh" ]; then + chmod +x update.sh + ./update.sh + # Exit cleanly after the update + exit 0 + else + echo "⚠️ Could not find 'update.sh' or not in a git repository." + echo "Please re-clone the repository to get the update script, or remove the existing installation to run setup again:" + echo " sudo rm -rf ${INSTALL_DIR}" + exit 1 + fi + ;; + esac +fi + + # Determine package manager PKG_MANAGER="" if command -v apt &> /dev/null; then @@ -227,8 +264,9 @@ if [ "$PKG_MANAGER" == "apt" ]; then echo "✅ nodogsplash installed successfully." # Disable the standalone hostapd service to let NetworkManager manage it. - sudo systemctl disable hostapd - sudo systemctl mask hostapd + # We are now using the classic hostapd service, so unmask it. + sudo systemctl unmask hostapd + sudo systemctl enable hostapd sudo systemctl enable nodogsplash else echo "This script is designed for Debian-based systems like Raspberry Pi OS." @@ -240,40 +278,71 @@ fi sudo systemctl stop hostapd || true sudo systemctl stop dnsmasq || true -# Ensure NetworkManager is managing wlan0 by removing any conflicting configurations. -# This is the critical fix for the "No suitable device" error. -echo "Ensuring NetworkManager is managing wlan0..." -sudo rm -f /etc/NetworkManager/conf.d/99-unmanaged-wlan0.conf +# --- Configure networking for AP mode --- + +# Set the WiFi country code to prevent radio issues. This is a critical step. +echo "Setting WiFi Country Code to US..." +sudo raspi-config nonint do_wifi_country US + +# Tell NetworkManager to ignore wlan0 completely to prevent conflicts. +echo "Configuring NetworkManager to ignore wlan0..." +sudo tee /etc/NetworkManager/conf.d/99-unmanaged-wlan0.conf > /dev/null < /dev/null < /dev/null < /dev/null < /dev/null; then echo "Attempting to start nodogsplash service..." if ! sudo systemctl restart nodogsplash; then @@ -332,11 +426,11 @@ if [ "$IP_CHECK" == "10.0.252.1" ]; then fi else echo "❌ Error: wlan0 failed to get the static IP 10.0.252.1. Found: '$IP_CHECK'." - echo "Please check 'sudo nmcli c show \"$CON_NAME\"' and 'ip addr show wlan0'." + echo "Please check 'sudo systemctl status hostapd' and 'sudo systemctl status dhcpcd'." exit 1 fi -echo "✅ WiFi hotspot and captive portal configured. SSID: TimeTurner, IP: 10.0.252.1" +echo "✅ WiFi hotspot and captive portal configured. SSID: Fetch-Hachi, IP: 10.0.252.1" echo "Clients will be redirected to http://10.0.252.1/static/index.html" # 1. Build the release binary @@ -389,7 +483,7 @@ if [[ "$(uname)" == "Linux" ]]; then echo " sudo systemctl start timeturner.service" echo "" echo "To view live logs, run:" - echo " journalctl -u tim_turner.service -f" + echo " journalctl -u timeturner.service -f" echo "" fi echo "To run the interactive TUI instead, simply run from the project directory:" diff --git a/update.sh b/update.sh new file mode 100644 index 0000000..666471e --- /dev/null +++ b/update.sh @@ -0,0 +1,28 @@ +#!/bin/bash +set -e + +echo "--- TimeTurner Update Script ---" + +# 1. Fetch the latest changes from the git repository +echo "🔄 Pulling latest changes from GitHub..." +git pull origin main + +# 2. Rebuild the release binary +echo "📦 Building release binary with Cargo..." +cargo build --release + +# 3. Stop the currently running service to release the file lock +echo "🛑 Stopping TimeTurner service..." +sudo systemctl stop timeturner.service + +# 4. Copy the new binary to the installation directory +echo "🚀 Deploying new binary..." +sudo cp target/release/timeturner /opt/timeturner/timeturner + +# 5. Restart the service with the new binary +echo "✅ Restarting TimeTurner service..." +sudo systemctl restart timeturner.service + +echo "" +echo "Update complete. To check the status of the service, run:" +echo " systemctl status timeturner.service" \ No newline at end of file