-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathentrypoint.sh
More file actions
65 lines (54 loc) · 1.77 KB
/
Copy pathentrypoint.sh
File metadata and controls
65 lines (54 loc) · 1.77 KB
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
#!/bin/bash -eu
set +H -euo pipefail
if [ "${PCLOUD_DEBUG:=0}" == "1" ]; then
echo "# Enabling debug output"
set -x
fi
PCLOUD_DRIVE_PATH="/pCloudDrive"
: ${PCLOUD_UID:=$(stat ${PCLOUD_DRIVE_PATH} -c '%u')}
: ${PCLOUD_GID:=$(stat ${PCLOUD_DRIVE_PATH} -c '%g')}
# Create new group using target GID
if ! pcloud_group="$(getent group "$PCLOUD_GID")"; then
pcloud_group='pcloud'
groupadd "${pcloud_group}" -g "$PCLOUD_GID"
else
pcloud_group=${pcloud_group%%:*}
fi
# Create new user using target UID
if ! pcloud_user="$(getent passwd "$PCLOUD_UID")"; then
pcloud_user='pcloud'
useradd -m "${pcloud_user}" -u "$PCLOUD_UID" -g "$PCLOUD_GID"
else
pcloud_user="${pcloud_user%%:*}"
usermod -g "${pcloud_group}" "${pcloud_user}"
grep -qv root <( groups "${pcloud_user}" ) || { echo 'ROOT level privileges prohibited!'; exit 1; }
fi
ARGS=(-m ${PCLOUD_DRIVE_PATH})
echo "Base Args: ${ARGS}"
if [ -n "${PCLOUD_SAVE_PASSWORD:=''}" ]; then
echo "# Adding -s to save password"
ARGS=(-s ${ARGS[@]})
fi
if [ -n "${PCLOUD_USERNAME:=''}" ]; then
ARGS=(-u ${PCLOUD_USERNAME} ${ARGS[@]})
fi
# Conditionally pass the password
# from a password file or stdin
# https://stackoverflow.com/a/1987599
password_file_stdin="/dev/stdin"
if [ -n "${PCLOUD_PASSWORD_FILE:=""}" ]; then
password_file_stdin="${PCLOUD_PASSWORD_FILE}"
ARGS=(-p ${ARGS[@]})
fi
echo "# Launching pcloud"
# Only switch user if not running as target uid (ie. Docker)
if [ "$PCLOUD_UID" = "$(id -u)" ]; then
set -x
/usr/bin/pcloudcc "${ARGS[@]}" < ${password_file_stdin}
else
mkdir -p ${PCLOUD_DRIVE_PATH}
chown "${pcloud_user}:${pcloud_group}" ${PCLOUD_DRIVE_PATH}
chown -R "${pcloud_user}:${pcloud_group}" /home/${pcloud_user}
set -x
exec gosu "${pcloud_user}" /usr/bin/pcloudcc "${ARGS[@]}" < ${password_file_stdin}
fi