summaryrefslogtreecommitdiffstats
path: root/start-rsyncd.sh
blob: 3fa22ee5832c9811152a934a2b6ab64652ab5736 (plain)
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
#!/bin/bash

set -e

while :; do
	port=$RANDOM
	[[ $port -gt 1024 && $port -lt 65535 ]] && break
done

tmpdir=$(mktemp -d /tmp/start-rsyncd.sh.XXXXXX)

cleanup() {
	rm -rf "$tmpdir"
}

trap cleanup EXIT INT TERM

cat <<EOF >"$tmpdir/rsyncd.conf"
max connections = 1
pid file = $tmpdir/pid
lock file = $tmpdir/lock
use chroot = no
log file = /dev/stderr
read only = true
port = $port
uid = $USER
[share]
  path = $PWD
EOF

echo "use: rsync -rtP --port $port \"rsync://$(hostname -f)/share/\" \"share-copy/\""
echo "stating rsyncd..."
rsync --daemon --no-detach --config="$tmpdir/rsyncd.conf"