-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-admin-panel.sh
More file actions
152 lines (131 loc) · 5.89 KB
/
deploy-admin-panel.sh
File metadata and controls
152 lines (131 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
# =============================================================================
# Overleaf Admin Panel — Deployment Script
# Deploys the user-management web panel to the Overleaf server via SSH.
#
# Usage: ./deploy-admin-panel.sh
# Reads connection parameters from .env in the same directory.
# =============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PANEL_DIR="${SCRIPT_DIR}/admin-panel"
# ---- Load .env ----
if [[ ! -f "${SCRIPT_DIR}/.env" ]]; then
echo "ERROR: .env file not found in ${SCRIPT_DIR}"
exit 1
fi
source "${SCRIPT_DIR}/.env"
HOST="${HOST_NAME}"
USER="${HOST_USERNAME}"
PASS="${HOST_PASS}"
PORT="${HOST_PORT:-22}"
# ---- Check dependencies ----
if ! command -v sshpass &>/dev/null; then
echo "ERROR: sshpass is required but not installed."
echo ""
echo " macOS: brew install hudochenkov/sshpass/sshpass"
echo " Linux: sudo apt install sshpass"
exit 1
fi
# ---- SSH helpers ----
SSH_OPTS="-o StrictHostKeyChecking=no -o LogLevel=ERROR -o ServerAliveInterval=15 -o ServerAliveCountMax=10"
ssh_run() {
sshpass -p "${PASS}" ssh ${SSH_OPTS} -p "${PORT}" "${USER}@${HOST}" "$@"
}
# Run a command with sudo, piping password via stdin (-S)
ssh_sudo() {
ssh_run "echo '${PASS}' | sudo -S bash -c '$*' 2>&1"
}
scp_file() {
sshpass -p "${PASS}" scp ${SSH_OPTS} -P "${PORT}" "$1" "${USER}@${HOST}:$2"
}
# ---- Generate credentials ----
ADMIN_PANEL_PASS="$(openssl rand -base64 18 | tr -d '/+=' | head -c 16)"
SECRET_KEY="$(openssl rand -hex 32)"
echo "═══════════════════════════════════════════════════"
echo " Overleaf Admin Panel — Deployment"
echo "═══════════════════════════════════════════════════"
echo " Server: ${HOST}"
echo ""
# ------------------------------------------------------------------
# Step 1 — Create directories
# ------------------------------------------------------------------
echo "[1/6] Creating directories on server…"
ssh_sudo "mkdir -p /opt/overleaf-admin-panel/templates"
# ------------------------------------------------------------------
# Step 2 — Upload application files
# ------------------------------------------------------------------
echo "[2/6] Uploading application files…"
for f in app.py Dockerfile requirements.txt update_nginx.py; do
scp_file "${PANEL_DIR}/${f}" "/tmp/oa_${f}"
ssh_sudo "mv /tmp/oa_${f} /opt/overleaf-admin-panel/${f}"
done
for f in layout.html login.html index.html; do
scp_file "${PANEL_DIR}/templates/${f}" "/tmp/oa_${f}"
ssh_sudo "mv /tmp/oa_${f} /opt/overleaf-admin-panel/templates/${f}"
done
# ------------------------------------------------------------------
# Step 3 — Create docker-compose.override.yml
# ------------------------------------------------------------------
echo "[3/6] Configuring docker-compose.override.yml…"
# NOTE: The Overleaf Toolkit reads overrides from config/docker-compose.override.yml
OVERRIDE_DEST="/opt/overleaf-toolkit/config/docker-compose.override.yml"
# Build the override content locally (with credentials injected)
OVERRIDE_FILE=$(mktemp)
cat > "${OVERRIDE_FILE}" <<EOF
services:
admin-panel:
build: /opt/overleaf-admin-panel
container_name: overleaf-admin
restart: unless-stopped
environment:
- ADMIN_PASSWORD=${ADMIN_PANEL_PASS}
- MONGO_URL=mongodb://mongo:27017/sharelatex
- SHARELATEX_CONTAINER=sharelatex
- SECRET_KEY=${SECRET_KEY}
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
depends_on:
- mongo
- sharelatex
EOF
# Check for existing override file
if ssh_run "test -f ${OVERRIDE_DEST}" 2>/dev/null; then
if ssh_run "grep -q 'admin-panel' ${OVERRIDE_DEST}" 2>/dev/null; then
echo " → Override file already has admin-panel configuration (skipped)"
else
echo " → WARNING: docker-compose.override.yml already exists without admin-panel."
echo " New config saved to ${OVERRIDE_DEST}.admin-panel"
echo " Please merge it manually."
scp_file "${OVERRIDE_FILE}" "/tmp/oa_override.yml"
ssh_sudo "mv /tmp/oa_override.yml ${OVERRIDE_DEST}.admin-panel"
fi
else
scp_file "${OVERRIDE_FILE}" "/tmp/oa_override.yml"
ssh_sudo "mv /tmp/oa_override.yml ${OVERRIDE_DEST}"
echo " → Created successfully"
fi
rm -f "${OVERRIDE_FILE}"
# ------------------------------------------------------------------
# Step 4 — Update Nginx config
# ------------------------------------------------------------------
echo "[4/6] Updating Nginx configuration…"
ssh_sudo "python3 /opt/overleaf-admin-panel/update_nginx.py"
# ------------------------------------------------------------------
# Step 5 & 6 — Build and restart in a single SSH session
# ------------------------------------------------------------------
echo "[5/6] Building admin panel container y reiniciando servicios…"
ssh_run "echo '${PASS}' | sudo -S bash -c 'cd /opt/overleaf-toolkit && bin/docker-compose build admin-panel 2>&1 && bin/stop 2>&1 && bin/up -d 2>&1'"
echo ""
echo "═══════════════════════════════════════════════════"
echo " Deployment complete!"
echo "═══════════════════════════════════════════════════"
echo ""
echo " URL: https://${HOST}/admin-panel/"
echo " Password: ${ADMIN_PANEL_PASS}"
echo ""
echo " ⚠ Save this password! To change it later:"
echo " 1. Edit /opt/overleaf-toolkit/config/docker-compose.override.yml"
echo " (change the ADMIN_PASSWORD value)"
echo " 2. Restart: cd /opt/overleaf-toolkit && sudo bin/stop && sudo bin/up -d"
echo ""