forked from sirjmann92/nicotineplus-proper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·83 lines (69 loc) · 2.29 KB
/
init.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
#!/bin/bash
# Logging function to echo output with a timestamp
log() {
echo "[$(date '+%m/%d/%y %H:%M:%S')] $1"
}
# Update NGINX configuration with the desired port
if [ "$WEB_UI_PORT" != "6565" ]; then
log "Updating NGINX configuration to use port $WEB_UI_PORT..."
fi
sed -i "s/__PORT__/$WEB_UI_PORT/g" /etc/nginx/sites-available/default
# Start NGINX server
log "Starting NGINX server..."
nginx > >(while IFS= read -r line; do log "$line"; done) 2>&1 &
# Output current nicotine user UID/GID for awareness
log "The current nicotine UID/GID is:"
log "$(id nicotine)"
# Define and change UID/GID, and WebUI port
PUID=${PUID:-1000}
PGID=${PGID:-1000}
WEB_UI_PORT=${WEB_UI_PORT:-6565}
changed=false
if [ "$PUID" != "1000" ]; then
log "Changing nicotine user UID to $PUID"
usermod -o -u "$PUID" nicotine
changed=true
fi
if [ "$PGID" != "1000" ]; then
log "Changing nicotine user GID to $PGID"
groupmod -o -g "$PGID" nicotine
changed=true
fi
if [ "$changed" = true ]; then
log "The nicotine user UID/GID has been changed to:"
log "$(id nicotine)"
fi
# Set the timezone if TZ is provided
if [ -n "${TZ}" ]; then
if [ -f "/usr/share/zoneinfo/${TZ}" ]; then
ln -sf "/usr/share/zoneinfo/${TZ}" /etc/localtime
echo "${TZ}" > /etc/timezone
log "Timezone set to ${TZ}"
log "Current time: $(date)"
else
log "Invalid timezone: ${TZ}. Falling back to UTC."
ln -sf "/usr/share/zoneinfo/UTC" /etc/localtime
echo "UTC" > /etc/timezone
fi
else
log "Time zone not set, using default (UTC)"
log "Current time: $(date)"
fi
if [ -n "${LANG}" ]; then
# Add locale to system config
echo "${LANG} UTF-8" >> /etc/locale.gen
# Run locale-gen and log the output
if locale-gen "${LANG}" > /tmp/locale_gen_output.log 2>&1; then
# Update environment with locale
echo "LANG=${LANG}" > /etc/locale.conf
echo -e "LANG=${LANG}\nLC_ALL=${LANG}\nLANGUAGE=${LANG}" > /etc/environment
else
log "Failed to generate locale for ${LANG}"
fi
# Log the output
while IFS= read -r line; do log "$line"; done < /tmp/locale_gen_output.log
else
log "Locale not specified, using default (C.UTF-8)"
fi
# Run Nicotine+ launch script as nicotine user
exec su -c "/usr/local/bin/launch.sh" nicotine