atlus/package.sh
roberts f9743bb29a Initial commit — Atlus web desktop environment for SBCs
Full-stack implementation: FastAPI backend with PAM auth, WebSocket
stats/terminal, and vanilla JS frontend with tiling desktop shell.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-14 16:53:46 -05:00

177 lines
5.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Build a self-contained Atlus tarball for deployment to SBCs.
# Usage: ./package.sh
# Output: atlus-<version>.tar.gz (scp it to the target, then run the bundled install)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
VERSION=$(date +%Y%m%d-%H%M%S)
STAGING="/tmp/atlus-package-$$"
OUT="${SCRIPT_DIR}/atlus-${VERSION}.tar.gz"
info() { echo -e "\033[1;34m[package]\033[0m $*"; }
ok() { echo -e "\033[1;32m[package]\033[0m $*"; }
cleanup() { rm -rf "$STAGING"; }
trap cleanup EXIT
info "Packaging Atlus..."
# Create staging directory
mkdir -p "$STAGING/atlus"
# Copy application files (exclude dev artifacts)
rsync -a --exclude='.git' \
--exclude='venv' \
--exclude='.claude' \
--exclude='.atlus_data' \
--exclude='.DS_Store' \
--exclude='__pycache__' \
--exclude='*.pyc' \
--exclude='atlus-*.tar.gz' \
--exclude='package.sh' \
"$SCRIPT_DIR/" "$STAGING/atlus/"
# Create the deploy script that lives inside the tarball
cat > "$STAGING/deploy.sh" << 'DEPLOY_EOF'
#!/usr/bin/env bash
# Atlus deployment script — run on the target SBC as root
# Usage: sudo ./deploy.sh
set -euo pipefail
INSTALL_DIR="/opt/atlus"
CONFIG_DIR="/etc/atlus"
DATA_DIR="/var/lib/atlus"
SERVICE_FILE="/etc/systemd/system/atlus.service"
info() { echo -e "\033[1;34m[atlus]\033[0m $*"; }
ok() { echo -e "\033[1;32m[atlus]\033[0m $*"; }
err() { echo -e "\033[1;31m[atlus]\033[0m $*" >&2; }
# ---------------------------------------------------------------------------
# Pre-flight
# ---------------------------------------------------------------------------
if [[ $EUID -ne 0 ]]; then
err "This installer must be run as root (use sudo)."
exit 1
fi
echo ""
echo " _ _ _"
echo " /_\ | |_| |_ _ ___"
echo " / _ \| _| | | | (_-<"
echo " /_/ \_\\\\__|_| \\_,_/__/"
echo ""
echo " Web Desktop Environment for SBCs"
echo ""
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
if [ -f /etc/os-release ]; then
. /etc/os-release
info "Detected OS: ${PRETTY_NAME:-Linux}"
else
info "Detected OS: Linux"
fi
# ---------------------------------------------------------------------------
# System dependencies
# ---------------------------------------------------------------------------
info "Installing system dependencies..."
apt-get update -qq
apt-get install -y -qq \
python3 python3-venv python3-dev python3-pip \
libpam0g-dev \
cifs-utils \
> /dev/null 2>&1
ok "System dependencies installed."
# ---------------------------------------------------------------------------
# Install application files
# ---------------------------------------------------------------------------
info "Installing Atlus to $INSTALL_DIR..."
# Back up existing config if upgrading
if [ -d "$INSTALL_DIR" ] && [ -d "$CONFIG_DIR" ]; then
info "Existing installation found — upgrading..."
fi
# Copy application files
mkdir -p "$INSTALL_DIR"
rsync -a --delete \
--exclude='venv' \
"$SCRIPT_DIR/atlus/" "$INSTALL_DIR/"
# ---------------------------------------------------------------------------
# Python virtual environment
# ---------------------------------------------------------------------------
info "Setting up Python virtual environment..."
if [ ! -d "$INSTALL_DIR/venv" ]; then
python3 -m venv "$INSTALL_DIR/venv"
fi
"$INSTALL_DIR/venv/bin/pip" install --upgrade pip -q
"$INSTALL_DIR/venv/bin/pip" install -r "$INSTALL_DIR/backend/requirements.txt" -q
ok "Python dependencies installed."
# ---------------------------------------------------------------------------
# Directories and permissions
# ---------------------------------------------------------------------------
mkdir -p "$CONFIG_DIR" "$DATA_DIR"
chmod 700 "$DATA_DIR"
# ---------------------------------------------------------------------------
# systemd service
# ---------------------------------------------------------------------------
info "Installing systemd service..."
cp "$INSTALL_DIR/atlus.service" "$SERVICE_FILE"
systemctl daemon-reload
systemctl enable atlus.service
systemctl restart atlus.service
ok "Atlus service started."
# ---------------------------------------------------------------------------
# Done
# ---------------------------------------------------------------------------
echo ""
ok "============================="
ok " Atlus installed!"
ok "============================="
echo ""
IP=$(hostname -I 2>/dev/null | awk '{print $1}')
if [ -n "$IP" ]; then
info "Access Atlus at: http://$IP:7779"
else
info "Access Atlus at: http://$(hostname):7779"
fi
info "Log in with any system user (PAM authentication)."
echo ""
info "Manage the service:"
info " systemctl status atlus"
info " systemctl restart atlus"
info " journalctl -u atlus -f"
echo ""
DEPLOY_EOF
chmod +x "$STAGING/deploy.sh"
# Build tarball
info "Creating tarball..."
tar -czf "$OUT" -C "$STAGING" deploy.sh atlus/
ok "Package built: $OUT"
FILESIZE=$(du -h "$OUT" | cut -f1)
ok "Size: $FILESIZE"
echo ""
info "Deploy to your SBC:"
info " scp $OUT user@your-sbc:~/"
info " ssh user@your-sbc"
info " tar xzf $(basename "$OUT")"
info " sudo ./deploy.sh"
echo ""