forked from apnar/docker-image-rsync-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
69 lines (53 loc) · 1.59 KB
/
Copy pathentrypoint.sh
File metadata and controls
69 lines (53 loc) · 1.59 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
66
67
68
69
#!/bin/bash
set -e
if [ ! -z "${WAIT_INT}" ]; then
/usr/bin/pipework --wait -i ${WAIT_INT}
fi
USERNAME=${USERNAME:-rsync}
PASSWORD=${PASSWORD:-rsync}
SSHPORT=${SSHPORT:-22}
ALLOW=${ALLOW:-192.168.0.0/16 172.16.0.0/12 10.0.0.0/24 127.0.0.1/32}
VOLUME=${VOLUME:-/data}
# Delete old PID file on reboot
rm -f /var/run/rsyncd.pid
# Clear old allowances
cat /dev/null > /etc/hosts.allow
# Set Allowed hosts and ports for SSH as well
ALLOWEDHOSTS=( $ALLOW )
for h in "${ALLOWEDHOSTS[@]}"
do
echo "sshd : $h : allow" >> /etc/hosts.allow
done
echo "sshd : ALL : deny" >> /etc/hosts.allow
# Restarts not needed. Started later on this script anyway
sed -i "s/.*Port 22.*/Port $SSHPORT/g" /etc/ssh/sshd_config
if [ "$1" = 'rsync_server' ]; then
if [ -e "/root/.ssh/authorized_keys" ]; then
chmod 400 /root/.ssh/authorized_keys
chown root:root /root/.ssh/authorized_keys
fi
exec /usr/sbin/sshd &
echo "root:$PASSWORD" | chpasswd
echo "$USERNAME:$PASSWORD" > /etc/rsyncd.secrets
chmod 0400 /etc/rsyncd.secrets
mkdir -p $VOLUME
[ -f /etc/rsyncd.conf ] || cat <<EOF > /etc/rsyncd.conf
pid file = /var/run/rsyncd.pid
log file = /var/log/rsync.log
timeout = 300
max connections = 10
port = 873
[data]
uid = root
gid = root
hosts deny = *
hosts allow = ${ALLOW}
read only = false
path = ${VOLUME}
comment = ${VOLUME} directory
auth users = ${USERNAME}
secrets file = /etc/rsyncd.secrets
EOF
exec /usr/bin/rsync --no-detach --daemon --config /etc/rsyncd.conf "$@"
fi
exec "$@"