-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathentry_script_sh
82 lines (60 loc) · 2.77 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
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
#!/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")")" ]; }
inst() {
if [ -n "$1" ] && [ -n "$2" ] && [ -e "$1" ] && [ ! -e "$2" ]; then
install -D -m 0640 -o torrust -g torrust "$1" "$2"; fi; }
# 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
mkdir -p /var/lib/torrust/tracker/database/ /etc/torrust/tracker/
chown -R "${USER_ID}":"${USER_ID}" /var/lib/torrust /var/log/torrust /etc/torrust
chmod -R 2770 /var/lib/torrust /var/log/torrust /etc/torrust
# Install the database and config:
if [ -n "$TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER" ]; then
if cmp_lc "$TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER" "sqlite3"; then
# Select Sqlite3 empty database
default_database="/usr/share/torrust/default/database/tracker.sqlite3.db"
# Select Sqlite3 default configuration
default_config="/usr/share/torrust/default/config/tracker.container.sqlite3.toml"
elif cmp_lc "$TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER" "mysql"; then
# (no database file needed for MySQL)
# Select default MySQL configuration
default_config="/usr/share/torrust/default/config/tracker.container.mysql.toml"
else
echo "Error: Unsupported Database Type: \"$TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER\"."
echo "Please Note: Supported Database Types: \"sqlite3\", \"mysql\"."
exit 1
fi
else
echo "Error: \"\$TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER\" was not set!"; exit 1;
fi
install_config="/etc/torrust/tracker/tracker.toml"
install_database="/var/lib/torrust/tracker/database/sqlite3.db"
inst "$default_config" "$install_config"
inst "$default_database" "$install_database"
# 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 "$@"