#!/bin/bash
# instant-rsyncd lets you quickly set up and start a simple, unprivileged rsync
# daemon with a single module in the current directory. I've found it
# invaluable for quick testing, and I use it when writing a list of commands
# that people can paste into a terminal to reproduce a daemon-related bug.
# Sysadmins deploying an rsync daemon for the first time may find it helpful as
# a starting point.
#
# Usage: instant-rsyncd MODULE PORT RSYNCD-USERNAME [RSYNC-PATH]
# The script asks for the rsyncd user's password twice on stdin, once to set it
# and once to log in to test the daemon.
# -- Matt McCutchen
set -e
dir="$(pwd)"
if [ "$#" -lt 3 ]; then
echo "I would install an rsync daemon in $dir if you gave me"
echo "a module name, a port, and an rsync username."
exit 1
fi
module="$1"
port="$2"
user="$3"
rsync="$4"
if [ ! "$rsync" ]; then
rsync=rsync
fi
moduledir="${dir%/}/$module"
echo
echo "I'm about to install an rsync daemon in $dir."
echo "It will listen on port $port for requests giving rsync username $user"
echo "and the password you are about to specify. It will serve a module"
echo "$module corresponding to $moduledir."
echo
IFS='' read -s -p 'Desired password: ' password
mkdir "$module"
cat >rsyncd.conf <"$module".secrets <start <stop <