-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·59 lines (54 loc) · 2.06 KB
/
Copy pathbootstrap.sh
File metadata and controls
executable file
·59 lines (54 loc) · 2.06 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
#!/bin/bash
# bootstrap.sh – prepare local OrbVis setup before `docker compose up`.
#
# - Generates a .env file with a fresh random SECRET_KEY if none exists yet.
# - Creates data/boards and data/icons so docker compose's bind-mount targets
# exist and aren't auto-created by the docker daemon (which would chown them
# to root).
#
# Safe to run repeatedly; existing files/dirs are left untouched.
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
ENV_FILE=".env"
if [[ ! -f "$ENV_FILE" ]]; then
if command -v openssl >/dev/null 2>&1; then
SECRET_KEY="$(openssl rand -hex 32)"
elif command -v python3 >/dev/null 2>&1; then
SECRET_KEY="$(python3 -c 'import secrets; print(secrets.token_hex(32))')"
else
echo "Error: need either openssl or python3 to generate SECRET_KEY." >&2
exit 1
fi
cat > "$ENV_FILE" <<EOF
# Auto-generated by bootstrap.sh — keep this file private (.gitignore'd).
# Re-run bootstrap.sh after deleting this file to mint a new SECRET_KEY.
SECRET_KEY=$SECRET_KEY
# HOST_UID/HOST_GID let the docker container write to bind-mounted host dirs
# (data/boards, data/icons) without root-owned permission errors.
HOST_UID=$(id -u)
HOST_GID=$(id -g)
EOF
chmod 600 "$ENV_FILE"
echo "Wrote $ENV_FILE with a fresh SECRET_KEY."
else
echo ".env already exists — leaving SECRET_KEY untouched."
if ! grep -q '^HOST_UID=' "$ENV_FILE"; then
cat >> "$ENV_FILE" <<EOF
HOST_UID=$(id -u)
HOST_GID=$(id -g)
EOF
echo "Appended HOST_UID/HOST_GID to existing .env."
fi
fi
# Bind-mount targets must exist on the host before `docker compose up` so the
# daemon doesn't auto-create them as root.
if ! mkdir -p data/boards data/icons data/db 2>/dev/null; then
echo "Error: cannot create data/{boards,icons,db}." >&2
if [[ -d data && ! -w data ]]; then
echo " data/ exists but is not writable by $USER." >&2
echo " Likely a leftover from a previous docker run that created it as root." >&2
echo " Fix: sudo chown -R \$USER:\$USER data/ (or: sudo rm -rf data/ if empty)" >&2
fi
exit 1
fi
echo "Ensured data/{boards,icons,db} exist."