-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·46 lines (35 loc) · 1.24 KB
/
Copy pathentrypoint.sh
File metadata and controls
executable file
·46 lines (35 loc) · 1.24 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
#!/bin/sh
set -e
# PUID / PGID remapping
# Unraid convention: let users set PUID/PGID to match host filesystem
# ownership. The image creates huntarr2 with UID/GID 1000; if the
# requested IDs differ, remap them before anything else.
PUID="${PUID:-1000}"
PGID="${PGID:-1000}"
CURRENT_UID=$(id -u huntarr2)
CURRENT_GID=$(getent group huntarr2 | cut -d: -f3)
if [ "$PGID" != "$CURRENT_GID" ]; then
groupmod -o -g "$PGID" huntarr2
fi
if [ "$PUID" != "$CURRENT_UID" ]; then
usermod -o -u "$PUID" huntarr2
fi
# Encryption key auto-generation
# If ENCRYPTION_KEY is not set, try to read a previously generated key
# from persistent storage. If no stored key exists, generate one and
# write it to /config so it survives container recreation.
KEY_FILE="/config/encryption.key"
if [ -z "$ENCRYPTION_KEY" ]; then
if [ -f "$KEY_FILE" ]; then
ENCRYPTION_KEY=$(cat "$KEY_FILE")
else
ENCRYPTION_KEY=$(head -c 32 /dev/urandom | od -A n -t x1 | tr -d ' \n')
printf '%s' "$ENCRYPTION_KEY" > "$KEY_FILE"
chmod 600 "$KEY_FILE"
echo "Generated new encryption key at $KEY_FILE"
fi
export ENCRYPTION_KEY
fi
# Fix ownership and drop privileges
chown -R huntarr2:huntarr2 /config
exec su-exec huntarr2 /bin/huntarr2