nomadro/apps/ebook/wemini/deploy/remote-setup.sh
eric d93a355fd5 Migrate navmini/ebook/nomadweb into apps/ as same-origin portal subpaths.
Shield external portal jumps (keep EXTERNAL_* for later), serve /nav from static build, and proxy /book + /community to vertical Next apps with Caddy notes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 03:30:34 -05:00

100 lines
2.7 KiB
Bash

#!/bin/bash
set -euo pipefail
APP_ROOT="/opt/nomadmini"
BACKEND="$APP_ROOT/backend"
ADMIN_WWW="/www/wwwroot/admin.nomadro.cn"
NGINX_VHOST="/www/server/panel/vhost/nginx"
echo "==> Prepare directories"
sudo mkdir -p "$ADMIN_WWW" "$APP_ROOT/data"
sudo rsync -a --delete "$APP_ROOT/admin/dist/" "$ADMIN_WWW/"
sudo chown -R www:www "$ADMIN_WWW"
sudo chown -R ubuntu:ubuntu "$APP_ROOT"
echo "==> Backend venv + deps"
cd "$BACKEND"
python3 -m venv .venv
./.venv/bin/pip install --upgrade pip
./.venv/bin/pip install -r requirements.txt
echo "==> systemd (port 8010)"
sudo cp "$APP_ROOT/deploy/nomadmini-api.service" /etc/systemd/system/nomadmini-api.service
sudo systemctl daemon-reload
sudo systemctl enable nomadmini-api
sudo systemctl restart nomadmini-api
echo "==> nginx vhosts (BaoTa)"
sudo cp "$APP_ROOT/deploy/api.nomadro.cn.conf" "$NGINX_VHOST/api.nomadro.cn.conf"
if [ ! -f "$NGINX_VHOST/admin.nomadro.cn.conf" ]; then
sudo cp "$APP_ROOT/deploy/admin.nomadro.cn.conf" "$NGINX_VHOST/admin.nomadro.cn.conf"
fi
sudo nginx -t
sudo systemctl reload nginx
echo "==> SSL for admin.nomadro.cn (if missing)"
if [ ! -d /etc/letsencrypt/live/admin.nomadro.cn ]; then
sudo certbot certonly --webroot -w "$ADMIN_WWW" -d admin.nomadro.cn \
--non-interactive --agree-tos -m admin@nomadro.cn || true
if [ -d /etc/letsencrypt/live/admin.nomadro.cn ]; then
sudo tee "$NGINX_VHOST/admin.nomadro.cn.conf" >/dev/null <<'EOF'
server
{
listen 80;
server_name admin.nomadro.cn;
root /www/wwwroot/admin.nomadro.cn;
location ~ ^/\.well-known/ {
allow all;
}
location / {
return 301 https://$host$request_uri;
}
access_log /www/wwwlogs/admin.nomadro.cn.log;
error_log /www/wwwlogs/admin.nomadro.cn.error.log;
}
server
{
listen 443 ssl http2;
server_name admin.nomadro.cn;
root /www/wwwroot/admin.nomadro.cn;
index index.html;
client_max_body_size 20m;
ssl_certificate /etc/letsencrypt/live/admin.nomadro.cn/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/admin.nomadro.cn/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location ~ ^/\.well-known/ {
allow all;
}
location /assets/ {
try_files $uri =404;
expires 30d;
add_header Cache-Control "public, immutable";
}
location / {
try_files $uri $uri/ /index.html;
}
access_log /www/wwwlogs/admin.nomadro.cn.log;
error_log /www/wwwlogs/admin.nomadro.cn.error.log;
}
EOF
sudo nginx -t && sudo systemctl reload nginx
fi
fi
echo "==> Status"
sudo systemctl status nomadmini-api --no-pager -l | head -15
curl -s http://127.0.0.1:8010/health || true
echo
echo "Deploy finished."