Index: rsync-files.sh =================================================================== --- rsync-files.sh (revision 12146) +++ rsync-files.sh (working copy) @@ -1,29 +1,48 @@ -#!/bin/bash -x +#!/bin/bash -e -function usage -{ - echo "ERROR: $*" - echo "usage: $0 " +# Synchronizes the network /build/share => /local/build/share +# +# NOTE: the source MUST be mounted on /build, or rsync will throw errors related to broken links +# +# So, we need to fiddle with the local directories in order to get this to work. +# +# We assume that /build is a symlink to /local/build -- if so, we unlink it before mounting and then +# relink it afterwards. +# +# For now, not bothering with permissions, so script must be run as root + +[[ $# -gt 0 ]] || { echo "Usage: $0 filename"; exit 1; } +[[ -f $1 ]] || { echo "$1 is not a file"; exit 1; } +DIR_LIST=$1 + +#LOCAL_BUILD="/shared/build" # Bill's machine +LOCAL_BUILD=/local/build # convention going forward + +# check that link points where we think it should +if [[ ! "$(readlink -fn /build)" -ef "${LOCAL_BUILD}" ]]; then + echo "/build doesnt point to ${LOCAL_BUILD}!" exit 1 -} +fi -[[ $# -gt 2 ]] || usage -[[ -d $1 ]] || usage "$1 is not a directory" -[[ -f $3 ]] || usage "$3 is not a file" +# mount remote as /build +rm -f /build # remove the link +mkdir /build # create directory to mount over +mount -r 172.26.90.61:/vol/vol1/build /build # mount netapp as /build +#mount -o ro,noload 172.26.90.61:/vol/vol1/build /build # mount netapp as /build -SRC_PATH=$1 -TGT_PATH=$2 -DIR_LIST=$3 - +# process the file for dir in $(egrep -v '^#|^\s*$' "${DIR_LIST}"); do - if [[ -d "${SRC_PATH}/${dir}" ]]; then + if [[ -d "/build/share/${dir}" ]]; then # if source is a directory, simply copy it recursively - mkdir -p "${TGT_PATH}/${dir}" - rsync -azh --delete "${SRC_PATH}/${dir}/" "${TGT_PATH}/${dir}/" - elif [[ -L "${SRC_PATH}/${dir}" ]]; then - # if the source is a symlink, the symlink must be transferred - link_target=$(dirname "${dir}") - mkdir -p "${TGT_PATH}/${link_target}" - rsync -a "${SRC_PATH}/${dir}" "${TGT_PATH}/${link_target}" + mkdir -p "${LOCAL_BUILD}/share/${dir}" || true + echo "Copying ${dir} ..." + rsync -azh --delete "/build/share/${dir}/" "${LOCAL_BUILD}/share/${dir}/" + else + echo "Cant find ${dir} on source ..." fi done + +# put the link back +umount -f /build +rmdir /build +ln -s ${LOCAL_BUILD} /build