Created
April 5, 2018 15:19
Checkout a team's projects in SVN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
REPO_BASE="https://svn.repo/department/team" | |
LOCAL_BASE="${HOME}/svn" | |
backoff() { | |
local count iteration timeout output ret | |
timeout=1 | |
count=5 | |
iteration=0 | |
output="$(${@} 2>&1)" | |
ret=$? | |
while [[ $ret -ne 0 && $iteration -lt $count ]] | |
do | |
sleep ${timeout} | |
timeout=$((timeout * 2)) | |
iteration=$((iteration + 1)) | |
output="$(${@} 2>&1)" | |
ret=$? | |
done | |
if [ -n "${output}" ] | |
then | |
echo "${output}" | |
fi | |
return $ret | |
} | |
is_stdlayout() { | |
output=$(backoff svn ls "${1}") | |
if [[ $? -ne 0 ]] | |
then | |
return 2 | |
elif [[ $(grep "^\(branches\|tags\|trunk\)/\?$" <<< "${output}" | wc -l) -gt 0 ]] | |
then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
repo_list=$(backoff svn ls "${REPO_BASE}") | |
if [ $? -ne 0 ] | |
then | |
echo "Unable to list ${REPO_BASE}" | |
exit 1 | |
fi | |
while read repo; | |
do | |
SVNFLAGS="--quiet --ignore-externals" | |
REMOTE_REPO="${REPO_BASE}/${repo%%/}" | |
LOCAL_REPO="${LOCAL_BASE}/${repo%%/}" | |
if [[ -d "${LOCAL_REPO}" ]] | |
then | |
continue | |
fi | |
echo "${REMOTE_REPO} -> ${LOCAL_REPO}" | |
if is_stdlayout "${REMOTE_REPO}" | |
then | |
REMOTE_REPO="${REMOTE_REPO}/trunk" | |
fi | |
backoff svn checkout ${SVNFLAGS} "${REMOTE_REPO}" "${LOCAL_REPO}" | |
if [ $? -ne 0 ] | |
then | |
echo "${REMOTE_REPO}" >> failed.txt | |
echo "Failed to checkout ${REMOTE_REPO}" | |
echo -n "${output}" | |
fi | |
done <<< "${repo_list}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment