-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·354 lines (309 loc) · 13.4 KB
/
install.sh
File metadata and controls
executable file
·354 lines (309 loc) · 13.4 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/usr/bin/env bash
# VyManager Installation Script
# Supports: Ubuntu/Debian, Fedora, CentOS/RHEL, Arch Linux, openSUSE
set -euo pipefail
# ============================================================================
# Colors & Formatting
# ============================================================================
BOLD='\033[1m'
DIM='\033[2m'
RESET='\033[0m'
CYAN='\033[36m'
GREEN='\033[32m'
YELLOW='\033[33m'
RED='\033[31m'
MAGENTA='\033[35m'
# ============================================================================
# UI Helpers
# ============================================================================
banner() {
clear
echo -e "${CYAN}${BOLD}"
echo " ╔═══════════════════════════════════════════════╗"
echo " ║ VyManager Installer ║"
echo " ║ Professional VyOS Management ║"
echo " ╚═══════════════════════════════════════════════╝"
echo -e "${RESET}"
}
info() { echo -e " ${CYAN}▸${RESET} $1"; }
success() { echo -e " ${GREEN}✓${RESET} $1"; }
warn() { echo -e " ${YELLOW}!${RESET} $1"; }
fail() { echo -e " ${RED}✗${RESET} $1"; exit 1; }
step() { echo -e "\n ${MAGENTA}${BOLD}[$1/$TOTAL_STEPS]${RESET} ${BOLD}$2${RESET}\n"; }
prompt() {
local var_name="$1" prompt_text="$2" default="${3:-}"
if [[ -n "$default" ]]; then
echo -en " ${CYAN}?${RESET} ${prompt_text} ${DIM}(${default})${RESET}: "
read -r input
eval "$var_name=\"${input:-$default}\""
else
echo -en " ${CYAN}?${RESET} ${prompt_text}: "
read -r input
while [[ -z "$input" ]]; do
echo -en " ${RED}!${RESET} This field is required: "
read -r input
done
eval "$var_name=\"$input\""
fi
}
prompt_secret() {
local var_name="$1" prompt_text="$2"
echo -en " ${CYAN}?${RESET} ${prompt_text}: "
read -rs input
echo
while [[ -z "$input" ]]; do
echo -en " ${RED}!${RESET} This field is required: "
read -rs input
echo
done
eval "$var_name=\"$input\""
}
prompt_yn() {
local prompt_text="$1" default="${2:-y}"
local hint="Y/n"
[[ "$default" == "n" ]] && hint="y/N"
echo -en " ${CYAN}?${RESET} ${prompt_text} ${DIM}(${hint})${RESET}: "
read -r input
input="${input:-$default}"
[[ "${input,,}" == "y" ]]
}
divider() {
echo -e " ${DIM}─────────────────────────────────────────────${RESET}"
}
# ============================================================================
# Detect Distro
# ============================================================================
detect_distro() {
if [[ -f /etc/os-release ]]; then
. /etc/os-release
DISTRO="${ID}"
DISTRO_FAMILY="${ID_LIKE:-$ID}"
else
fail "Cannot detect Linux distribution"
fi
}
# ============================================================================
# Install Docker
# ============================================================================
install_docker() {
if command -v docker &>/dev/null; then
success "Docker is already installed ($(docker --version | cut -d' ' -f3 | tr -d ','))"
return
fi
info "Installing Docker for ${BOLD}${DISTRO}${RESET}..."
case "$DISTRO" in
ubuntu|debian)
apt-get update -qq
apt-get install -y -qq ca-certificates curl gnupg >/dev/null
install -m 0755 -d /etc/apt/keyrings
curl -fsSL "https://download.docker.com/linux/${DISTRO}/gpg" | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/${DISTRO} $(. /etc/os-release && echo "$VERSION_CODENAME") stable" \
> /etc/apt/sources.list.d/docker.list
apt-get update -qq
apt-get install -y -qq docker-ce docker-ce-cli containerd.io docker-compose-plugin >/dev/null
;;
fedora)
dnf install -y -q dnf-plugins-core >/dev/null
dnf config-manager addrepo --from-repofile=https://download.docker.com/linux/fedora/docker-ce.repo
dnf install -y -q docker-ce docker-ce-cli containerd.io docker-compose-plugin >/dev/null
;;
centos|rhel|rocky|alma)
yum install -y -q yum-utils >/dev/null
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo >/dev/null
yum install -y -q docker-ce docker-ce-cli containerd.io docker-compose-plugin >/dev/null
;;
arch|manjaro)
pacman -Sy --noconfirm --quiet docker docker-compose >/dev/null
;;
opensuse*|sles)
zypper install -y -q docker docker-compose >/dev/null
;;
*)
fail "Unsupported distribution: ${DISTRO}. Install Docker manually and re-run this script."
;;
esac
systemctl enable --now docker >/dev/null 2>&1
success "Docker installed successfully"
}
# ============================================================================
# Generate Secrets
# ============================================================================
generate_secret() {
openssl rand -base64 32
}
generate_hex() {
openssl rand -hex 32
}
generate_db_pass() {
# Alphanumeric only — avoids URL-encoding issues in DATABASE_URL
# and special character issues with PostgreSQL connection strings
openssl rand -base64 32 | tr -dc 'A-Za-z0-9' | head -c 32
}
# ============================================================================
# Main
# ============================================================================
TOTAL_STEPS=5
INSTALL_DIR="/opt/vymanager"
REGISTRY="ghcr.io/community-vyprojects/vymanager"
banner
# Pre-flight checks
[[ $EUID -ne 0 ]] && fail "Please run as root: ${BOLD}sudo bash install.sh${RESET}"
detect_distro
success "Detected: ${BOLD}${DISTRO}${RESET}"
echo
# ──────────────────────────────────────────────────────────────────────────────
step 1 "Install Docker"
# ──────────────────────────────────────────────────────────────────────────────
install_docker
# ──────────────────────────────────────────────────────────────────────────────
step 2 "Configure VyManager"
# ──────────────────────────────────────────────────────────────────────────────
info "Answer the following to configure your deployment.\n"
prompt APP_URL "Application URL (e.g. https://vymanager.example.com)" "http://localhost:3000"
prompt FRONTEND_PORT "Frontend port" "3000"
prompt BACKEND_PORT "Backend port" "8000"
divider
prompt DB_USER "PostgreSQL username" "vymanager"
DB_PASS=$(generate_db_pass)
success "PostgreSQL password generated"
divider
if prompt_yn "Generate random secrets automatically?" "y"; then
AUTH_SECRET=$(generate_secret)
SSH_KEY=$(generate_hex)
success "Secrets generated"
else
prompt_secret AUTH_SECRET "Better Auth secret (base64 string)"
prompt_secret SSH_KEY "SSH encryption key (64-char hex)"
fi
echo
# ──────────────────────────────────────────────────────────────────────────────
step 3 "Create installation directory"
# ──────────────────────────────────────────────────────────────────────────────
mkdir -p "${INSTALL_DIR}"
success "Created ${INSTALL_DIR}"
# ──────────────────────────────────────────────────────────────────────────────
step 4 "Write configuration files"
# ──────────────────────────────────────────────────────────────────────────────
DB_URL="postgresql://${DB_USER}:${DB_PASS}@postgres:5432/vymanager"
# -- docker-compose.yml --
cat > "${INSTALL_DIR}/docker-compose.yml" <<YAML
services:
postgres:
image: postgres:16-alpine
container_name: vymanager-postgres
environment:
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASS}
POSTGRES_DB: vymanager
volumes:
- postgres_data:/var/lib/postgresql/data
restart: unless-stopped
networks:
- vymanager
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d vymanager"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
backend:
image: ${REGISTRY}-backend:beta
container_name: vymanager-backend
ports:
- "${BACKEND_PORT}:8000"
env_file:
- .env
restart: unless-stopped
networks:
- vymanager
depends_on:
postgres:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
frontend:
image: ${REGISTRY}-frontend:beta
container_name: vymanager-frontend
ports:
- "${FRONTEND_PORT}:3000"
env_file:
- .env
restart: unless-stopped
networks:
- vymanager
depends_on:
backend:
condition: service_healthy
postgres:
condition: service_healthy
networks:
vymanager:
driver: bridge
volumes:
postgres_data:
driver: local
YAML
success "docker-compose.yml"
# Build TRUSTED_ORIGINS (app URL + common local origins)
TRUSTED_ORIGINS="${APP_URL},http://localhost:${FRONTEND_PORT}"
# -- .env --
cat > "${INSTALL_DIR}/.env" <<EOF
# VyManager Configuration
# Generated by install.sh
# ============================================================================
# Application Environment
# ============================================================================
NODE_ENV=production
# ============================================================================
# Better Auth Configuration
# ============================================================================
BETTER_AUTH_SECRET=${AUTH_SECRET}
BETTER_AUTH_URL=${APP_URL}
NEXT_PUBLIC_APP_URL=${APP_URL}
# ============================================================================
# Backend / Frontend
# ============================================================================
BACKEND_URL=http://backend:8000
FRONTEND_URL=${APP_URL}
SSH_ENCRYPTION_KEY=${SSH_KEY}
# Trusted origins for CORS (comma-separated list)
TRUSTED_ORIGINS=${TRUSTED_ORIGINS}
# ============================================================================
# Database
# ============================================================================
DATABASE_URL=${DB_URL}
EOF
success ".env"
chmod 600 "${INSTALL_DIR}/.env"
success "Env file secured (chmod 600)"
# ──────────────────────────────────────────────────────────────────────────────
step 5 "Pull images & start VyManager"
# ──────────────────────────────────────────────────────────────────────────────
info "Pulling Docker images...\n"
docker compose -f "${INSTALL_DIR}/docker-compose.yml" pull
echo
info "Starting services...\n"
docker compose -f "${INSTALL_DIR}/docker-compose.yml" up -d
# ──────────────────────────────────────────────────────────────────────────────
# Done
# ──────────────────────────────────────────────────────────────────────────────
echo
echo -e " ${GREEN}${BOLD}═══════════════════════════════════════════════${RESET}"
echo -e " ${GREEN}${BOLD} VyManager is running!${RESET}"
echo -e " ${GREEN}${BOLD}═══════════════════════════════════════════════${RESET}"
echo
info "URL: ${BOLD}${APP_URL}${RESET}"
info "Install: ${BOLD}${INSTALL_DIR}${RESET}"
echo
info "Manage with:"
echo -e " ${DIM}cd ${INSTALL_DIR}${RESET}"
echo -e " ${DIM}docker compose logs -f ${RESET}${DIM}# view logs${RESET}"
echo -e " ${DIM}docker compose pull && \\\\${RESET}"
echo -e " ${DIM}docker compose down && \\\\${RESET}"
echo -e " ${DIM}docker compose up -d ${RESET}${DIM}# update${RESET}"
echo