diff options
author | Stephen Cprek <smcprek@us.ibm.com> | 2015-04-08 15:00:32 -0500 |
---|---|---|
committer | A. Patrick Williams III <iawillia@us.ibm.com> | 2015-06-18 13:52:04 -0500 |
commit | 33c6264cbb812221b1247692b67fb770d3b5e43f (patch) | |
tree | be3aeaaa2efbe637d4e2466bc0e4c8a9def373f8 /src/build/tools | |
parent | b4a41f74b3b0082c846d7fa0ecf3be77f7ac62c4 (diff) | |
download | talos-hostboot-33c6264cbb812221b1247692b67fb770d3b5e43f.tar.gz talos-hostboot-33c6264cbb812221b1247692b67fb770d3b5e43f.zip |
Add some safety measures to the hb rsync command
Confirm if rsync dir is empty or looks like a
hostboot repository, otherwise prompt the user if
the location specified is what they want
Also added the --force option to skip over this check
can be used for cronjobs
Change-Id: I06d5488d4e4fca6a91a25a650e4e042b7f70e7ee
Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/16955
Tested-by: Jenkins Server
Reviewed-by: Brian H. Horton <brianh@linux.ibm.com>
Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/build/tools')
-rwxr-xr-x | src/build/tools/hb | 66 |
1 files changed, 61 insertions, 5 deletions
diff --git a/src/build/tools/hb b/src/build/tools/hb index 3856388a0..19625142f 100755 --- a/src/build/tools/hb +++ b/src/build/tools/hb @@ -153,13 +153,16 @@ hb_helptext() echo " Topic 'rsync'" echo echo " Usage:" - echo " hb rsync" + echo " hb rsync <opts>" echo echo " Synchronizes an entire Hostboot repository with another" echo " directory. This can be useful for creating a backup of" echo " the repository or for pushing it to a remote host, such" echo " as a pool machine where simics is executed." echo + echo " Options:" + echo " --force : Skip user prompt for RSYNCDIR confirmation (reserve for cronjobs)." + echo echo " Environment Variables:" echo " RSYNCHOST: (optional) remote host to rsync to." echo " RSYNCDIR: Destination directory of the rsync." @@ -392,11 +395,8 @@ hb_startsimics() "start_simics -machine ${MACHINE} ${SIMICSOPTIONS} $*" "ppc" } -hb_rsync() +hb_rsync_call() { - [ -z "${HOSTBOOTROOT}" ] && echo "Missing HOSTBOOTROOT." && exit -1 - [ -z "${RSYNCDIR}" ] && echo "Missing RSYNCDIR." && exit -1 - if [ -z "${RSYNCHOST}" ]; then rsync -av --delete ${HOSTBOOTROOT}/ ${RSYNCDIR} else @@ -404,6 +404,62 @@ hb_rsync() fi } +hb_rsync_helper() +{ + if [ -n "${RSYNCHOST}" ]; then + echo -n "${RSYNCHOST}:" + fi + echo "${RSYNCDIR} does not look like a hostboot repo and is not empty" + read -r -p "rsync will clear out ${RSYNCDIR} then copy files into it, is this correct? [y/N] " response + case $response in + [yY][eE][sS]|[yY]) + hb_rsync_call + ;; + *) + echo "hb rsync cancelled" + ;; + esac +} + +hb_rsync() +{ + [ -z "${HOSTBOOTROOT}" ] && echo "Missing HOSTBOOTROOT." && exit -1 + [ -z "${RSYNCDIR}" ] && echo "Missing RSYNCDIR." && exit -1 + + # Parse arguments + case $1 in + "--force") + hb_rsync_call + ;; + *) + # Check destination directory, if not empty check if looks like + # a hostboot repository, otherwise proceed + # If remote directory + if [ -n "${RSYNCHOST}" ]; then + if [ "$(ssh ${RSYNCHOST} 'if [ "$(ls -A '${RSYNCDIR}')" ]; then echo 1; fi')" ]; then + # Remote check for hb and .git + if [ "$(ssh ${RSYNCHOST} 'if [ -f '${RSYNCDIR}/hb' -a -d '${RSYNCDIR}/.git' ]; then echo 1; fi')" ]; then + hb_rsync_call; + else + hb_rsync_helper; + fi + else + hb_rsync_call; + fi + # Local check for emptiness + elif [ "$(ls -A ${RSYNCDIR})" ]; then + # Local check for hb and .git + if [ -f ${RSYNCDIR}/hb -a -d ${RSYNCDIR}/.git ]; then + hb_rsync_call; + else + hb_rsync_helper; + fi + else + hb_rsync_call; + fi + esac +} + hb_objsizes() { [ -z "${HOSTBOOTROOT}" ] && echo "Missing HOSTBOOTROOT." && exit -1 |