mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
Compare commits
4 commits
9c57c32c68
...
e2d48391ea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2d48391ea | ||
|
|
8362435e12 | ||
|
|
cd9ac5a141 | ||
|
|
b6a7606e1a |
1 changed files with 188 additions and 6 deletions
194
setup.sh
194
setup.sh
|
|
@ -3,14 +3,196 @@ set -e
|
||||||
|
|
||||||
echo "--- TimeTurner Setup ---"
|
echo "--- TimeTurner Setup ---"
|
||||||
|
|
||||||
# 1. Build the release binary
|
# Determine package manager
|
||||||
echo "📦 Building release binary with Cargo..."
|
PKG_MANAGER=""
|
||||||
if ! command -v cargo &> /dev/null
|
if command -v apt &> /dev/null; then
|
||||||
then
|
PKG_MANAGER="apt"
|
||||||
echo "❌ Cargo is not installed. Please install Rust and Cargo first."
|
elif command -v dnf &> /dev/null; then
|
||||||
echo "Visit https://rustup.rs/ for instructions."
|
PKG_MANAGER="dnf"
|
||||||
|
elif command -v pacman &> /dev/null; then
|
||||||
|
PKG_MANAGER="pacman"
|
||||||
|
else
|
||||||
|
echo "Error: No supported package manager (apt, dnf, pacman) found. Please install dependencies manually."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Detected package manager: $PKG_MANAGER"
|
||||||
|
|
||||||
|
# --- Update System Packages ---
|
||||||
|
echo "Updating system packages..."
|
||||||
|
if [ "$PKG_MANAGER" == "apt" ]; then
|
||||||
|
sudo apt update && sudo apt upgrade -y
|
||||||
|
elif [ "$PKG_MANAGER" == "dnf" ]; then
|
||||||
|
sudo dnf upgrade -y
|
||||||
|
elif [ "$PKG_MANAGER" == "pacman" ]; then
|
||||||
|
sudo pacman -Syu --noconfirm
|
||||||
|
fi
|
||||||
|
echo "System packages updated."
|
||||||
|
|
||||||
|
# --- Install Rust/Cargo if not installed ---
|
||||||
|
if ! command -v cargo &> /dev/null; then
|
||||||
|
echo "Rust/Cargo not found. Installing Rustup..."
|
||||||
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||||
|
# Source cargo's env for the current shell session
|
||||||
|
# This is for the current script's execution path, typically rustup adds to .bashrc/.profile for future sessions.
|
||||||
|
# We need it now, but for non-interactive script, sourcing won't affect parent shell.
|
||||||
|
# However, cargo build below will rely on it being in PATH. rustup makes sure of this if it installs.
|
||||||
|
# For safety, ensure PATH is updated.
|
||||||
|
export PATH="$HOME/.cargo/bin:$PATH"
|
||||||
|
echo "Rust/Cargo installed successfully."
|
||||||
|
else
|
||||||
|
echo "Rust/Cargo is already installed."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Install common build dependencies for Rust ---
|
||||||
|
echo "Installing common build dependencies..."
|
||||||
|
if [ "$PKG_MANAGER" == "apt" ]; then
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y build-essential libudev-dev pkg-config curl
|
||||||
|
elif [ "$PKG_MANAGER" == "dnf" ]; then
|
||||||
|
sudo dnf install -y gcc make perl-devel libudev-devel pkg-config curl
|
||||||
|
elif [ "$PKG_MANAGER" == "pacman" ]; then
|
||||||
|
sudo pacman -Sy --noconfirm base-devel libudev pkg-config curl
|
||||||
|
fi
|
||||||
|
echo "Common build dependencies installed."
|
||||||
|
|
||||||
|
# --- Apply custom splash screen ---
|
||||||
|
if [[ "$(uname)" == "Linux" ]]; then
|
||||||
|
echo "🖼️ Applying custom splash screen..."
|
||||||
|
SPLASH_URL="https://raw.githubusercontent.com/cjfranko/NTP-Timeturner/refs/heads/main/splash.png"
|
||||||
|
PLYMOUTH_THEME_DIR="/usr/share/plymouth/themes/pix"
|
||||||
|
PLYMOUTH_IMAGE_PATH="${PLYMOUTH_THEME_DIR}/splash.png"
|
||||||
|
|
||||||
|
sudo mkdir -p "${PLYMOUTH_THEME_DIR}"
|
||||||
|
echo "Downloading splash image from ${SPLASH_URL}..."
|
||||||
|
sudo curl -L "${SPLASH_URL}" -o "${PLYMOUTH_IMAGE_PATH}"
|
||||||
|
|
||||||
|
if [ -f "${PLYMOUTH_IMAGE_PATH}" ]; then
|
||||||
|
echo "Splash image downloaded. Updating Plymouth configuration..."
|
||||||
|
# Set 'pix' as the default plymouth theme if not already.
|
||||||
|
# This is a common theme that expects splash.png.
|
||||||
|
sudo update-alternatives --install /usr/share/plymouth/themes/default.plymouth default.plymouth "${PLYMOUTH_THEME_DIR}/pix.plymouth" 100 || true
|
||||||
|
# Ensure the pix theme exists and is linked
|
||||||
|
if [ ! -f "${PLYMOUTH_THEME_DIR}/pix.plymouth" ]; then
|
||||||
|
echo "Creating dummy pix.plymouth for update-initramfs"
|
||||||
|
echo "[Plymouth Theme]" | sudo tee "${PLYMOUTH_THEME_DIR}/pix.plymouth" > /dev/null
|
||||||
|
echo "Name=Pi Splash" | sudo tee -a "${PLYMOUTH_THEME_DIR}/pix.plymouth" > /dev/null
|
||||||
|
echo "Description=TimeTurner Raspberry Pi Splash Screen" | sudo tee -a "${PLYMOUTH_THEME_DIR}/pix.plymouth" > /dev/null
|
||||||
|
echo "SpriteAnimation=/splash.png" | sudo tee -a "${PLYMOUTH_THEME_DIR}/pix.plymouth" > /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update the initial RAM filesystem to include the new splash screen
|
||||||
|
sudo update-initramfs -u
|
||||||
|
echo "✅ Custom splash screen applied. Reboot may be required to see changes."
|
||||||
|
else
|
||||||
|
echo "❌ Failed to download splash image from ${SPLASH_URL}."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "⚠️ Skipping splash screen configuration on non-Linux OS."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Remove NTPD and install Chrony, NMTUI, Adjtimex ---
|
||||||
|
echo "Removing NTPD (if installed) and installing Chrony, NMTUI, Adjtimex..."
|
||||||
|
|
||||||
|
# --- Remove NTPD and install Chrony, NMTUI, Adjtimex ---
|
||||||
|
echo "Removing NTPD (if installed) and installing Chrony, NMTUI, Adjtimex..."
|
||||||
|
|
||||||
|
if [ "$PKG_MANAGER" == "apt" ]; then
|
||||||
|
sudo apt update
|
||||||
|
sudo apt remove -y ntp || true # Remove ntp if it exists, ignore if not
|
||||||
|
sudo apt install -y chrony nmtui adjtimex
|
||||||
|
sudo systemctl enable chrony --now
|
||||||
|
elif [ "$PKG_MANAGER" == "dnf" ]; then
|
||||||
|
sudo dnf remove -y ntp || true
|
||||||
|
sudo dnf install -y chrony NetworkManager-tui adjtimex
|
||||||
|
sudo systemctl enable chronyd --now
|
||||||
|
elif [ "$PKG_MANAGER" == "pacman" ]; then
|
||||||
|
sudo pacman -Sy --noconfirm ntp || true
|
||||||
|
sudo pacman -R --noconfirm ntp || true # Ensure ntp is removed
|
||||||
|
sudo pacman -Sy --noconfirm chrony networkmanager adjtimex
|
||||||
|
sudo systemctl enable chronyd --now
|
||||||
|
sudo systemctl enable NetworkManager --now # nmtui relies on NetworkManager
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "NTPD removed (if present). Chrony, NMTUI, and Adjtimex installed and configured."
|
||||||
|
|
||||||
|
# --- Install and configure WiFi hotspot and captive portal ---
|
||||||
|
echo "📡 Installing and configuring WiFi hotspot and captive portal..."
|
||||||
|
|
||||||
|
if [ "$PKG_MANAGER" == "apt" ]; then
|
||||||
|
sudo apt install -y hostapd dnsmasq nodogsplash
|
||||||
|
sudo systemctl unmask hostapd
|
||||||
|
sudo systemctl enable hostapd
|
||||||
|
sudo systemctl enable nodogsplash
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Stop services to configure
|
||||||
|
sudo systemctl stop hostapd
|
||||||
|
sudo systemctl stop dnsmasq
|
||||||
|
sudo systemctl stop nodogsplash
|
||||||
|
|
||||||
|
# Configure static IP for wlan0
|
||||||
|
echo "Configuring static IP for wlan0..."
|
||||||
|
sudo sed -i '/^interface wlan0/d' /etc/dhcpcd.conf
|
||||||
|
sudo tee -a /etc/dhcpcd.conf > /dev/null <<EOF
|
||||||
|
interface wlan0
|
||||||
|
static ip_address=10.0.252.1/24
|
||||||
|
nohook wpa_supplicant
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Configure dnsmasq for DHCP
|
||||||
|
echo "Configuring dnsmasq..."
|
||||||
|
sudo tee /etc/dnsmasq.conf > /dev/null <<EOF
|
||||||
|
interface=wlan0
|
||||||
|
dhcp-range=10.0.252.10,10.0.252.50,255.255.255.0,24h
|
||||||
|
address=/#/10.0.252.1
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Configure hostapd
|
||||||
|
echo "Configuring hostapd..."
|
||||||
|
sudo tee /etc/hostapd/hostapd.conf > /dev/null <<EOF
|
||||||
|
interface=wlan0
|
||||||
|
driver=nl80211
|
||||||
|
ssid=TimeTurner
|
||||||
|
hw_mode=g
|
||||||
|
channel=7
|
||||||
|
wmm_enabled=0
|
||||||
|
macaddr_acl=0
|
||||||
|
auth_algs=1
|
||||||
|
ignore_broadcast_ssid=0
|
||||||
|
wpa=2
|
||||||
|
wpa_passphrase=harry-ron-hermione
|
||||||
|
wpa_key_mgmt=WPA-PSK
|
||||||
|
rsn_pairwise=CCMP
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sudo sed -i 's|#DAEMON_CONF=""|DAEMON_CONF="/etc/hostapd/hostapd.conf"|' /etc/default/hostapd
|
||||||
|
|
||||||
|
# Configure nodogsplash for captive portal
|
||||||
|
echo "Configuring nodogsplash..."
|
||||||
|
sudo tee /etc/nodogsplash/nodogsplash.conf > /dev/null <<EOF
|
||||||
|
GatewayInterface wlan0
|
||||||
|
GatewayAddress 10.0.252.1
|
||||||
|
MaxClients 50
|
||||||
|
ClientIdleTimeout 3600
|
||||||
|
FirewallRuleSet preauthenticated-users {
|
||||||
|
FirewallRule allow tcp port 80
|
||||||
|
}
|
||||||
|
RedirectURL http://10.0.252.1/static/index.html
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Restart services
|
||||||
|
sudo systemctl restart dhcpcd
|
||||||
|
sudo systemctl restart dnsmasq
|
||||||
|
sudo systemctl restart hostapd
|
||||||
|
sudo systemctl restart nodogsplash
|
||||||
|
|
||||||
|
echo "✅ WiFi hotspot and captive portal configured. SSID: TimeTurner, IP: 10.0.252.1"
|
||||||
|
echo "Clients will be redirected to http://10.0.252.1/static/index.html"
|
||||||
|
|
||||||
|
# 1. Build the release binary
|
||||||
|
echo "📦 Building release binary with Cargo..."
|
||||||
|
# No need to check for cargo again, as it's handled above
|
||||||
cargo build --release
|
cargo build --release
|
||||||
echo "✅ Build complete."
|
echo "✅ Build complete."
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue