-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathentrypoint.sh
executable file
·89 lines (79 loc) · 2.46 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
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
#!/bin/bash
check_config_permissions () {
# Check permissions
find /.airdcpp -print0 |
while IFS= read -r -d '' item
do
if [[ ! (-r "$item" && -w "$item") ]]
then
echo "Can't read/write configuration."
echo "Make sure that UID $(id -u) can read/write the"
echo "configuraton directory and all files therin."
exit 1
fi
done
}
init_config () {
# If configuration doesn't exist, create defaults
[[ -r /.airdcpp/DCPlusPlus.xml ]] || cp /.default-config/DCPlusPlus.xml /.airdcpp/
[[ -r /.airdcpp/web-server.json ]] || cp /.default-config/web-server.json /.airdcpp/
[[ -r /.airdcpp/web-users.json ]] || cp /.default-config/web-users.json /.airdcpp/
}
validate_id () {
# Check PUID/PGID values
if [[ -z "${PUID}" || -z "${PGID}" ]]
then
echo "PUID and PGID variables must be set when container is run as root."
exit 1
fi
if [[ "${PUID}" -lt 101 || "${PGID}" -lt 101 ]]
then
echo "PUID must be >= 101 and PGID must be >= 101 due to existing IDs in the image."
echo "If you need to use a lower ID, start container with --user <uid>:<gid> instead."
exit 1
fi
}
create_user_and_group () {
# Create airdcpp user and group if needed
if [[ "$(id -u airdcpp &>/dev/null)" != "${PUID}" || "$(id -g airdcpp)" != "${PGID}" ]]
then
groupdel airdcpp &>/dev/null
userdel airdcpp &>/dev/null
groupadd -f -g ${PGID} airdcpp || exit 1
useradd -u ${PUID} -g ${PGID} --no-create-home -s /usr/sbin/nologin airdcpp || exit 1
fi
}
take_ownership () {
# Set ownership of config files and make all files writable
chown -R ${PUID}:${PGID} /.airdcpp
chmod -R u+rw /.airdcpp
}
if [[ ! -z "$LOG_STARTUP" ]]
then
set -x
fi
if [[ ! -z "$UMASK" ]]
then
if [[ ! "$UMASK" =~ ^0?[0-7]{1,3}$ ]]
then
echo "The umask value $UMASK is not valid. It must be an octal number such as 0022 (or 22 without leading 0)"
exit 1
fi
umask $UMASK
fi
if [[ "$container" == "podman" ]] || [[ "$(id -u)" -ne 0 ]]
then
# Container is run as a normal user or with podman
check_config_permissions
init_config
# Start airdcppd
exec /airdcpp-webclient/airdcppd "$@"
else
# Container is run as root
validate_id
create_user_and_group
take_ownership
init_config
# Start airdcppd
exec runuser -u airdcpp -g airdcpp -- /airdcpp-webclient/airdcppd "$@"
fi