Debian Codegraph @

support/instant-rsyncd

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