Skip to content

Instantly share code, notes, and snippets.

@jhcarr
Created November 8, 2016 23:54
Show Gist options
  • Save jhcarr/1096c78491dab860de06614a197024d8 to your computer and use it in GitHub Desktop.
Save jhcarr/1096c78491dab860de06614a197024d8 to your computer and use it in GitHub Desktop.
A half-baked solution to SVN server timeouts
#! /bin/bash
### SVN CHECKOUT HAMMER
### Justin Carr : 11/8/2016
### A half-baked solution to SVN server timeouts.
## Globals
hammer="";
url="";
cleanTarget="";
messages=(
"DROPPING THE HAMMER"
"Aligning square peg with round hole ..."
"More like Source Out-Of-Control, amirite? ... guys? ... where are you going?"
"Preparing to loop Jeopardy theme ..."
"Spam target sighted and locked ..."
"This is the script that never ends. / Yes it goes on and on my friends."
"What hath science wrought?"
)
## Function Definitions
function attemptCheckout(){
echo "";
svn checkout $url;
R=$?;
if [ $R == 0 ]; then
echo "SVN checkout succeeded.";
echo "Exiting ...";
exit 0;
else
# If there was a timeout/etc, clean up the mess
echo "";
echo "SVN checkout failed.";
echo "Cleaning ...";
svn cleanup $cleanTarget;
# Invite the user to retry (unless in hammer mode)
if [[ "y" == $hammer || "Y" == $hammer ]]; then
echo "";
stupidStatusMessage;
attemptCheckout;
else
echo "";
echo "Retry checkout? (y/n)";
read retry;
if [[ "y" == $retry || "Y" == $retry ]]; then
attemptCheckout;
fi
fi
exit 1;
fi
}
function stupidStatusMessage(){
length=${#messages[@]};
index=$(($RANDOM % $length));
chosen=${messages[$index]};
echo $chosen;
}
## Main
echo "";
echo "*** SVN CHECKOUT HAMMER ***";
# Prompt for SVN target, use url to create local cleanup target
echo "";
echo "Where would you like to checkout from? (enter SVN server URL)";
read url;
cleanTarget=${url##*/svn/};
cleanTarget=${cleanTarget%/};
# Prompt for hammer mode
echo "";
echo "Would you like to hammer SVN until checkout succeeds? (y/n/a)";
read hammer;
if [[ "a" == $hammer || "A" == $hammer ]]; then
echo "";
echo "Aborting ...";
exit 0;
elif [[ "y" == $hammer || "Y" == $hammer ]]; then
echo "";
stupidStatusMessage;
fi
attemptCheckout;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment