Files
env-shared/bin-shared/pull_clone.sh

66 lines
1.4 KiB
Bash
Executable File

#!/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" ]]; then
echo "'$DIR' is not labeled as a clone. 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
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 "`date` - $PROG complete."
exit 0