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"
29 COMPONENTLIST=/etc/static-components.conf
32 echo "local Usage: $0 <host>"
33 echo "via ssh orig command:"
35 echo " static-master-update-component <component>"
39 if [ "$#" -lt 1 ]; then
46 logger -p daemon.info -t "$MYLOGNAME" "$1"
50 logger -s -p daemon.warn -t "$MYLOGNAME" "$1"
56 local path="$1"; shift
57 local exclusive="$1"; shift
59 eval "exec $fd< '$path'"
61 if [ "$exclusive" -gt 0 ]; then
67 if ! flock "$locktype" "$fd"; then
68 echo >&2 "$0: Cannot acquire lock on $base (flock $locktype failed) - Very bad, we should have waited!"
74 local remote_host="$1"; shift
75 local path="$1"; shift
77 local sender='rsync --server --sender -vlogDtprze.iLsf . '
79 if [ -e "$path" ]; then
80 info "serving $remote_host with $path"
83 info "$remote_host wants non-existing $path"
84 echo >&2 "$path does not exist."
90 local remote_host="$1"; shift
92 if [ "$*" = "--server --sender -vlogDtprze.iLsf . -new-/" ] ; then
93 serve_dir "$remote_host" "$BASEDIR/current-push"
94 elif [ "$*" = "--server --sender -vlogDtprze.iLsf . -live-/" ] ; then
95 local p="$BASEDIR/current-live"
96 info "host $remote_host wants $p, acquiring lock"
98 serve_dir "$remote_host" "$p"
100 info "NOT allowed for $remote_host: rsync $*"
101 echo >&2 "This rsync command ($@) not allowed."
106 do_update_component() {
107 local remote_host="$1"; shift
113 hit="$(awk -v component="$component" -v host="$remote_host" '$1 == component && $2 == host {print $3; exit}' "$COMPONENTLIST")"
114 if [ -n "$hit" ]; then
115 exec static-master-update-component "$component"
116 echo >&2 "Exec failed"
119 info "Not whitelisted: $remote_host update $component"
120 echo >&2 "Not whitelisted: $remote_host update $component"
126 if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
136 # check/parse remote command line
137 if [ -z "${SSH_ORIGINAL_COMMAND:-}" ] ; then
138 croak "Did not find SSH_ORIGINAL_COMMAND"
140 set "dummy" ${SSH_ORIGINAL_COMMAND}
143 info "host $remote_host called with $*"
151 do_rsync "$remote_host" "$@"
153 static-master-update-component)
154 do_update_component "$remote_host" "$@"
157 croak "Invalid operation '$action'"