forked from bt-sync/sync-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_sync
executable file
·35 lines (27 loc) · 912 Bytes
/
run_sync
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
#!/bin/bash -eu
set +H -xeuo pipefail
: ${RSYNC_UID:=$(stat /mnt/sync/data -c '%u')}
: ${RSYNC_GID:=$(stat /mnt/sync/data -c '%g')}
# Create new group using target GID
if ! odgroup="$(getent group "$RSYNC_GID")"; then
odgroup='run_sync'
groupadd "${odgroup}" -g "$RSYNC_GID"
else
odgroup=${odgroup%%:*}
fi
# Create new user using target UID
if ! oduser="$(getent passwd "$RSYNC_UID")"; then
oduser='run_sync'
useradd -m "${oduser}" -u "$RSYNC_UID" -g "$RSYNC_GID"
else
oduser="${oduser%%:*}"
usermod -g "${odgroup}" "${oduser}"
grep -qv root <( groups "${oduser}" ) || { echo 'ROOT level privileges prohibited!'; exit 1; }
fi
chown -R "${oduser}:${odgroup}" /mnt/sync
mkdir -p /mnt/sync/folders
mkdir -p /mnt/sync/config
if ! [ -f /mnt/sync/sync.conf ]; then
cp /etc/sync.conf.default /mnt/sync/sync.conf;
fi
HOME=/mnt/sync/folders exec gosu "${oduser}" /usr/bin/rslsync --nodaemon $*