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>
18 echo "This will setup an rsync daemon in $dir"
21 IFS='' read -p 'Module name to create (or return to exit): ' module
22 [ ! "$module" ] && exit
29 IFS='' read -p 'Port number the daemon should listen on [873]: ' port
34 [ "$port" ] || port=873
37 IFS='' read -p 'User name for authentication (empty for none): ' user
44 IFS='' read -s -p 'Desired password: ' password
49 [ "$rsync" ] || rsync=rsync
51 moduledir="${dir%/}/$module"
55 cat >rsyncd.conf <<EOF
67 cat >>rsyncd.conf <<-EOF
69 secrets file = $module.secrets
71 touch "$module".secrets
72 chmod go-rwx "$module".secrets
73 echo "$user:$password" >"$module".secrets
81 ! [ -e rsyncd.pid ] || {
82 echo "Is the daemon already running? If not, delete rsyncd.pid."
85 $rsync --daemon --config=rsyncd.conf
93 ! [ -e rsyncd.pid ] || kill -s SIGTERM $(< rsyncd.pid)
97 path="rsync://$user$(hostname):$port/$module/"
102 echo "I ran the start command for the daemon. The log file rsyncd.log says:"
106 echo "You can start and stop it with ./start and ./stop respectively."
107 echo "You can customize the configuration file rsyncd.conf."
109 echo "Give rsync the following path to access the module:"
113 echo "Let's test the daemon now. Enter the password you chose at the prompt."
115 echo "Let's test the daemon now."
118 echo '$' $rsync --list-only "$path"
119 $rsync --list-only "$path"
121 echo "You should see an empty folder; it's $moduledir."
123 echo "Something went wrong. Do you see an error message?"