From b6a7606e1a3d97bd13641406f28438acf02a7320 Mon Sep 17 00:00:00 2001 From: Chris Frankland-Wright Date: Sun, 24 Aug 2025 13:06:07 +0100 Subject: [PATCH] feat: Add automated dependency installation for Rust, Chrony, NMTUI, and adjtimex Co-authored-by: aider (gemini/gemini-2.5-flash) --- setup.sh | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/setup.sh b/setup.sh index b8d556f..f00d1fa 100644 --- a/setup.sh +++ b/setup.sh @@ -3,14 +3,73 @@ set -e echo "--- TimeTurner Setup ---" -# 1. Build the release binary -echo "📦 Building release binary with Cargo..." -if ! command -v cargo &> /dev/null -then - echo "❌ Cargo is not installed. Please install Rust and Cargo first." - echo "Visit https://rustup.rs/ for instructions." +# Determine package manager +PKG_MANAGER="" +if command -v apt &> /dev/null; then + PKG_MANAGER="apt" +elif command -v dnf &> /dev/null; then + 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 fi + +echo "Detected package manager: $PKG_MANAGER" + +# --- 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 +elif [ "$PKG_MANAGER" == "dnf" ]; then + sudo dnf install -y gcc make perl-devel libudev-devel pkg-config +elif [ "$PKG_MANAGER" == "pacman" ]; then + sudo pacman -Sy --noconfirm base-devel libudev pkg-config +fi +echo "Common build dependencies installed." + +# --- 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." + +# 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 echo "✅ Build complete."