-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentrypoint.sh
64 lines (55 loc) · 1.95 KB
/
entrypoint.sh
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
#!/bin/sh
# Function to check if a group with the given GID exists and return its name
get_group_name_by_gid() {
getent group "$1" | cut -d: -f1
}
# Function to check if a user with the given UID exists and return its name
get_user_name_by_uid() {
getent passwd "$1" | cut -d: -f1
}
# Attempt to create the group if PGID is provided and does not already exist
if [ -n "$PGID" ]; then
GROUP_NAME=$(get_group_name_by_gid "$PGID")
if [ -z "$GROUP_NAME" ]; then
GROUP_NAME="shinkrogrp"
addgroup -g "$PGID" "$GROUP_NAME"
fi
else
GROUP_NAME="shinkrogrp"
# Optionally create a default group if PGID is not set
fi
# Attempt to create the user if PUID is provided and does not already exist
if [ -n "$PUID" ]; then
USER_NAME=$(get_user_name_by_uid "$PUID")
if [ -z "$USER_NAME" ]; then
USER_NAME="shinkrousr"
adduser -D -u "$PUID" -G "$GROUP_NAME" "$USER_NAME"
fi
else
USER_NAME="shinkrousr"
# Optionally create a default user if PUID is not set
fi
# Transform and export the ANIME_LIBRARIES environment variable
if [ -n "$ANIME_LIBRARIES" ]; then
ANIME_LIBRARIES=$(echo "$ANIME_LIBRARIES" | sed 's/,/","/g')
export ANIME_LIBRARIES="\"$ANIME_LIBRARIES\""
fi
# Generate and export the SHINKRO_APIKEY
SHINKRO_APIKEY=$(shinkro genkey)
export SHINKRO_APIKEY="$SHINKRO_APIKEY"
# Only generate config.toml from the template if it doesn't already exist
if [ ! -f /config/config.toml ]; then
if [ -n "$PUID" ] && [ -n "$PGID" ]; then
gosu "$USER_NAME" envsubst </app/config.toml.template >/config/config.toml
else
envsubst </app/config.toml.template >/config/config.toml
fi
fi
# Change ownership of /config, considering existing or newly created user/group
chown -R "$PUID":"$PGID" /config
# Execute the main process
if [ -n "$PUID" ] && [ -n "$PGID" ]; then
exec gosu "$USER_NAME" /usr/local/bin/shinkro --config /config "$@"
else
exec /usr/local/bin/shinkro --config /config "$@"
fi