Files
NomadArch/Install-Mac.sh
Gemini AI eb863bdde7
Some checks failed
Release Binaries / release (push) Has been cancelled
fix: update all installers to robust ASCII-only versions for maximum compatibility
2025-12-29 03:53:27 +04:00

297 lines
9.5 KiB
Bash

#!/bin/bash
# NomadArch Installer for macOS
# Version: 0.6.1 - Universal Edition
# Exit on undefined variables
set -u
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
BOLD='\033[1m'
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TARGET_DIR="$SCRIPT_DIR"
BIN_DIR="$TARGET_DIR/bin"
LOG_FILE="$TARGET_DIR/install.log"
ERRORS=0
WARNINGS=0
BINARY_FREE_MODE=1
# Logging function
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE"
}
print_header() {
echo ""
echo -e "${CYAN}==============================================================${NC}"
echo -e "${CYAN}|${NC} ${BOLD}NomadArch Installer for macOS${NC} ${CYAN}|${NC}"
echo -e "${CYAN}|${NC} Version: 0.6.1 - Universal Edition ${CYAN}|${NC}"
echo -e "${CYAN}==============================================================${NC}"
echo ""
}
print_header
log "========== Installer started =========="
# ---------------------------------------------------------------
# STEP 1: OS and Architecture Detection
# ---------------------------------------------------------------
echo "[STEP 1/8] Detecting System..."
OS_TYPE=$(uname -s)
ARCH_TYPE=$(uname -m)
log "OS: $OS_TYPE, Arch: $ARCH_TYPE"
if [[ "$OS_TYPE" != "Darwin" ]]; then
echo -e "${RED}[ERROR]${NC} This installer is for macOS. Current OS: $OS_TYPE"
echo " Use Install-Linux.sh for Linux or Install-Windows.bat for Windows."
log "ERROR: Not macOS ($OS_TYPE)"
exit 1
fi
case "$ARCH_TYPE" in
x86_64) ARCH="x64" ;;
arm64) ARCH="arm64" ;;
*)
echo -e "${YELLOW}[WARN]${NC} Unusual architecture: $ARCH_TYPE (proceeding anyway)"
ARCH="$ARCH_TYPE"
((WARNINGS++)) || true
;;
esac
echo -e "${GREEN}[OK]${NC} OS: macOS ($OS_TYPE)"
echo -e "${GREEN}[OK]${NC} Architecture: $ARCH_TYPE ($ARCH)"
# ---------------------------------------------------------------
# STEP 2: Check Write Permissions
# ---------------------------------------------------------------
echo ""
echo "[STEP 2/8] Checking Write Permissions..."
mkdir -p "$BIN_DIR" 2>/dev/null || true
if ! touch "$SCRIPT_DIR/.install-write-test" 2>/dev/null; then
echo -e "${YELLOW}[WARN]${NC} No write access to $SCRIPT_DIR"
TARGET_DIR="$HOME/.nomadarch"
BIN_DIR="$TARGET_DIR/bin"
LOG_FILE="$TARGET_DIR/install.log"
mkdir -p "$BIN_DIR"
cp -R "$SCRIPT_DIR/"* "$TARGET_DIR/" 2>/dev/null || true
echo -e "${GREEN}[INFO]${NC} Using fallback location: $TARGET_DIR"
else
rm "$SCRIPT_DIR/.install-write-test" 2>/dev/null
echo -e "${GREEN}[OK]${NC} Write permissions verified"
fi
log "Install target: $TARGET_DIR"
# ---------------------------------------------------------------
# STEP 3: Check and Install Node.js
# ---------------------------------------------------------------
echo ""
echo "[STEP 3/8] Checking Node.js..."
NODE_OK=0
NPM_OK=0
if command -v node >/dev/null 2>&1; then
NODE_VERSION=$(node --version)
echo -e "${GREEN}[OK]${NC} Node.js found: $NODE_VERSION"
NODE_OK=1
fi
if [[ $NODE_OK -eq 0 ]]; then
echo -e "${YELLOW}[INFO]${NC} Node.js not found. Attempting automatic installation..."
log "Node.js not found, attempting install"
# Check for Homebrew
if command -v brew >/dev/null 2>&1; then
echo -e "${GREEN}[INFO]${NC} Installing Node.js via Homebrew..."
brew install node
if [[ $? -eq 0 ]]; then
echo -e "${GREEN}[OK]${NC} Node.js installed via Homebrew"
NODE_OK=1
else
echo -e "${RED}[ERROR]${NC} Homebrew install failed"
fi
else
echo -e "${YELLOW}[WARN]${NC} Homebrew not found. Trying direct download..."
# Download macOS installer
DOWNLOAD_URL="https://nodejs.org/dist/v20.10.0/node-v20.10.0.pkg"
PKG_FILE="$TARGET_DIR/node-installer.pkg"
echo -e "${GREEN}[INFO]${NC} Downloading Node.js installer..."
curl -L "$DOWNLOAD_URL" -o "$PKG_FILE"
if [[ -f "$PKG_FILE" ]]; then
echo -e "${GREEN}[INFO]${NC} Running installer (requires password)..."
if sudo installer -pkg "$PKG_FILE" -target /; then
echo -e "${GREEN}[OK]${NC} Node.js installed successfully"
NODE_OK=1
else
echo -e "${RED}[ERROR]${NC} Node.js installation failed"
fi
rm "$PKG_FILE"
else
echo -e "${RED}[ERROR]${NC} Failed to download Node.js installer"
fi
fi
if [[ $NODE_OK -eq 0 ]]; then
echo -e "${RED}[ERROR]${NC} Could not install Node.js automatically."
echo "Please install Node.js manually from https://nodejs.org/"
echo "and run this installer again."
log "ERROR: Node.js installation failed"
((ERRORS++))
fi
fi
# Check npm
if command -v npm >/dev/null 2>&1; then
NPM_VERSION=$(npm --version)
echo -e "${GREEN}[OK]${NC} npm found: $NPM_VERSION"
NPM_OK=1
else
echo -e "${RED}[ERROR]${NC} npm not found (check Node.js installation)"
((ERRORS++))
fi
# ---------------------------------------------------------------
# STEP 4: Check Git (Optional)
# ---------------------------------------------------------------
echo ""
echo "[STEP 4/8] Checking Git (optional)..."
if command -v git >/dev/null 2>&1; then
GIT_VERSION=$(git --version)
echo -e "${GREEN}[OK]${NC} $GIT_VERSION"
else
echo -e "${YELLOW}[INFO]${NC} Git not found (optional)"
((WARNINGS++))
fi
# ---------------------------------------------------------------
# STEP 5: Install Dependencies
# ---------------------------------------------------------------
echo ""
echo "[STEP 5/8] Installing Dependencies..."
cd "$TARGET_DIR" || exit 1
if [[ ! -f "package.json" ]]; then
echo -e "${RED}[ERROR]${NC} package.json not found in $TARGET_DIR"
log "ERROR: package.json missing"
((ERRORS++))
else
echo -e "${GREEN}[INFO]${NC} Running npm install..."
log "Running npm install"
if npm install --no-audit --no-fund; then
echo -e "${GREEN}[OK]${NC} Dependencies installed"
else
echo -e "${YELLOW}[WARN]${NC} npm install issues, trying legacy peer deps..."
if npm install --legacy-peer-deps --no-audit --no-fund; then
echo -e "${GREEN}[OK]${NC} Dependencies installed (legacy mode)"
else
echo -e "${RED}[ERROR]${NC} npm install failed"
log "ERROR: npm install failed"
((ERRORS++))
fi
fi
fi
# ---------------------------------------------------------------
# STEP 6: OpenCode Setup
# ---------------------------------------------------------------
echo ""
echo "[STEP 6/8] OpenCode Setup..."
echo ""
echo -e "${CYAN}==============================================================${NC}"
echo -e "${CYAN}|${NC} NomadArch supports Binary-Free Mode! ${CYAN}|${NC}"
echo -e "${CYAN}|${NC} Using free cloud models: GPT-5 Nano, Grok Code, etc. ${CYAN}|${NC}"
echo -e "${CYAN}==============================================================${NC}"
echo ""
echo -e "${GREEN}[OK]${NC} Using Binary-Free Mode (default)"
log "Using Binary-Free Mode"
# ---------------------------------------------------------------
# STEP 7: Build Assets
# ---------------------------------------------------------------
echo ""
echo "[STEP 7/8] Building Assets..."
if [[ -f "$TARGET_DIR/packages/ui/dist/index.html" ]]; then
echo -e "${GREEN}[OK]${NC} UI build exists"
else
echo -e "${GREEN}[INFO]${NC} Building UI..."
cd "$TARGET_DIR/packages/ui" || exit 1
if npm run build; then
echo -e "${GREEN}[OK]${NC} UI assets built"
else
echo -e "${RED}[ERROR]${NC} UI build failed"
log "ERROR: UI build failed"
((ERRORS++))
fi
cd "$TARGET_DIR" || exit 1
fi
# ---------------------------------------------------------------
# STEP 8: Health Check
# ---------------------------------------------------------------
echo ""
echo "[STEP 8/8] Running Health Check..."
HEALTH_OK=1
[[ -f "$TARGET_DIR/package.json" ]] || HEALTH_OK=0
[[ -d "$TARGET_DIR/packages/ui" ]] || HEALTH_OK=0
[[ -d "$TARGET_DIR/packages/server" ]] || HEALTH_OK=0
[[ -d "$TARGET_DIR/node_modules" ]] || HEALTH_OK=0
if [[ $HEALTH_OK -eq 1 ]]; then
echo -e "${GREEN}[OK]${NC} All checks passed"
else
echo -e "${RED}[ERROR]${NC} Health checks failed"
((ERRORS++))
fi
# ---------------------------------------------------------------
# SUMMARY
# ---------------------------------------------------------------
echo ""
echo -e "${CYAN}==============================================================${NC}"
echo -e "${CYAN}|${NC} INSTALLATION SUMMARY ${CYAN}|${NC}"
echo -e "${CYAN}==============================================================${NC}"
echo ""
echo " Target: $TARGET_DIR"
echo " Mode: Binary-Free Mode"
echo " Errors: $ERRORS"
echo " Warnings: $WARNINGS"
echo ""
if [[ $ERRORS -gt 0 ]]; then
echo -e "${RED}==============================================================${NC}"
echo -e "${RED} INSTALLATION FAILED${NC}"
echo -e "${RED}==============================================================${NC}"
echo "Check the log file: $LOG_FILE"
exit 1
else
echo -e "${GREEN}==============================================================${NC}"
echo -e "${GREEN} INSTALLATION SUCCESSFUL!${NC}"
echo -e "${GREEN}==============================================================${NC}"
echo ""
echo "To start NomadArch, run:"
echo -e " ${BOLD}./Launch-Mac.sh${NC}"
echo ""
exit 0
fi