Rustelo/scripts/install.sh

273 lines
7.7 KiB
Bash
Raw Normal View History

2026-02-08 20:18:46 +00:00
#!/usr/bin/env bash
set -euo pipefail
2025-07-07 23:53:50 +01:00
2026-02-08 20:18:46 +00:00
# Rustelo Prerequisites Installer (Bootstrap)
# This script installs the minimal requirements to run the Nushell installer
2025-07-07 23:53:50 +01:00
2026-02-08 20:18:46 +00:00
echo "🚀 Rustelo Prerequisites Bootstrap Installer"
echo ""
2025-07-07 23:53:50 +01:00
2026-02-08 20:18:46 +00:00
# Detect OS and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
2025-07-07 23:53:50 +01:00
2026-02-08 20:18:46 +00:00
case "$OS" in
darwin) OS="macos" ;;
linux) OS="linux" ;;
msys*|mingw*|cygwin*) OS="windows" ;;
esac
2025-07-07 23:53:50 +01:00
2026-02-08 20:18:46 +00:00
case "$ARCH" in
x86_64|amd64) ARCH="x86_64" ;;
arm64|aarch64) ARCH="aarch64" ;;
armv7*) ARCH="armv7" ;;
esac
2025-07-07 23:53:50 +01:00
2026-02-08 20:18:46 +00:00
echo "Detected: $OS on $ARCH"
echo ""
2025-07-07 23:53:50 +01:00
2026-02-08 20:18:46 +00:00
# Function to check if command exists
2025-07-07 23:53:50 +01:00
command_exists() {
command -v "$1" >/dev/null 2>&1
}
2026-02-08 20:18:46 +00:00
# Install Rust if not present
2025-07-07 23:53:50 +01:00
install_rust() {
2026-02-08 20:18:46 +00:00
if command_exists rustc && command_exists cargo; then
echo "✅ Rust already installed: $(rustc --version)"
2025-07-07 23:53:50 +01:00
else
2026-02-08 20:18:46 +00:00
echo "📦 Installing Rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
echo "✅ Rust installed successfully"
2025-07-07 23:53:50 +01:00
fi
}
2026-02-08 20:18:46 +00:00
# Install Node.js and pnpm
install_node() {
if command_exists node && command_exists pnpm; then
echo "✅ Node.js and pnpm already installed"
echo " Node.js: $(node --version)"
echo " pnpm: $(pnpm --version)"
return
fi
echo "📦 Installing Node.js and pnpm..."
case "$OS" in
macos)
if command_exists brew; then
2025-07-07 23:53:50 +01:00
brew install node
2026-02-08 20:18:46 +00:00
npm install -g pnpm
2025-07-07 23:53:50 +01:00
else
2026-02-08 20:18:46 +00:00
echo "⚠️ Homebrew not found. Please install Node.js manually:"
echo " Visit: https://nodejs.org/"
echo " Then run: npm install -g pnpm"
return 1
2025-07-07 23:53:50 +01:00
fi
;;
2026-02-08 20:18:46 +00:00
linux)
if command_exists apt; then
sudo apt update
sudo apt install -y nodejs npm
sudo npm install -g pnpm
elif command_exists dnf; then
sudo dnf install -y nodejs npm
sudo npm install -g pnpm
elif command_exists pacman; then
sudo pacman -S nodejs npm
sudo npm install -g pnpm
else
echo "⚠️ Package manager not found. Please install Node.js manually:"
echo " Visit: https://nodejs.org/"
echo " Then run: npm install -g pnpm"
return 1
fi
2025-07-07 23:53:50 +01:00
;;
2026-02-08 20:18:46 +00:00
windows)
echo "⚠️ Please install Node.js manually on Windows:"
echo " Visit: https://nodejs.org/"
echo " Then run: npm install -g pnpm"
return 1
2025-07-07 23:53:50 +01:00
;;
esac
2026-02-08 20:18:46 +00:00
echo "✅ Node.js and pnpm installed successfully"
2025-07-07 23:53:50 +01:00
}
2026-02-08 20:18:46 +00:00
# Install Nushell
install_nushell() {
if command_exists nu; then
echo "✅ Nushell already installed: $(nu --version | head -n1)"
return
fi
echo "📦 Installing Nushell..."
case "$OS" in
macos)
if command_exists brew; then
brew install nushell
elif command_exists cargo; then
cargo install nu --features=extra
2025-07-07 23:53:50 +01:00
else
2026-02-08 20:18:46 +00:00
install_nushell_binary
2025-07-07 23:53:50 +01:00
fi
2026-02-08 20:18:46 +00:00
;;
linux)
if command_exists cargo; then
cargo install nu --features=extra
else
install_nushell_binary
fi
;;
windows)
echo "⚠️ Please install Nushell manually on Windows:"
echo " Visit: https://github.com/nushell/nushell/releases"
echo " Or run: cargo install nu --features=extra"
return 1
;;
esac
echo "✅ Nushell installed successfully"
2025-07-07 23:53:50 +01:00
}
2026-02-08 20:18:46 +00:00
# Install Nushell from binary release
install_nushell_binary() {
echo " 🔽 Installing Nushell from GitHub releases..."
local version="0.88.1"
local os_suffix
local filename
case "$OS-$ARCH" in
macos-x86_64) os_suffix="apple-darwin" ;;
macos-aarch64) os_suffix="apple-darwin" ;;
linux-x86_64) os_suffix="unknown-linux-gnu" ;;
linux-aarch64) os_suffix="unknown-linux-gnu" ;;
*)
echo "❌ Unsupported platform: $OS-$ARCH"
echo " Please install manually: cargo install nu --features=extra"
return 1
;;
esac
filename="nu-${version}-${ARCH}-${os_suffix}.tar.gz"
url="https://github.com/nushell/nushell/releases/download/${version}/${filename}"
echo " 📥 Downloading: $filename"
if ! curl -fsSL "$url" | tar -xz; then
echo "❌ Failed to download Nushell binary"
echo " Please install via cargo: cargo install nu --features=extra"
return 1
2025-07-07 23:53:50 +01:00
fi
2026-02-08 20:18:46 +00:00
sudo mv nu /usr/local/bin/
echo " ✅ Nushell binary installed to /usr/local/bin/nu"
2025-07-07 23:53:50 +01:00
}
2026-02-08 20:18:46 +00:00
# Install Just command runner
install_just() {
if command_exists just; then
echo "✅ Just already installed: $(just --version)"
return
2025-07-07 23:53:50 +01:00
fi
2026-02-08 20:18:46 +00:00
echo "📦 Installing Just command runner..."
if command_exists cargo; then
cargo install just
echo "✅ Just installed via cargo"
2025-07-07 23:53:50 +01:00
else
2026-02-08 20:18:46 +00:00
install_just_binary
2025-07-07 23:53:50 +01:00
fi
}
2026-02-08 20:18:46 +00:00
# Install Just from binary release
install_just_binary() {
echo " 🔽 Installing Just from GitHub releases..."
local version="1.16.0"
local os_suffix
case "$OS" in
macos) os_suffix="apple-darwin" ;;
linux) os_suffix="unknown-linux-musl" ;;
*)
echo "❌ Unsupported OS for binary install: $OS"
echo " Please install via cargo: cargo install just"
return 1
;;
esac
local filename="just-${version}-${ARCH}-${os_suffix}.tar.gz"
local url="https://github.com/casey/just/releases/download/${version}/${filename}"
echo " 📥 Downloading: $filename"
if curl -fsSL "$url" | tar -xz && sudo mv just /usr/local/bin/; then
echo " ✅ Just binary installed to /usr/local/bin/just"
2025-07-07 23:53:50 +01:00
else
2026-02-08 20:18:46 +00:00
echo "❌ Failed to download Just binary"
echo " Please install via cargo: cargo install just"
return 1
2025-07-07 23:53:50 +01:00
fi
}
2026-02-08 20:18:46 +00:00
# Update PATH
update_path() {
echo ""
echo "🔧 Updating PATH..."
local cargo_bin="$HOME/.cargo/bin"
local local_bin="/usr/local/bin"
# Add to current session
export PATH="$PATH:$cargo_bin:$local_bin"
# Determine shell config file
local shell_config
case "$SHELL" in
*/zsh) shell_config="$HOME/.zshrc" ;;
*/bash) shell_config="$HOME/.bashrc" ;;
*/fish) shell_config="$HOME/.config/fish/config.fish" ;;
*) shell_config="$HOME/.bashrc" ;;
esac
# Add to shell config if not already present
local path_export="export PATH=\"\$PATH:$cargo_bin:$local_bin\""
if ! grep -q "$cargo_bin" "$shell_config" 2>/dev/null; then
echo "$path_export" >> "$shell_config"
echo "✅ Added Cargo and local bin to PATH in $shell_config"
2025-07-07 23:53:50 +01:00
fi
}
2026-02-08 20:18:46 +00:00
# Main installation
main() {
echo "Starting prerequisite installation..."
2025-07-07 23:53:50 +01:00
echo ""
2026-02-08 20:18:46 +00:00
# Install in order
install_rust
install_node
install_nushell
install_just
# Update PATH
update_path
2025-07-07 23:53:50 +01:00
echo ""
2026-02-08 20:18:46 +00:00
echo "✅ Bootstrap installation complete!"
2025-07-07 23:53:50 +01:00
echo ""
2026-02-08 20:18:46 +00:00
echo "🎯 Next steps:"
echo " 1. Restart your terminal or run: source ~/.bashrc (or ~/.zshrc)"
echo " 2. Run full installer: nu scripts/install-prerequisites.nu"
echo " 3. Verify installation: nu scripts/verify-prerequisites.nu"
echo " 4. Create your first project: rustelo new my-website"
2025-07-07 23:53:50 +01:00
echo ""
2026-02-08 20:18:46 +00:00
echo "📚 Documentation: BUILDING_WEBSITES_WITH_RUSTELO.md"
2025-07-07 23:53:50 +01:00
}
# Run main function
2026-02-08 20:18:46 +00:00
main "$@"