#!/usr/bin/env bash # TBD: # - merge into send-master script and use a variable to control push vs pull. ## Variables ## PROG="$(basename -- "${BASH_SOURCE[0]}")" loop=false DIR="`pwd`" dir="`basename $DIR`" ## Validations ## if [[ "$DIR" != *"-clone" || "$DIR" != *"-SYNC" ]]; then echo "'$DIR' is not labeled as a CLONE or SYNC. Skipping download." exit 0 fi # Only pull the existing subdirectories rather than ALL content. subdirs_only="false" if [[ "$dir" == "music-clone" ]]; then subdirs_only="true" fi ## Main ## echo "`date` - Pulling" \ "'$PROD_DATA_USER@$PROD_DATA_HOST:$PROD_DATA_PORT$PROD_DATA_DIR/$dir'" \ "to '$dir'." sleep=0 while true; do if (( $sleep > 0 )); then echo "Sleeping for '$sleep' seconds..." sleep $sleep fi if [[ "$subdirs_only" == "true" ]]; then ls $DIR | while read subdir; do echo -e "\n`date` - Working subdirectory '$subdir'..." clone -e "ssh -p $PROD_DATA_PORT" \ $PROD_DATA_USER@$PROD_DATA_HOST:$PROD_DATA_DIR/$dir/$subdir/ \ ./$subdir && echo "`date` - Success!" || echo "`date` - Failed!" done else clone -e "ssh -p $PROD_DATA_PORT" \ $PROD_DATA_USER@$PROD_DATA_HOST:$PROD_DATA_DIR/$dir/ \ . && echo "`date` - Success!" || echo "`date` - Failed!" fi sleep=30 if [[ "$loop" == false ]]; then break; fi done ## Complete ## echo -e "\n`date` - $PROG complete." exit 0