Man page: Move the description of --info=progress2 to a better place.
[rsync/rsync.git] / support / instant-rsyncd
... / ...
CommitLineData
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
19echo
20echo "This will setup an rsync daemon in $dir"
21
22if [ $# = 0 ]; then
23 IFS='' read -p 'Module name to create (or return to exit): ' module
24 [ ! "$module" ] && exit
25else
26 module="$1"
27 shift
28fi
29
30if [ $# = 0 ]; then
31 IFS='' read -p 'Port number the daemon should listen on [873]: ' port
32else
33 port="$1"
34 shift
35fi
36[ "$port" ] || port=873
37
38if [ $# = 0 ]; then
39 IFS='' read -p 'User name for authentication (empty for none): ' user
40else
41 user="$1"
42 shift
43fi
44
45if [ "$user" ]; then
46 IFS='' read -s -p 'Desired password: ' password
47 echo
48fi
49
50rsync="$1"
51[ "$rsync" ] || rsync=rsync
52
53moduledir="${dir%/}/$module"
54
55mkdir "$module"
56
57cat >rsyncd.conf <<EOF
58log file = rsyncd.log
59pid file = rsyncd.pid
60port = $port
61use chroot = no
62
63[$module]
64 path = $module
65 read only = false
66EOF
67
68if [ "$user" ]; then
69 cat >>rsyncd.conf <<-EOF
70 auth users = $user
71 secrets file = $module.secrets
72 EOF
73 touch "$module".secrets
74 chmod go-rwx "$module".secrets
75 echo "$user:$password" >"$module".secrets
76 user="$user@"
77fi
78
79cat >start <<EOF
80#!/bin/bash
81set -e
82cd \`dirname \$0\`
83! [ -e rsyncd.pid ] || {
84 echo "Is the daemon already running? If not, delete rsyncd.pid."
85 exit 1
86}
87$rsync --daemon --config=rsyncd.conf
88EOF
89chmod +x start
90
91cat >stop <<"EOF"
92#!/bin/bash
93set -e
94cd `dirname $0`
95! [ -e rsyncd.pid ] || kill -s SIGTERM $(< rsyncd.pid)
96EOF
97chmod +x stop
98
99path="rsync://$user$(hostname):$port/$module/"
100
101if ./start; then
102 sleep .2
103 echo
104 echo "I ran the start command for the daemon. The log file rsyncd.log says:"
105 echo
106 cat rsyncd.log
107 echo
108 echo "You can start and stop it with ./start and ./stop respectively."
109 echo "You can customize the configuration file rsyncd.conf."
110 echo
111 echo "Give rsync the following path to access the module:"
112 echo " $path"
113 echo
114 if [ "$user" ]; then
115 echo "Let's test the daemon now. Enter the password you chose at the prompt."
116 else
117 echo "Let's test the daemon now."
118 fi
119 echo
120 echo '$' $rsync --list-only "$path"
121 $rsync --list-only "$path"
122 echo
123 echo "You should see an empty folder; it's $moduledir."
124else
125 echo "Something went wrong. Do you see an error message?"
126fi