Add instant-rsyncd to support/ .
[rsync/rsync.git] / support / instant-rsyncd
CommitLineData
45574a73
MM
1#!/bin/bash
2
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
8# a starting point.
9#
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>
14
15set -e
16
17dir="$(pwd)"
18
19if [ "$#" -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."
22 exit 1
23fi
24
25module="$1"
26port="$2"
27user="$3"
28rsync="$4"
29if [ ! "$rsync" ]; then
30 rsync=rsync
31fi
32
33moduledir="${dir%/}/$module"
34
35echo
36echo "I'm about to install an rsync daemon in $dir."
37echo "It will listen on port $port for requests giving rsync username $user"
38echo "and the password you are about to specify. It will serve a module"
39echo "$module corresponding to $moduledir."
40echo
41
42IFS='' read -s -p 'Desired password: ' password
43
44mkdir "$module"
45
46cat >rsyncd.conf <<EOF
47log file = rsyncd.log
48pid file = rsyncd.pid
49port = $port
50use chroot = no
51
52[$module]
53 path = $module
54 read only = false
55 auth users = $user
56 secrets file = $module.secrets
57EOF
58
59touch "$module".secrets
60chmod go-rwx "$module".secrets
61cat >"$module".secrets <<EOF
62$user:$password
63EOF
64
65cat >start <<EOF
66#!/bin/bash
67set -e
68cd \`dirname \$0\`
69! [ -e rsyncd.pid ] || {
70 echo "Is the daemon already running? If not, delete rsyncd.pid."
71 exit 1
72}
73$rsync --daemon --config=rsyncd.conf
74EOF
75chmod +x start
76
77cat >stop <<"EOF"
78#!/bin/bash
79set -e
80cd `dirname $0`
81! [ -e rsyncd.pid ] || kill -s SIGTERM $(< rsyncd.pid)
82EOF
83chmod +x stop
84
85path="rsync://$user@$(hostname):$port/$module/"
86
87if ./start; then
88 sleep .2
89 echo
90 echo "I tried to start the daemon. The log file rsyncd.log says:"
91 echo
92 cat rsyncd.log
93 echo
94 echo "You can start and stop it with ./start and ./stop respectively."
95 echo "You can customize the configuration file rsyncd.conf."
96 echo
97 echo "Give rsync the following path to access the module:"
98 echo " $path"
99 echo
100 echo "Let's test the daemon now. Enter the password you chose."
101 echo '$' $rsync --list-only "$path"
102 $rsync --list-only "$path"
103 echo
104 echo "You should see an empty folder; it's $moduledir."
105else
106 echo "Something went wrong. Do you see an error message?"
107fi