From 474e62d487d482d8cda3bc7b00a243cde4e6a320 Mon Sep 17 00:00:00 2001 From: Chris Frankland-Wright Date: Sat, 30 Aug 2025 23:02:48 +0100 Subject: [PATCH 1/9] created updater --- README.md | 19 +++++++++++++++++++ update.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 update.sh 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/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 From 0c51fd77fae68df5f5b795de804cb89ace35605c Mon Sep 17 00:00:00 2001 From: Chris Frankland-Wright Date: Sat, 30 Aug 2025 23:15:47 +0100 Subject: [PATCH 2/9] rename AP to Hachi --- setup.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/setup.sh b/setup.sh index 3dffd84..5a3e0ee 100644 --- a/setup.sh +++ b/setup.sh @@ -250,7 +250,7 @@ sudo systemctl reload NetworkManager echo "Configuring static IP for wlan0 using NetworkManager..." # Define the connection name -CON_NAME="TimeTurner-AP" +CON_NAME="Fetch-Hachi-AP" # If a connection with this name already exists, delete it to ensure a clean slate. if nmcli c show --active | grep -q "$CON_NAME"; then @@ -263,10 +263,8 @@ fi # Create a new connection profile for the Access Point with a static IP. echo "Creating new '$CON_NAME' connection profile..." -sudo nmcli c add type wifi ifname wlan0 con-name "$CON_NAME" autoconnect yes ssid "TimeTurner" +sudo nmcli c add type wifi ifname wlan0 con-name "$CON_NAME" autoconnect yes ssid "Fetch-Hachi" sudo nmcli c modify "$CON_NAME" 802-11-wireless.mode ap 802-11-wireless.band bg -sudo nmcli c modify "$CON_NAME" 802-11-wireless-security.key-mgmt wpa-psk -sudo nmcli c modify "$CON_NAME" 802-11-wireless-security.psk "harry-ron-hermione" sudo nmcli c modify "$CON_NAME" ipv4.method manual ipv4.addresses 10.0.252.1/24 # Configure dnsmasq for DHCP @@ -336,7 +334,7 @@ else 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 From fb4ecc5f2a98c34cc1ec8d0ae57d3f8f61b72911 Mon Sep 17 00:00:00 2001 From: Chris Frankland-Wright Date: Sat, 30 Aug 2025 23:25:06 +0100 Subject: [PATCH 3/9] bug fix for AP captive --- setup.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/setup.sh b/setup.sh index 5a3e0ee..adf9445 100644 --- a/setup.sh +++ b/setup.sh @@ -270,8 +270,17 @@ sudo nmcli c modify "$CON_NAME" ipv4.method manual ipv4.addresses 10.0.252.1/24 # Configure dnsmasq for DHCP echo "Configuring dnsmasq..." sudo tee /etc/dnsmasq.conf > /dev/null < Date: Sat, 30 Aug 2025 23:39:05 +0100 Subject: [PATCH 4/9] update installer with reinstall options --- setup.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/setup.sh b/setup.sh index adf9445..84b72d6 100644 --- a/setup.sh +++ b/setup.sh @@ -3,6 +3,40 @@ 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..." + # 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 @@ -244,6 +278,15 @@ sudo systemctl stop dnsmasq || true # 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 + +# Prevent NetworkManager from running its own dnsmasq instance or managing resolv.conf. +# This allows our standalone dnsmasq service to function without conflict. +echo "Configuring NetworkManager to not manage DNS..." +sudo tee /etc/NetworkManager/conf.d/99-disable-dns.conf > /dev/null < Date: Sat, 30 Aug 2025 23:48:24 +0100 Subject: [PATCH 5/9] DHCP issues --- setup.sh | 76 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/setup.sh b/setup.sh index 84b72d6..ca62644 100644 --- a/setup.sh +++ b/setup.sh @@ -261,8 +261,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." @@ -274,41 +275,46 @@ 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 --- -# Prevent NetworkManager from running its own dnsmasq instance or managing resolv.conf. -# This allows our standalone dnsmasq service to function without conflict. -echo "Configuring NetworkManager to not manage DNS..." -sudo tee /etc/NetworkManager/conf.d/99-disable-dns.conf > /dev/null < /dev/null < /dev/null < /dev/null < Date: Sat, 30 Aug 2025 23:54:12 +0100 Subject: [PATCH 6/9] final attempt for the night --- setup.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index ca62644..efa9262 100644 --- a/setup.sh +++ b/setup.sh @@ -291,7 +291,12 @@ sudo systemctl reload NetworkManager echo "Configuring static IP for wlan0 via dhcpcd..." # Ensure dhcpcd is installed sudo apt install -y dhcpcd5 -# Add our static IP config, being careful not to overwrite existing settings + +# First, remove any existing configurations for wlan0 to prevent conflicts. +# This is a more robust way to ensure our settings are applied. +sudo sed -i '/^interface wlan0/,/^\s*$/d' /etc/dhcpcd.conf + +# Now, add our static IP config to the end of the file. sudo tee -a /etc/dhcpcd.conf > /dev/null < Date: Sat, 30 Aug 2025 23:59:34 +0100 Subject: [PATCH 7/9] force dns and dhcp --- setup.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index efa9262..c0cd2ae 100644 --- a/setup.sh +++ b/setup.sh @@ -355,6 +355,12 @@ EOF # Restart services in the correct order and add delays to prevent race conditions echo "Restarting services..." + +# Stop and disable systemd-resolved to prevent any DNS/DHCP conflicts +echo "Disabling systemd-resolved to ensure dnsmasq has full control..." +sudo systemctl stop systemd-resolved || true +sudo systemctl disable systemd-resolved || true + # Restart dhcpcd to apply the static IP sudo systemctl restart dhcpcd # Restart hostapd to create the access point @@ -377,7 +383,19 @@ done # Check for the IP address before starting nodogsplash if [ "$IP_CHECK" == "10.0.252.1" ]; then echo "✅ wlan0 configured with IP $IP_CHECK." - sudo systemctl restart dnsmasq + + # Add a small delay to ensure the interface is fully ready for dnsmasq + sleep 2 + + echo "Attempting to start dnsmasq service..." + if ! sudo systemctl restart dnsmasq; then + echo "❌ dnsmasq service failed to start. Displaying logs..." + sleep 2 + sudo journalctl -u dnsmasq.service --no-pager -n 50 + exit 1 + fi + echo "✅ dnsmasq service started successfully." + if command -v nodogsplash &> /dev/null; then echo "Attempting to start nodogsplash service..." if ! sudo systemctl restart nodogsplash; then From 459e44250ed67819213579eb2acd5ca139a899bc Mon Sep 17 00:00:00 2001 From: Chris Frankland-Wright Date: Sun, 31 Aug 2025 00:06:32 +0100 Subject: [PATCH 8/9] ugh another try... --- setup.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index c0cd2ae..288346c 100644 --- a/setup.sh +++ b/setup.sh @@ -346,9 +346,14 @@ GatewayAddress 10.0.252.1 MaxClients 250 AuthIdleTimeout 480 FirewallRuleSet preauthenticated-users { - FirewallRule allow tcp port 80 + # Allow DHCP for clients to get an IP address + FirewallRule allow udp port 67 + FirewallRule allow udp port 68 + # Allow DNS for captive portal detection FirewallRule allow tcp port 53 FirewallRule allow udp port 53 + # Allow HTTP for the captive portal redirect + FirewallRule allow tcp port 80 } RedirectURL http://10.0.252.1/static/index.html EOF From 04165f26867dd633505938843bf3198c87e33b94 Mon Sep 17 00:00:00 2001 From: Chris Frankland-Wright Date: Sun, 31 Aug 2025 00:19:24 +0100 Subject: [PATCH 9/9] last chance saloon! --- setup.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/setup.sh b/setup.sh index 288346c..87f51c8 100644 --- a/setup.sh +++ b/setup.sh @@ -12,6 +12,9 @@ if [ -f "${INSTALL_DIR}/timeturner" ]; then 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 ) @@ -277,6 +280,10 @@ sudo systemctl stop dnsmasq || true # --- 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 <