forked from axiom-data-science/rsync-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
66 lines (56 loc) · 1.37 KB
/
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
61
62
63
64
65
66
#!/bin/bash
set -e
USERNAME=${USERNAME:-user}
PASSWORD=${PASSWORD:-pass}
ALLOW=${ALLOW:-192.168.8.0/24 192.168.24.0/24 172.16.0.0/12 127.0.0.1/32}
VOLUME=${VOLUME:-/data}
setup_sshd(){
# ensure .ssh dir exists for root user
if ! [ -e "/root/.ssh"] ; then
mkdir -p /root/.ssh
chown root:root /root/.ssh
fi
# add authorized keys if defined
if ! [ -z "${AUTHORIZED_KEYS}"] ; then
echo ${AUTHORIZED_KEYS} > /root/.ssh/authorized_keys
fi
# ensure correct permission of the file
if [ -e "/root/.ssh/authorized_keys" ]; then
chmod 400 /root/.ssh/authorized_keys
chown root:root /root/.ssh/authorized_keys
fi
chmod 750 /root/.ssh
echo "root:$PASSWORD" | chpasswd
}
setup_rsyncd(){
echo "$USERNAME:$PASSWORD" > /etc/rsyncd.secrets
chmod 0400 /etc/rsyncd.secrets
[ -f /etc/rsyncd.conf ] || cat > /etc/rsyncd.conf <<EOF
pid file = /var/run/rsyncd.pid
log file = /dev/stdout
timeout = 300
max connections = 10
port = 873
[volume]
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
}
if [ "$1" = 'rsync_server' ]; then
setup_sshd
exec /usr/sbin/sshd &
mkdir -p $VOLUME
setup_rsyncd
exec /usr/bin/rsync --no-detach --daemon --config /etc/rsyncd.conf "$@"
else
setup_sshd
exec /usr/sbin/sshd &
fi
exec "$@"