#!/bin/sh # install.sh - furt Installation and Update Orchestrator set -e # Parse command line arguments UPGRADE_MODE=false SKIP_USER=false SKIP_SERVICE=false while [ $# -gt 0 ]; do case "$1" in --upgrade) UPGRADE_MODE=true; shift ;; --skip-user) SKIP_USER=true; shift ;; --skip-service) SKIP_SERVICE=true; shift ;; --help) echo "Usage: $0 [--upgrade] [--skip-user] [--skip-service]" echo " --upgrade Update existing installation (skip user/service creation)" echo " --skip-user Skip user creation step" echo " --skip-service Skip service creation step" exit 0 ;; *) echo "Unknown option: $1"; exit 1 ;; esac done # Validate we're in furt source directory if [ ! -f "src/main.lua" ] || [ ! -d "scripts" ]; then echo "Error: Not in furt source directory" echo "Expected files: src/main.lua, scripts/ directory" exit 1 fi echo "=== furt Installation ===" if [ "$UPGRADE_MODE" = "true" ]; then echo "Mode: Upgrade (preserving config and service)" else echo "Mode: Fresh installation" fi # Step 1: Create system user (skip in upgrade mode) if [ "$UPGRADE_MODE" = "false" ] && [ "$SKIP_USER" = "false" ]; then echo "\n[1/6] Creating system user..." ./scripts/setup-user.sh else echo "\n[1/6] Skipping user creation (upgrade mode)" fi # Step 2: Setup directories echo "\n[2/6] Setting up directories..." ./scripts/setup-directories.sh # Step 3: Sync source files (always needed for updates) echo "\n[3/6] Syncing source files..." ./scripts/sync-files.sh # Step 4: Create service (skip in upgrade mode unless requested) if [ "$UPGRADE_MODE" = "false" ] && [ "$SKIP_SERVICE" = "false" ]; then echo "\n[4/6] Creating system service..." ./scripts/create-service.sh else echo "\n[4/6] Skipping service creation (upgrade mode)" fi # Step 5: Validate configuration echo "\n[5/6] Validating configuration..." if ./scripts/validate-config.sh; then echo "Configuration validation successful" else echo "Warning: Configuration validation failed - manual setup may be needed" fi # Step 6: Health check echo "\n[6/6] Performing health check..." if ./scripts/health-check.sh >/dev/null 2>&1; then echo "Health check passed - furt is running" else echo "Health check failed - service may need to be started manually" fi # Installation summary echo "\n=== Installation Summary ===" if [ "$UPGRADE_MODE" = "true" ]; then echo "furt upgrade completed successfully" echo "" echo "Source code updated to:" if [ -f "/usr/local/share/furt/VERSION" ]; then echo " Version: $(cat /usr/local/share/furt/VERSION)" fi if [ -f "/usr/local/share/furt/.version_history" ]; then echo " Version history available (for furt internal tracking)" fi echo "" echo "Service restart required:" if [ "$(uname)" = "OpenBSD" ]; then echo " doas rcctl restart furt" else echo " sudo systemctl restart furt" fi else echo "furt installation completed successfully" echo "" echo "Next steps:" echo "1. Edit configuration file:" if [ "$(uname)" = "OpenBSD" ] || [ "$(uname)" = "FreeBSD" ]; then echo " /usr/local/etc/furt/furt.conf" else echo " /etc/furt/furt.conf" fi echo "2. Start the service:" if [ "$(uname)" = "OpenBSD" ]; then echo " doas rcctl start furt" else echo " sudo systemctl start furt" fi echo "3. Test the API:" echo " curl http://127.0.0.1:7811/health" fi echo "" echo "Installation log available in system logs"