#!/usr/bin/env bash # WifiCone Software — one-command installer # Usage: bash <(curl -fsSL https://get.wificone.com) # # Installs WifiCone vendo software on: # - Debian 12 / Ubuntu 22.04+ # - amd64, arm64, armv7 set -euo pipefail WFC_DIR="/opt/wificone" RELEASE_REPO="https://github.com/wificone/wfc-release.git" SERVICE_USER="wificone" APP_PORT="3000" NGINX_PORT="80" DB_NAME="wificone" DB_USER="wificone" RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m' log() { echo -e "${BLUE}▶${NC} $*"; } ok() { echo -e "${GREEN}✓${NC} $*"; } warn() { echo -e "${YELLOW}⚠${NC} $*"; } die() { echo -e "${RED}✗${NC} $*" >&2; exit 1; } echo -e "\n${BLUE}╔══════════════════════════════════════╗${NC}" echo -e "${BLUE}║ WifiCone Software Installer ║${NC}" echo -e "${BLUE}╚══════════════════════════════════════╝${NC}\n" # ── Root check ──────────────────────────────────────────────────────────────── [[ $EUID -eq 0 ]] || die "Run as root: sudo bash install.sh" # ── Detect architecture ─────────────────────────────────────────────────────── MACHINE=$(uname -m) case "$MACHINE" in x86_64) ARCH="x64" ;; aarch64|arm64) ARCH="arm64" ;; armv7l|armhf) ARCH="armv7" ;; *) die "Unsupported architecture: $MACHINE" ;; esac ok "Architecture: $ARCH ($MACHINE)" # ── Save arch for updater ───────────────────────────────────────────────────── mkdir -p /etc/wificone echo "$ARCH" > /etc/wificone/arch # ── Install system packages ─────────────────────────────────────────────────── log "Installing system dependencies" apt-get update -qq apt-get install -y -qq nginx postgresql git curl 2>/dev/null ok "System packages installed" # ── Clone wfc-release ──────────────────────────────────────────────────────── log "Downloading WifiCone release" if [[ -d "$WFC_DIR/.git" ]]; then git -C "$WFC_DIR" pull --quiet ok "wfc-release updated" else git clone --depth=1 "$RELEASE_REPO" "$WFC_DIR" ok "wfc-release cloned" fi VERSION=$(cat "$WFC_DIR/version.txt" 2>/dev/null || echo "unknown") ok "Version: $VERSION" # ── Install binary ──────────────────────────────────────────────────────────── log "Installing wificone binary" BINARY="$WFC_DIR/bin/wificone-linux-$ARCH" [[ -f "$BINARY" ]] || die "Binary not found for arch $ARCH: $BINARY" cp "$BINARY" /usr/local/bin/wificone chmod +x /usr/local/bin/wificone # Keep previous binary for rollback [[ -f /usr/local/bin/wificone.prev ]] && cp /usr/local/bin/wificone.prev /usr/local/bin/wificone.prev.bak || true cp /usr/local/bin/wificone /usr/local/bin/wificone.prev ok "Binary installed: /usr/local/bin/wificone" # ── Copy config defaults (if not already present) ──────────────────────────── log "Setting up configuration" mkdir -p /etc/wificone if [[ -d "$WFC_DIR/config/defaults" ]]; then for f in "$WFC_DIR/config/defaults/"*; do dest="/etc/wificone/$(basename "$f")" [[ -f "$dest" ]] || cp "$f" "$dest" done fi ok "Config at /etc/wificone/" # ── PostgreSQL setup ────────────────────────────────────────────────────────── log "Setting up PostgreSQL" systemctl enable postgresql --quiet systemctl start postgresql # Generate a random DB password DB_PASS="$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 32)" # Create user + database (idempotent) sudo -u postgres psql -tc "SELECT 1 FROM pg_roles WHERE rolname='$DB_USER'" | grep -q 1 || \ sudo -u postgres psql -c "CREATE USER $DB_USER WITH PASSWORD '$DB_PASS';" sudo -u postgres psql -tc "SELECT 1 FROM pg_database WHERE datname='$DB_NAME'" | grep -q 1 || \ sudo -u postgres psql -c "CREATE DATABASE $DB_NAME OWNER $DB_USER;" # Save DB credentials for the app cat > /etc/wificone/db.env </dev/null; then useradd -r -s /bin/false -d /var/lib/wificone "$SERVICE_USER" fi mkdir -p /var/lib/wificone chown -R "$SERVICE_USER:$SERVICE_USER" /var/lib/wificone /etc/wificone # ── nginx ──────────────────────────────────────────────────────────────────── log "Configuring nginx" cat > /etc/nginx/sites-available/wificone < /etc/systemd/system/wificone.service < /etc/systemd/system/wificone-updater.service < /etc/systemd/system/wificone-updater.timer <