forked from mickaelperrin/docker-rsync-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
executable file
·62 lines (50 loc) · 1.54 KB
/
docker-entrypoint.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
#!/bin/bash
set -e
# Allow to run complementary processes or to enter the container without
# running this init script.
if [ "$1" == '/usr/bin/rsync' ]; then
# Ensure time is in sync with host
# see https://wiki.alpinelinux.org/wiki/Setting_the_timezone
if [ -n ${TZ} ] && [ -f /usr/share/zoneinfo/${TZ} ]; then
ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime
echo ${TZ} > /etc/timezone
fi
# Defaults
VOLUME_PATH=${VOLUME_PATH:-/docker}
HOSTS_ALLOW=${HOSTS_ALLOW:-0.0.0.0/0}
READ_ONLY=${READ_ONLY:-false}
CHROOT=${CHROOT:-no}
VOLUME_NAME=${VOLUME_NAME:-volume}
USERNAME=${USERNAME:-rsyncuser}
# Ensure VOLUME PATH exists
if [ ! -e $VOLUME_PATH ]; then
mkdir -p /$VOLUME_PATH
fi
# Grab UID of owner of the volume directory
if [ -z $OWNER_ID ]; then
OWNER_ID=$(stat -c '%u' $VOLUME_PATH)
else
echo "OWNER_ID is set forced to: $OWNER_ID"
fi
if [ -z $GROUP_ID ]; then
GROUP_ID=$(stat -c '%g' $VOLUME_PATH)
else
echo "GROUP_ID is set forced to: $GROUP_ID"
fi
# Generate password file
if [ ! -z $PASSWORD ]; then
echo "$USERNAME:$PASSWORD" > /etc/rsyncd.secrets
chmod 600 /etc/rsyncd.secrets
fi
# Generate configuration
eval "echo \"$(cat /rsyncd.tpl.conf)\"" > /etc/rsyncd.conf
# Check if a script is available in /docker-entrypoint.d and source it
# You can use it for example to create additional sftp users
for f in /docker-entrypoint.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*) echo "$0: ignoring $f" ;;
esac
done
fi
exec "$@"