3 # Copyright (c) 2009, 2010, 2012 Peter Palfrader
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 MYLOGNAME="`basename "$0"`[$$]"
30 echo "local Usage: $0 <basedir> <host>"
31 echo "via ssh orig command:"
32 echo " mirror <serial>"
36 if [ "$#" -lt 1 ]; then
43 logger -p daemon.info -t "$MYLOGNAME" "$1"
47 logger -s -p daemon.warn -t "$MYLOGNAME" "$1"
52 local basedir="$1"; shift
53 local remote_host="$1"; shift
55 local serial="$1"; shift
57 info "Host $remote_host triggered a mirror run for serial $serial"
58 exec /usr/local/bin/static-mirror-run "$basedir" "$remote_host:-new-" "$serial"
59 echo >&2 "Exec failed"
64 local remote_host="$1"
73 # '^--server --sender -tre\.iLsf \. /srv/www-master\.torproject\.org/htdocs/\.$'
78 for cmd_idx in ${!allowed_rsyncs[*]}; do
79 allowed="${allowed_rsyncs[$cmd_idx]}"
80 if [[ "$*" =~ $allowed ]]; then # do !not! quote regex
81 info "Running for host $remote_host: rsync $*"
83 echo >&2 "Exec failed"
88 info "NOT allowed for $remote_host: rsync $*"
89 echo >&2 "This rsync command ($*) not allowed."
94 if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
108 # check/parse remote command line
109 if [ -z "${SSH_ORIGINAL_COMMAND:-}" ] ; then
110 croak "Did not find SSH_ORIGINAL_COMMAND"
112 set "dummy" ${SSH_ORIGINAL_COMMAND}
121 do_mirror "$basedir" "$remote_host" "$@"
124 do_rsync "$remote_host" "$@"
127 croak "Invalid operation '$action'"