mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 10:22:02 +00:00
feat: Add automated dependency installation for Rust, Chrony, NMTUI, and adjtimex
Co-authored-by: aider (gemini/gemini-2.5-flash) <aider@aider.chat>
This commit is contained in:
parent
9c57c32c68
commit
b6a7606e1a
1 changed files with 65 additions and 6 deletions
71
setup.sh
71
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."
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue