MYLOGNAME="`basename "$0"`[$$]"
BASEDIR="/home/staticsync/static-master"
+COMPONENTLIST=/etc/static-components.conf
usage() {
echo "local Usage: $0 <host>"
fi
}
-serve_dir() {
- local remote_host="$1"; shift
- local path="$1"; shift
-
- local sender='rsync --server --sender -vlogDtprze.iLsf . '
-
- if [ -e "$path" ]; then
- info "serving $remote_host with $path"
- $sender "$path/"
- else
- info "$remote_host wants non-existing $path"
- echo >&2 "$path does not exist."
- exit 1
- fi
-}
-
do_rsync() {
local remote_host="$1"; shift
-
- if [ "$*" = "--server --sender -vlogDtprze.iLsf . -new-/" ] ; then
- serve_dir "$remote_host" "$BASEDIR/current-push"
- elif [ "$*" = "--server --sender -vlogDtprze.iLsf . -live-/" ] ; then
- local p="$BASEDIR/current-live"
- info "host $remote_host wants $p, acquiring lock"
- lock 200 "$p" 0
- serve_dir "$remote_host" "$p"
- else
- info "NOT allowed for $remote_host: rsync $*"
- echo >&2 "This rsync command ($@) not allowed."
- exit 1
- fi
+ local args="--server --sender -vlHtrze.iLsf --safe-links ."
+
+ 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/$component-current-push"
+ info "serving $remote_host with $path"
+ rsync $args "$path/."
+ return
+ elif [ "$*" = "$args . $component/-live-/" ] || [ "$*" = "$args . ./$component/-live-/" ] ; then
+ local path="$BASEDIR/$component-current-live"
+ info "host $remote_host wants $path, acquiring lock"
+ lock 200 "$path" 0
+ 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
- #if [ "$component" = "www.torproject.org" ] && [ "$remote_host" = "vescum.torproject.org" ]; then
- # exec static-master-update-component "$component"
- # echo >&2 "Exec failed"
- # croak "exec failed"
- #else
+ 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"
+ croak "exec failed"
+ else
info "Not whitelisted: $remote_host update $component"
echo >&2 "Not whitelisted: $remote_host update $component"
exit 1
- #fi
+ fi
}