refactor(setup): remove tmux dependency from setup.sh

This commit is contained in:
2026-04-13 18:54:16 +02:00 Unverified
parent 479a03a1e1
commit e77be87c7d
+23 -44
View File
@@ -13,18 +13,27 @@ info() { echo -e "${GREEN}[+]${NC} $*"; }
warn() { echo -e "${YELLOW}[!]${NC} $*"; }
die() { echo -e "${RED}[✗] FATAL:${NC} $*" >&2; exit 1; }
SESSION="theplug"
start_proxy() {
API_PORT=$(grep -E '^API_PORT=' .env | cut -d '=' -f2)
API_PORT=${API_PORT:-3671}
info "Launching FastAPI on port $API_PORT..."
PYTHONPATH=app uv run uvicorn app.main:app --host 0.0.0.0 --port "$API_PORT" 2>&1 &
PID=$!
warn "Started thePlug with PID [$PID], 'pkill -9 $PID' to kill it"
}
# ── 1. ensure we're in thePlug ────────────────────────────────────────────────
if [[ "$PWD" != "/srv/theplug" ]]; then
if tmux has-session -t "$SESSION" 2>/dev/null; then
info "thePlug già in esecuzione — attaching..."
exec tmux attach -t "$SESSION"
if [[ -d "/srv/theplug" ]]; then
info "thePlug già presente — avvio diretto..."
cd /srv/theplug
start_proxy
exit 0
fi
cd /srv
git clone https://git.reloia.uk/reloia/thePlug theplug || die "git clone failed"
cd theplug
fi
chmod +x ./setup.sh
@@ -66,56 +75,26 @@ if ! command -v uv &>/dev/null; then
info "uv installed: $(uv --version)"
fi
# ── 5. ensure tmux is available ───────────────────────────────────────────────
if ! command -v tmux &>/dev/null; then
warn "tmux not found — installing..."
sudo apt-get install -y tmux || die "tmux installation failed"
info "tmux installed"
fi
# ── 6. venv + deps ────────────────────────────────────────────────────────────
# ── 5. venv + deps ────────────────────────────────────────────────────────────
info "Pinning Python 3.14..."
uv python pin 3.14
info "Creating/updating venv..."
info "Creating venv..."
uv venv
source .venv/bin/activate
info "Syncing dependencies..."
uv sync
# ── 7. run in tmux with autorestart ───────────────────────────────────────────
if tmux has-session -t "$SESSION" 2>/dev/null; then
warn "tmux session '$SESSION' already exists — killing it..."
tmux kill-session -t "$SESSION"
fi
# 6 start
start_proxy
info "Launching FastAPI in tmux session '$SESSION'..."
API_PORT=$(grep -E '^API_PORT=' .env | cut -d '=' -f2)
API_PORT=${API_PORT:-3671}
tmux new-session -d -s "$SESSION" "bash -c '
cd $(pwd)
source .venv/bin/activate
while true; do
echo \"[\$(date +%T)] Starting uvicorn...\"
PYTHONPATH=app uv run uvicorn app.main:app --host 0.0.0.0 --port $API_PORT 2>&1 | tee uvicorn.log
echo \"[\$(date +%T)] Process exited — restarting in 3s (Ctrl+C to stop)\"
sleep 3
done
'"
echo -e "";
echo -e ""
info "Automatically generated Secrets:"
info " MONGO_PASS: $MONGO_PASS"
info " JWT_SECRET: $JWT_SECRET"
info " AUTH_PASS: $AUTH_PASS - questa è importante"
warn "Save them — these won't be showed again (non è vero basta che leggi $PLUG_DIR/.env)"
echo -e "";
echo -e ""
info "Installed this script into /usr/bin/theplug"
info "Installed in $PLUG_DIR"
echo -e "";
info "Done — attach with: 'theplug' or 'tmux attach -t $SESSION'"
warn "To detatch from tmux do: ctrl+b d"
info "Installed thePlug in $PLUG_DIR"
echo -e ""