#!/bin/sh # Dist v1.3.8 (c) 24.6.98 by Andreas Ley (u) 29.11.2011 # Distribute cluster and package configuration files usage() { echo "Usage: `basename $0` [-v|-q] [-s subset] [-u] [-c] [-C] [-n] [-d host] [filename [...]]" >&2 echo "-v verbose mode" >&2 echo "-q quiet mode" >&2 echo "-s select subset" >&2 echo "-u update only (skip files that are newer on the receiver)" >&2 echo "-c copy only, don't delete any remote files" >&2 echo "-C use checksums even when timestamps match" >&2 echo "-n dry run, show what would have been transferred" >&2 echo "-d destination host" >&2 echo "-a don't use include/exclude list (copy all, only with filename specified)" >&2 exit 1 } trace=false verbose=true unset subset delete='--delete' opt_v='' unset opts unset host include='yes' while getopts hxvqs:ucCnd:a OPTION; do case ${OPTION} in h) sed '1d;s/^# *//;/^$/q' $0; usage;; x) set -x; trace=true;; v) verbose=true; opt_v='-v';; q) verbose=false; opt_v='';; s) subset=".${OPTARG}";; u) opts="${opts} -u";; c) delete='';; C) opts="${opts} -c";; n) opt_v='-v'; opts="${opts} -n";; d) host="${OPTARG}";; a) unset include;; ?) usage;; esac done shift $(($OPTIND - 1)) if test -n "${subset}" -a ! -f /etc/cluster/files${subset}; then echo "No such subset: can't read /etc/cluster/files${subset}" >&2 exit 1 fi PATH=$PATH:/usr/machine/bin:/usr/machine/sbin localnode="`hostname`" localfqdn="`getfqdn`" ssh="/usr/bin/ssh -a -k -x" test -x /usr/bin/ssh || ssh="/usr/machine/bin/ssh1 -a -k -x" if test $# -eq 0; then test -n "${include}" || usage id=`id -u` if test ${id} -eq 0; then set -- `grep '^/' /etc/cluster/files${subset}` else set -- `for file in \`grep '^/' /etc/cluster/files${subset}\`; do uid=\`stat -u ${file} 2>/dev/null\`; test ${uid:-0} -eq ${id} && echo ${file}; done` fi if test $# -eq 0; then echo "There's nothing you can copy!" >&2 exit 1 fi else for file do case "${file}" in /*) :;; *) echo "Absolute path needed" >&2 exit 1;; esac done fi fping -a -r1 ${host} /dev/null | while read node; do if test "${node}" != "${localnode}" -a "${node}" != "test-${localnode}" -a "${node}" != "${localfqdn}"; then ${verbose} && echo "Copying to ${node}..." rsync ${opt_v} ${opts} -axRS --no-implied-dirs -e "${ssh}" ${delete} --exclude=lost+found --exclude=.Xauthority --exclude=.ssh/random_seed ${include:+--include-from=/etc/cluster/files${subset}} "$@" ${node}:/ | egrep -v '^building file list \.\.\. done$|/$|^wrote [0-9]* bytes read [0-9]* bytes [0-9.]* bytes/sec$|^total size is [0-9]* speedup is [0-9.]*$|^$' fi done exit 0