3 # instant-rsyncd lets you quickly set up and start a simple, unprivileged rsync
4 # daemon with a single module in the current directory. I've found it
5 # invaluable for quick testing, and I use it when writing a list of commands
6 # that people can paste into a terminal to reproduce a daemon-related bug.
7 # Sysadmins deploying an rsync daemon for the first time may find it helpful as
10 # Usage: instant-rsyncd MODULE PORT RSYNCD-USERNAME [RSYNC-PATH]
11 # The script asks for the rsyncd user's password twice on stdin, once to set it
12 # and once to log in to test the daemon.
13 # -- Matt McCutchen <matt@mattmccutchen.net>
19 if [ "$#" -lt 3 ]; then
20 echo "I would install an rsync daemon in $dir if you gave me"
21 echo "a module name, a port, and an rsync username."
29 if [ ! "$rsync" ]; then
33 moduledir="${dir%/}/$module"
36 echo "I'm about to install an rsync daemon in $dir."
37 echo "It will listen on port $port for requests giving rsync username $user"
38 echo "and the password you are about to specify. It will serve a module"
39 echo "$module corresponding to $moduledir."
42 IFS='' read -s -p 'Desired password: ' password
46 cat >rsyncd.conf <<EOF
56 secrets file = $module.secrets
59 touch "$module".secrets
60 chmod go-rwx "$module".secrets
61 cat >"$module".secrets <<EOF
69 ! [ -e rsyncd.pid ] || {
70 echo "Is the daemon already running? If not, delete rsyncd.pid."
73 $rsync --daemon --config=rsyncd.conf
81 ! [ -e rsyncd.pid ] || kill -s SIGTERM $(< rsyncd.pid)
85 path="rsync://$user@$(hostname):$port/$module/"
90 echo "I tried to start the daemon. The log file rsyncd.log says:"
94 echo "You can start and stop it with ./start and ./stop respectively."
95 echo "You can customize the configuration file rsyncd.conf."
97 echo "Give rsync the following path to access the module:"
100 echo "Let's test the daemon now. Enter the password you chose."
101 echo '$' $rsync --list-only "$path"
102 $rsync --list-only "$path"
104 echo "You should see an empty folder; it's $moduledir."
106 echo "Something went wrong. Do you see an error message?"