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>
20 echo "This will setup an rsync daemon in $dir"
23 IFS
='' read -p 'Module name to create (or return to exit): ' module
24 [ ! "$module" ] && exit
31 IFS
='' read -p 'Port number the daemon should listen on [873]: ' port
36 [ "$port" ] || port
=873
39 IFS
='' read -p 'User name for authentication (empty for none): ' user
46 IFS
='' read -s -p 'Desired password: ' password
51 [ "$rsync" ] || rsync
=rsync
53 moduledir
="${dir%/}/$module"
57 cat >rsyncd.conf
<<EOF
69 cat >>rsyncd.conf
<<-EOF
71 secrets file = $module.secrets
73 touch "$module".secrets
74 chmod go-rwx
"$module".secrets
75 echo "$user:$password" >"$module".secrets
83 ! [ -e rsyncd.pid ] || {
84 echo "Is the daemon already running? If not, delete rsyncd.pid."
87 $rsync --daemon --config=rsyncd.conf
95 ! [ -e rsyncd.pid ] || kill -s SIGTERM $(< rsyncd.pid)
99 path="rsync://$user$(hostname):$port/$module/"
104 echo "I ran the start command for the daemon. The log file rsyncd.log says:"
108 echo "You can start and stop it with ./start and ./stop respectively."
109 echo "You can customize the configuration file rsyncd.conf."
111 echo "Give rsync the following path to access the module:"
115 echo "Let's test the daemon now. Enter the password you chose at the prompt."
117 echo "Let's test the daemon now."
120 echo '$' $rsync --list-only "$path"
121 $rsync --list-only "$path"
123 echo "You should see an empty folder; it's $moduledir."
125 echo "Something went wrong. Do you see an error message?"