forked from torrust/torrust-index-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentry_script_sh
42 lines (33 loc) · 1.25 KB
/
entry_script_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
#!/bin/sh
set -x
to_lc() { echo "$1" | tr '[:upper:]' '[:lower:]'; }
clean() { echo "$1" | tr -d -c 'a-zA-Z0-9-' ; }
cmp_lc() { [ "$(to_lc "$(clean "$1")")" = "$(to_lc "$(clean "$2")")" ]; }
# Add torrust user, based upon supplied user-id.
if [ -z "$USER_ID" ] && [ "$USER_ID" -lt 1000 ]; then
echo "ERROR: USER_ID is not set, or less than 1000"
exit 1
fi
adduser --disabled-password --shell "/bin/sh" --uid "$USER_ID" "torrust"
# Configure Permissions for Torrust Folders
chown -R "${USER_ID}" /var/log/torrust
chmod -R 2770 /var/log/torrust
# Make Minimal Message of the Day
if cmp_lc "$RUNTIME" "runtime"; then
printf '\n in runtime \n' >> /etc/motd;
elif cmp_lc "$RUNTIME" "debug"; then
printf '\n in debug mode \n' >> /etc/motd;
elif cmp_lc "$RUNTIME" "release"; then
printf '\n in release mode \n' >> /etc/motd;
else
echo "ERROR: running in unknown mode: \"$RUNTIME\""; exit 1
fi
if [ -e "/usr/share/torrust/container/message" ]; then
cat "/usr/share/torrust/container/message" >> /etc/motd; chmod 0644 /etc/motd
fi
# Load message of the day from Profile
# shellcheck disable=SC2016
echo '[ ! -z "$TERM" -a -r /etc/motd ] && cat /etc/motd' >> /etc/profile
cd /home/torrust || exit 1
# Switch to torrust user
exec /bin/su-exec torrust "$@"