exit 1
}
-lock() {
- local fd="$1"; shift
- local path="$1"; shift
- local exclusive="$1"; shift
-
- eval "exec $fd< '$path'"
-
- if [ "$exclusive" -gt 0 ]; then
- locktype="-e"
- else
- locktype="-s"
- fi
-
- if ! flock "$locktype" "$fd"; then
- echo >&2 "$0: Cannot acquire lock on $base (flock $locktype failed) - Very bad, we should have waited!"
- exit 1
- fi
-}
-
do_rsync() {
local remote_host="$1"; shift
-
local args="--server --sender -vlHtrze.iLsf --safe-links ."
- if [ "$*" = "$args -new-/" ] || [ "$*" = "$args ./-new-/" ] ; then
- local path="$BASEDIR/current-push"
- info "serving $remote_host with $path"
- rsync $args "$path/."
- elif [ "$*" = "$args . -live-/" ] || [ "$*" = "$args . ./-live-/" ] ; then
- local path="$BASEDIR/current-live"
- info "host $remote_host wants $path, acquiring lock"
- lock 200 "$path" 0
- rsync $args "$path/."
- else
- info "NOT allowed for $remote_host: rsync $*"
- echo >&2 "This rsync command ($@) not allowed."
- exit 1
- fi
+
+ for component in $(awk -v this_host="$(hostname -f)" '$1 == this_host {print $2}' $COMPONENTLIST); do
+ if [ "$*" = "$args $component/-new-/" ] || [ "$*" = "$args ./$component/-new-/" ] ; then
+ local path="$BASEDIR/master/$component-current-push"
+ info "serving $remote_host with $path"
+ rsync $args "$path/."
+ return
+ elif [ "$*" = "$args $component/-live-/" ] || [ "$*" = "$args ./$component/-live-/" ] ; then
+ local path="$BASEDIR/master/$component-current-live"
+ info "host $remote_host wants $path, acquiring lock"
+ exec 200< "$path"
+ if ! flock -s -w 0 200; then
+ echo >&2 "Cannot acquire shared lock on $path - this should mean an update is already underway anyway."
+ exit 1
+ fi
+ rsync $args "$path/."
+ return
+ fi
+ done
+
+ info "NOT allowed for $remote_host: rsync $*"
+ echo >&2 "This rsync command ($@) not allowed."
+ exit 1
}
do_update_component() {
component="$1"
shift
- hit="$(awk -v component="$component" -v host="$remote_host" '$1 == component && $2 == host {print $3; exit}' "$COMPONENTLIST")"
+ hit="$(
+ awk -v this_host="$(hostname -f)" -v component="$component" -v host="$remote_host" '
+ $1 == this_host && $2 == component {
+ if ($3 == host) {
+ print $4
+ exit
+ }
+ split($5,extra,",")
+ for (i in extra) {
+ if (host == extra[i]) {
+ printf "%s:%s\n", $3, $4
+ exit
+ }
+ }
+ exit
+ }' "$COMPONENTLIST"
+ )"
if [ -n "$hit" ]; then
exec static-master-update-component "$component"
echo >&2 "Exec failed"