-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathuserSetup.sh
86 lines (68 loc) · 2.78 KB
/
userSetup.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
#!/bin/bash
# More/less taken from https://github.com/linuxserver/docker-baseimage-alpine/blob/3eb7146a55b7bff547905e0d3f71a26036448ae6/root/etc/cont-init.d/10-adduser
source /etc/openvpn/utils.sh
RUN_AS=root
if [ -n "$PUID" ] && [ ! "$(id -u root)" -eq "$PUID" ]; then
RUN_AS=abc
if [ ! "$(id -u ${RUN_AS})" -eq "$PUID" ]; then
usermod -o -u "$PUID" ${RUN_AS};
fi
if [ -n "$PGID" ] && [ ! "$(id -g ${RUN_AS})" -eq "$PGID" ]; then
groupmod -o -g "$PGID" ${RUN_AS};
fi
if [[ "true" = "$LOG_TO_STDOUT" ]]; then
chown ${RUN_AS}:${RUN_AS} /dev/stdout
fi
# Make sure directories exist before chown and chmod
mkdir -p /config \
"${TRANSMISSION_HOME}" \
"${TRANSMISSION_DOWNLOAD_DIR}" \
"${TRANSMISSION_INCOMPLETE_DIR}" \
"${TRANSMISSION_WATCH_DIR}"
echo "Enforcing ownership on transmission directories"
chown -R ${RUN_AS}:${RUN_AS} \
/config \
"${TRANSMISSION_HOME}"
echo "Applying permissions to transmission directories"
chmod -R go=rX,u=rwX \
/config \
"${TRANSMISSION_HOME}"
if [ "$GLOBAL_APPLY_PERMISSIONS" = true ] ; then
echo "Setting owner for transmission paths to ${PUID}:${PGID}"
chown -R ${RUN_AS}:${RUN_AS} \
"${TRANSMISSION_DOWNLOAD_DIR}" \
"${TRANSMISSION_INCOMPLETE_DIR}" \
"${TRANSMISSION_WATCH_DIR}"
echo "Setting permissions for download and incomplete directories"
if [ -z "$TRANSMISSION_UMASK" ] ; then
# fetch from settings.json if not defined in environment
# because updateSettings.py is called after this script is run
TRANSMISSION_UMASK=$(jq .umask ${TRANSMISSION_HOME}/settings.json | tr -d \" )
fi
TRANSMISSION_UMASK_OCTAL=$( printf "%o\n" "${TRANSMISSION_UMASK}" )
DIR_PERMS=$( printf '%o\n' $(( 8#777 & ~TRANSMISSION_UMASK)) )
FILE_PERMS=$( printf '%o\n' $(( 8#666 & ~TRANSMISSION_UMASK)) )
echo "umask: ${TRANSMISSION_UMASK_OCTAL}"
echo "Directories: ${DIR_PERMS}"
echo "Files: ${FILE_PERMS}"
find "${TRANSMISSION_DOWNLOAD_DIR}" "${TRANSMISSION_INCOMPLETE_DIR}" -type d \
-exec chmod "${DIR_PERMS}" {} +
find "${TRANSMISSION_DOWNLOAD_DIR}" "${TRANSMISSION_INCOMPLETE_DIR}" -type f \
-exec chmod "${FILE_PERMS}" {} +
echo "Setting permission for watch directory (775) and its files (664)"
chmod -R o=rX,ug=rwX \
"${TRANSMISSION_WATCH_DIR}"
fi
fi
echo "
-------------------------------------
Transmission will run as
-------------------------------------
User name: ${RUN_AS}
User uid: $(id -u ${RUN_AS})
User gid: $(id -g ${RUN_AS})
-------------------------------------
"
export PUID
export PGID
export RUN_AS