-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsetup.sh
More file actions
310 lines (271 loc) · 11.2 KB
/
setup.sh
File metadata and controls
310 lines (271 loc) · 11.2 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
#!/usr/bin/env bash
set -euo pipefail
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
GUM_VERSION="0.16.0"
TOTAL_STEPS=6
CURRENT_STEP=0
# ── Dependency check ───────────────────────────────────────────────
if ! command -v gum &>/dev/null; then
echo "gum not found — downloading v${GUM_VERSION}..."
mkdir -p "$REPO_DIR/.bin"
ARCH=$(uname -m)
case "$ARCH" in
x86_64) ARCH="x86_64" ;;
aarch64|arm64) ARCH="arm64" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac
OS=$(uname -s)
case "$OS" in
Linux) OS="Linux" ;;
Darwin) OS="Darwin" ;;
*) echo "Unsupported OS: $OS"; exit 1 ;;
esac
curl -fsSL "https://github.com/charmbracelet/gum/releases/download/v${GUM_VERSION}/gum_${GUM_VERSION}_${OS}_${ARCH}.tar.gz" \
| tar xz -C "$REPO_DIR/.bin" --strip-components=1 "gum_${GUM_VERSION}_${OS}_${ARCH}/gum"
export PATH="$REPO_DIR/.bin:$PATH"
echo "gum installed to $REPO_DIR/.bin/gum"
fi
# ── Theme ──────────────────────────────────────────────────────────
ACCENT="212" # pink/magenta
MUTED="240" # gray
OK="2" # green
WARN="3" # yellow
# ── Header ─────────────────────────────────────────────────────────
echo ""
gum style \
--border double --padding "1 3" --margin "0 2" \
--border-foreground "$ACCENT" \
--bold --foreground "$ACCENT" \
"uncompressed" \
"" \
"$(gum style --faint 'Jellyfin + *arr + VPN isolation')" \
"$(gum style --faint 'setup wizard')"
# ── Helpers ────────────────────────────────────────────────────────
section() {
CURRENT_STEP=$((CURRENT_STEP + 1))
echo ""
gum style --bold --foreground "$ACCENT" \
"[$CURRENT_STEP/$TOTAL_STEPS] $1"
gum style --foreground "$MUTED" \
"$(printf '%.0s─' {1..45})"
}
hint() {
gum style --foreground "$MUTED" --italic --margin "0 0 0 2" "$@"
}
prompt() {
local label="$1" default="$2"
gum input \
--placeholder "$default" \
--value "$default" \
--header " $label" \
--header.foreground "$MUTED" \
--prompt "› " \
--prompt.foreground "$ACCENT" \
--cursor.foreground "$ACCENT"
}
prompt_required() {
local label="$1" default="${2:-}"
local value=""
while [ -z "$value" ]; do
if [ -n "$default" ]; then
value=$(gum input \
--placeholder "$default" \
--value "$default" \
--header " $label" \
--header.foreground "$MUTED" \
--prompt "› " \
--prompt.foreground "$ACCENT" \
--cursor.foreground "$ACCENT")
else
value=$(gum input \
--placeholder "required" \
--header " $label" \
--header.foreground "$MUTED" \
--prompt "› " \
--prompt.foreground "$ACCENT" \
--cursor.foreground "$ACCENT")
[ -z "$value" ] && gum style --foreground 1 " This field is required."
fi
done
echo "$value"
}
prompt_password_required() {
local label="$1"
local value=""
while [ -z "$value" ]; do
value=$(gum input --password \
--header " $label" \
--header.foreground "$MUTED" \
--prompt "› " \
--prompt.foreground "$ACCENT" \
--cursor.foreground "$ACCENT")
[ -z "$value" ] && gum style --foreground 1 " This field is required."
done
echo "$value"
}
ok() { gum style --foreground "$OK" " ✓ $1"; }
warn() { gum style --foreground "$WARN" " ⚠ $1"; }
skip() { gum style --foreground "$MUTED" " ⟳ $1"; }
# ── 1. System ─────────────────────────────────────────────────────
section "System"
TZ=$(prompt "Timezone" "Europe/Warsaw")
PUID=$(prompt "User ID (PUID)" "1000")
PGID=$(prompt "Group ID (PGID)" "1000")
# ── 2. Domain & Networking ────────────────────────────────────────
section "Domain & Networking"
hint "A \$2/yr .xyz domain works — DNS records point to your private Tailscale IP."
DOMAIN_NAME=$(prompt_required "Domain name (e.g. media.xyz)")
TAILSCALE_IP=$(prompt_required "Tailscale IP (e.g. 100.64.1.5)")
# ── 3. Cloudflare ─────────────────────────────────────────────────
section "Cloudflare"
hint "Create a scoped API token at dash.cloudflare.com → API Tokens" \
"Required scopes: Zone → Zone → Read + Zone → DNS → Edit"
CF_DNS_API_TOKEN=$(prompt_password_required "Cloudflare API token")
CF_API_EMAIL=$(prompt_required "Cloudflare account email")
ACME_EMAIL=$(prompt "ACME email (for Let's Encrypt)" "$CF_API_EMAIL")
# ── 4. ProtonVPN ──────────────────────────────────────────────────
section "ProtonVPN"
hint "WireGuard keys from account.protonvpn.com → Downloads → WireGuard configuration"
WG_PRIVATE_KEY=$(prompt_password_required "WireGuard private key")
WG_PUBLIC_KEY=$(prompt_required "WireGuard public key")
WIREGUARD_ADDRESSES=$(prompt "WireGuard address" "10.2.0.2/32")
echo ""
hint "OpenVPN credentials (used as fallback)"
PROTONVPN_USERNAME=$(prompt_required "ProtonVPN username")
PROTONVPN_PASSWORD=$(prompt_password_required "ProtonVPN password")
# ── 5. Volume Paths ───────────────────────────────────────────────
section "Volume Paths"
hint "Adjust for your system — defaults are Unraid paths."
DATA_DIR=$(prompt "Config/appdata base directory" "/mnt/user/appdata")
DOWNLOADS_DIR=$(prompt "Downloads directory" "/mnt/user/media/downloads/qbittorrent")
MEDIA_TV_DIR=$(prompt "TV shows directory" "/mnt/user/media/tv")
MEDIA_MOVIES_DIR=$(prompt "Movies directory" "/mnt/user/media/movies")
# ── 6. qBittorrent ────────────────────────────────────────────────
section "qBittorrent"
QB_USERNAME=$(prompt "WebUI username" "admin")
QB_PASSWORD=$(prompt_password_required "WebUI password")
BT_PORT=$(prompt "Torrenting port" "51413")
# ── Summary ────────────────────────────────────────────────────────
echo ""
gum style --bold --foreground "$ACCENT" "Review"
gum style --foreground "$MUTED" "$(printf '%.0s─' {1..45})"
gum style --border rounded --padding "1 2" --margin "0 2" \
--border-foreground "$MUTED" \
"$(gum style --bold 'Domain') $DOMAIN_NAME" \
"$(gum style --bold 'Tailscale IP') $TAILSCALE_IP" \
"$(gum style --bold 'CF Email') $CF_API_EMAIL" \
"" \
"$(gum style --bold 'Data dir') $DATA_DIR" \
"$(gum style --bold 'Downloads') $DOWNLOADS_DIR" \
"$(gum style --bold 'TV dir') $MEDIA_TV_DIR" \
"$(gum style --bold 'Movies dir') $MEDIA_MOVIES_DIR" \
"" \
"$(gum style --bold 'QB user') $QB_USERNAME" \
"$(gum style --bold 'QB port') $BT_PORT" \
"" \
"$(gum style --faint 'Secrets (CF token, VPN keys, passwords) are hidden.')"
echo ""
if ! gum confirm \
--prompt.foreground "$ACCENT" \
--selected.background "$ACCENT" \
"Write .env and set up?"; then
gum style --foreground 1 "Aborted."
exit 0
fi
# ── Write .env ─────────────────────────────────────────────────────
echo ""
ENV_FILE="$REPO_DIR/.env"
cat > "$ENV_FILE" <<EOF
# Generated by setup.sh
# Timezone
TZ=$TZ
# Container user/group IDs
PUID=$PUID
PGID=$PGID
# Domain for Traefik routing (*.$DOMAIN_NAME)
DOMAIN_NAME=$DOMAIN_NAME
# Tailscale IP (bind Traefik here, not 0.0.0.0)
TAILSCALE_IP=$TAILSCALE_IP
# Cloudflare (ACME DNS challenge for Let's Encrypt)
CF_DNS_API_TOKEN=$CF_DNS_API_TOKEN
CF_API_EMAIL=$CF_API_EMAIL
ACME_EMAIL=$ACME_EMAIL
# ProtonVPN WireGuard — main tunnel (NL/CH, P2P)
WG_PRIVATE_KEY=$WG_PRIVATE_KEY
WG_PUBLIC_KEY=$WG_PUBLIC_KEY
WIREGUARD_ADDRESSES=$WIREGUARD_ADDRESSES
# ProtonVPN credentials (OpenVPN fallback)
PROTONVPN_USERNAME=$PROTONVPN_USERNAME
PROTONVPN_PASSWORD=$PROTONVPN_PASSWORD
# Volume paths
DATA_DIR=$DATA_DIR
DOWNLOADS_DIR=$DOWNLOADS_DIR
MEDIA_TV_DIR=$MEDIA_TV_DIR
MEDIA_MOVIES_DIR=$MEDIA_MOVIES_DIR
# qBittorrent
QB_USERNAME=$QB_USERNAME
QB_PASSWORD=$QB_PASSWORD
BT_PORT=$BT_PORT
EOF
ok "Wrote $ENV_FILE"
# ── Symlinks ───────────────────────────────────────────────────────
for subdir in arr infra; do
target="$REPO_DIR/$subdir/.env"
if [ -L "$target" ]; then
skip "$subdir/.env already symlinked"
elif [ -f "$target" ]; then
warn "$subdir/.env exists as a regular file — remove it manually to use symlink"
else
ln -s ../.env "$target"
ok "Symlinked $subdir/.env → ../.env"
fi
done
# ── Docker network ─────────────────────────────────────────────────
if docker network inspect traefik_proxy &>/dev/null; then
skip "traefik_proxy network already exists"
else
gum spin \
--spinner dot \
--spinner.foreground "$ACCENT" \
--title "Creating traefik_proxy network..." -- \
docker network create traefik_proxy
ok "Created traefik_proxy network"
fi
# ── Start stack ────────────────────────────────────────────────────
echo ""
if gum confirm \
--prompt.foreground "$ACCENT" \
--selected.background "$ACCENT" \
"Start the stack now?"; then
gum spin \
--spinner dot \
--spinner.foreground "$ACCENT" \
--title "Starting Traefik..." -- \
docker compose -f "$REPO_DIR/infra/docker-compose.yml" up -d
ok "Traefik is up"
gum spin \
--spinner dot \
--spinner.foreground "$ACCENT" \
--title "Starting media pipeline (9 containers)..." -- \
docker compose -f "$REPO_DIR/arr/docker-compose.yml" up -d
ok "Media pipeline is up"
echo ""
gum style \
--border double --padding "1 3" --margin "0 2" \
--border-foreground "$OK" --foreground "$OK" --bold \
"All services running!" \
"" \
"$(gum style --faint --foreground "$MUTED" 'Check status:')" \
"$(gum style --foreground 7 ' docker compose -f arr/docker-compose.yml ps')"
else
echo ""
gum style \
--border double --padding "1 3" --margin "0 2" \
--border-foreground "$OK" --foreground "$OK" --bold \
"Setup complete!" \
"" \
"$(gum style --faint --foreground "$MUTED" 'Start the stack when ready:')" \
"$(gum style --foreground 7 ' docker compose -f infra/docker-compose.yml up -d')" \
"$(gum style --foreground 7 ' docker compose -f arr/docker-compose.yml up -d')"
fi
echo ""