#!/usr/bin/env bash set -euo pipefail echo "" echo "============================================" echo " Zlattea - Install" echo "============================================" echo "" # --- require non-root for local setup --- if [ "$(id -u)" = "0" ]; then echo "This install script is for local/home setup." echo "Run as a regular user, not root." echo "" echo "For production (systemd + reverse proxy), use:" echo " sudo ./install.sh" exit 1 fi # --- admin password --- if [ -z "${ADMIN_PASSWORD:-}" ]; then echo "Admin password (required for the admin account):" read -r -s -p "> " ADMIN_PASSWORD echo "" if [ -z "$ADMIN_PASSWORD" ]; then echo "ERROR: admin password is required." exit 1 fi fi # --- port and bind address --- if [ -z "${PORT:-}" ]; then echo "" echo "Port for the web server? (default: 3000)" read -r -p "> " PORT PORT="${PORT:-3000}" fi if [ -z "${BIND:-}" ]; then echo "" echo "IP address to bind to? (default: 127.0.0.1)" read -r -p "> " BIND BIND="${BIND:-127.0.0.1}" fi API_PORT=$((PORT + 1)) echo "" echo "============================================" echo " Configuration" echo "============================================" echo " Web server : ${BIND}:${PORT}" echo " API server : ${BIND}:${API_PORT}" echo "============================================" echo "" # --- install prerequisites --- install_prereqs() { echo "checking prerequisites..." local missing="" for cmd in git curl unzip; do if ! command -v "$cmd" &>/dev/null; then missing="$missing $cmd" fi done if [ -n "$missing" ]; then echo "installing:$missing" if command -v apt-get &>/dev/null; then sudo apt-get update -qq && sudo apt-get install -y -qq $missing elif command -v dnf &>/dev/null; then sudo dnf install -y $missing elif command -v yum &>/dev/null; then sudo yum install -y $missing elif command -v pacman &>/dev/null; then sudo pacman -S --noconfirm $missing elif command -v apk &>/dev/null; then sudo apk add $missing else echo "WARNING: unknown package manager. Install manually: $missing" fi fi } install_prereqs # --- install bun --- if ! command -v bun &>/dev/null; then echo "installing bun..." curl -fsSL https://bun.sh/install | bash export BUN_INSTALL="$HOME/.bun" export PATH="$BUN_INSTALL/bin:$PATH" fi if ! command -v bun &>/dev/null; then echo "ERROR: bun installation failed." exit 1 fi # --- write .env --- cat > .env </dev/null; exit" INT TERM wait