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"`[$$]"
28 BASEDIR="/home/staticsync/static-master"
31 echo "local Usage: $0 <host>"
32 echo "via ssh orig command:"
34 echo " static-master-update-component <component>"
38 if [ "$#" -lt 1 ]; then
45 logger -p daemon.info -t "$MYLOGNAME" "$1"
49 logger -s -p daemon.warn -t "$MYLOGNAME" "$1"
55 local path="$1"; shift
56 local exclusive="$1"; shift
58 eval "exec $fd< '$path'"
60 if [ "$exclusive" -gt 0 ]; then
66 if ! flock "$locktype" "$fd"; then
67 echo >&2 "$0: Cannot acquire lock on $base (flock $locktype failed) - Very bad, we should have waited!"
73 local remote_host="$1"; shift
74 local path="$1"; shift
76 local sender='rsync --server --sender -vlogDtprze.iLsf . '
78 if [ -e "$path" ]; then
79 info "serving $remote_host with $path"
82 info "$remote_host wants non-existing $path"
83 echo >&2 "$path does not exist."
89 local remote_host="$1"; shift
91 if [ "$*" = "--server --sender -vlogDtprze.iLsf . -new-/" ] ; then
92 serve_dir "$remote_host" "$BASEDIR/current-push"
93 elif [ "$*" = "--server --sender -vlogDtprze.iLsf . -live-/" ] ; then
94 local p="$BASEDIR/current-live"
95 info "host $remote_host wants $p, acquiring lock"
97 serve_dir "$remote_host" "$p"
99 info "NOT allowed for $remote_host: rsync $*"
100 echo >&2 "This rsync command ($@) not allowed."
105 do_update_component() {
106 local remote_host="$1"; shift
112 #if [ "$component" = "www.torproject.org" ] && [ "$remote_host" = "vescum.torproject.org" ]; then
113 # exec static-master-update-component "$component"
114 # echo >&2 "Exec failed"
115 # croak "exec failed"
117 info "Not whitelisted: $remote_host update $component"
118 echo >&2 "Not whitelisted: $remote_host update $component"
124 if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
134 # check/parse remote command line
135 if [ -z "${SSH_ORIGINAL_COMMAND:-}" ] ; then
136 croak "Did not find SSH_ORIGINAL_COMMAND"
138 set "dummy" ${SSH_ORIGINAL_COMMAND}
141 info "host $remote_host called with $*"
149 do_rsync "$remote_host" "$@"
151 static-master-update-component)
152 do_update_component "$remote_host" "$@"
155 croak "Invalid operation '$action'"