Skip to content

Commit b178f94

Browse files
authored
Merge pull request bcardiff#10 from mikeburgh/master
Assign UID and GID
2 parents d8d7a55 + ad02bcf commit b178f94

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ ENV FORCE_SYNC=
2222
ENV CHECK_URL=
2323
ENV FAIL_URL=
2424
ENV TZ=
25+
ENV UID=
26+
ENV GID=
2527

2628
RUN apk --no-cache add ca-certificates fuse wget dcron tzdata
2729

entrypoint.sh

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,42 @@ then
1919
exit 1
2020
fi
2121

22+
# Make sure UID and GID are both supplied
23+
if [ -z "$GID" -a ! -z "$UID" ] || [ -z "$UID" -a ! -z "$GID" ]
24+
then
25+
echo "WARNING: Must supply both UID and GID or neither. Stopping."
26+
exit 1
27+
fi
28+
29+
# Process UID and GID
30+
if [ ! -z "$GID" ]
31+
then
32+
33+
#Get group name or add it
34+
GROUP=$(getent group "$GID" | cut -d: -f1)
35+
if [ -z "$GROUP" ]
36+
then
37+
GROUP=rclone
38+
addgroup --gid "$GID" "$GROUP"
39+
fi
40+
41+
#get user or add it
42+
USER=$(getent passwd "$UID" | cut -d: -f1)
43+
if [ -z "$USER" ]
44+
then
45+
USER=rclone
46+
adduser \
47+
--disabled-password \
48+
--gecos "" \
49+
--no-create-home \
50+
--ingroup "$GROUP" \
51+
--uid "$UID" \
52+
"$USER" >/dev/null
53+
fi
54+
else
55+
USER=$(whoami)
56+
fi
57+
2258
# Re-write cron shortcut
2359
case "$(echo "$CRON" | tr '[:lower:]' '[:upper:]')" in
2460
*@YEARLY* ) echo "INFO: Cron shortcut $CRON re-written to 0 0 1 1 *" && CRONS="0 0 1 1 *";;
@@ -45,7 +81,7 @@ rm -f /tmp/sync.pid
4581
if [ -z "$SYNC_SRC" ] || [ -z "$SYNC_DEST" ]
4682
then
4783
echo "INFO: No SYNC_SRC and SYNC_DEST found. Starting rclone config"
48-
rclone config $RCLONE_OPTS
84+
su "$USER" -c "rclone config $RCLONE_OPTS"
4985
echo "INFO: Define SYNC_SRC and SYNC_DEST to start sync process."
5086
else
5187
# SYNC_SRC and SYNC_DEST setup
@@ -61,13 +97,13 @@ else
6197
then
6298
echo "INFO: No CRON setting found. Running sync once."
6399
echo "INFO: Add CRON=\"0 0 * * *\" to perform sync every midnight"
64-
/sync.sh
100+
su "$USER" -c /sync.sh
65101
else
66102
if [ -z "$FORCE_SYNC" ]
67103
then
68104
echo "INFO: Add FORCE_SYNC=1 to perform a sync upon boot"
69105
else
70-
/sync.sh
106+
su "$USER" -c /sync.sh
71107
fi
72108

73109
if [ ! -z "$SYNC_ONCE" ]
@@ -78,7 +114,7 @@ else
78114

79115
# Setup cron schedule
80116
crontab -d
81-
echo "$CRONS /sync.sh >>/tmp/sync.log 2>&1" > /tmp/crontab.tmp
117+
echo "$CRONS su $USER -c /sync.sh >>/tmp/sync.log 2>&1" > /tmp/crontab.tmp
82118
if [ -z "$CRON_ABORT" ]
83119
then
84120
echo "INFO: Add CRON_ABORT=\"0 6 * * *\" to cancel outstanding sync at 6am"

0 commit comments

Comments
 (0)