Skip to content

Commit 82240a6

Browse files
author
Jared Murrell
authored
added features and fixes
Added the following features: - detect large files exceeding MAX_FILE_SIZE (default=100MB) - exit script if files detected too large to migrate - exit script if authors file is missing Added the following fixes: - Fixed progress bar display - Fixed failed rev prompt loop
1 parent 67c9611 commit 82240a6

1 file changed

Lines changed: 92 additions & 33 deletions

File tree

_functions.sh

Lines changed: 92 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,32 @@ function _setup()
2525
export GITHUB_TOKEN # exporting so it's callable outside of this function
2626
echo ""
2727
done
28-
[[ ! -z ${AUTHORS_FILE} ]] && AUTHORS=" --authors-file=${AUTHORS_FILE}"
28+
[[ -z ${MAX_FILE_SIZE} ]] && MAX_FILE_SIZE=100
29+
if [[ ! -z ${AUTHORS_FILE} ]]
30+
then
31+
if [[ ! -f ${AUTHORS_FILE} ]]
32+
then
33+
echo "${AUTHORS_FILE} does not exist, but the AUTHORS_FILE variable is set"
34+
echo "Please ensure this file is created and contains a complete list of"
35+
echo "author information before continuing"
36+
exit 1
37+
else
38+
AUTHORS=" --authors-file=${AUTHORS_FILE}"
39+
fi
40+
fi
2941
github_machine=$(echo ${GITHUB_URL}|awk -F'//' {'print $2'})
30-
svn_machine=$(echo ${REPOSITORY}|awk -F'/' {'print $3'})
42+
svn_machine=$(echo ${REPOSITORY}|awk -F'/' {'print $3'}|awk -F':' {'print $1'})
3143
cat > ~/.netrc <<EOF
3244
machine ${github_machine}
33-
login token
34-
password ${GITHUB_TOKEN}
45+
login token
46+
password ${GITHUB_TOKEN}
3547
3648
machine ${svn_machine}
37-
login ${SVN_USERNAME}
38-
password ${SVN_PASSWORD}
49+
login ${SVN_USERNAME}
50+
password ${SVN_PASSWORD}
3951
EOF
4052
## Set our default SVN options
41-
SVN_OPTIONS="--trust-server-cert --non-interactive --no-auth-cache --username ${SVN_USERNAME} --password ${SVN_PASSWORD}"
53+
SVN_OPTIONS="--trust-server-cert --non-interactive --no-auth-cache"
4254
## Get the repo name and full URL for the remote subversion repository
4355
REPO_NAME=$(svn info ${REPOSITORY} ${SVN_OPTIONS}|grep '^Path'|awk {'print $2'}|sed 's/ /-/g')
4456
REPO_URL=$(svn info ${REPOSITORY} ${SVN_OPTIONS}|grep '^URL'|awk {'print $2'})
@@ -51,7 +63,46 @@ EOF
5163
function _svn_sizer()
5264
{
5365
_print_banner "Discovering repository size"
54-
svn list ${SVN_OPTIONS} -vR ${REPO_URL}|awk '{if ($3 !="") sum+=$3; i++} END {print "\nTotal Size: " sum/1024000" MB" "\nNumber of Files: " i/1000 " K"}'
66+
svn list ${SVN_OPTIONS} -vR ${REPO_URL}|grep -v '/$'|awk '
67+
{
68+
sum+=$3
69+
if (($3 + 1048575)/1048576 > '$MAX_FILE_SIZE')
70+
{
71+
print ($3 + 1048575)/1048575" MiB "$NF
72+
}
73+
i++
74+
} END {
75+
print "\nTotal Size: " (sum + 1048575)/1048576" MiB" "\nNumber of Files: " i/1000 " K"
76+
}' > /tmp/${REPO_NAME}-size.txt
77+
tail -n3 /tmp/${REPO_NAME}-size.txt
78+
if [[ "$(head -n1 /tmp/${REPO_NAME}-size.txt|awk {'print $2'})" = "MiB" ]]
79+
then
80+
_print_banner "The following files have been discovered to exceed" \
81+
"the maximum allowable filesize of the repository," \
82+
"which is currently set to ${MAX_FILE_SIZE}. Please" \
83+
"remove these files from the subversion repository, or" \
84+
"else increase the max file size (not recommended) and" \
85+
"then re-run the migration script." \
86+
" " \
87+
" For a complete list of files, refer to:" \
88+
"/tmp/${REPO_NAME}-size.txt"
89+
echo ""
90+
head -n -3 /tmp/${REPO_NAME}-size.txt
91+
exit 1
92+
else
93+
sleep 5
94+
fi
95+
}
96+
97+
# Convert bytes to human readable
98+
function _humanize_bytes()
99+
{
100+
local -i bytes=$1;
101+
if [[ ${bytes} -lt 1048576 ]]; then
102+
echo "$(( (bytes + 1023)/1024 )) KiB"
103+
else
104+
echo "$(( (bytes + 1048575)/1048576 )) MiB"
105+
fi
55106
}
56107

57108
## Format a banner
@@ -74,6 +125,7 @@ function _print_banner()
74125

75126
function _welcome()
76127
{
128+
clear
77129
_print_banner "Welcome to the Subversion to GitHub migrator" \
78130
"utility! This utility is intended for use by" \
79131
"experienced systems administrators, as there" \
@@ -148,7 +200,7 @@ function _discover_submodules()
148200
# Get the potential list of submodules, with branches, tags and trunk
149201
svn -R list ${REPO_URL} ${SVN_OPTIONS}|grep -E '(/trunk/$|/branches/$|/tags/$)' > /tmp/submodules.txt
150202
# Remove empty "trunk", "tags" and "branches" from the list of potentials
151-
for DIR in $(cat submodules.txt);
203+
for DIR in $(cat /tmp/submodules.txt);
152204
do
153205
FILES=$(svn list ${REPO_URL}/${DIR} ${SVN_OPTIONS})
154206
if [[ ${#FILES} -le 1 ]]
@@ -294,29 +346,30 @@ function _git_svn_clone()
294346
REV_COUNT=$(echo ${REV_LIST}|wc -w)
295347
REV_HEAD=$(echo ${REV_LIST}|awk {'print $NF'})
296348
## Setup the progress bar
297-
OLD_REV=0
349+
CURRENT_REV=0
298350
# Start Script
351+
clear
352+
HIDECURSOR
353+
echo -e "" && echo -e ""
354+
DRAW
355+
echo -e " CLONING ${REPO_NAME^^}"
356+
echo -e " lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk"
357+
echo -e " x x"
358+
echo -e " mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj"
359+
WRITE
299360
for REV in ${REV_LIST}
300361
do
301-
clear
302-
HIDECURSOR
303-
echo -e "" && echo -e ""
304-
DRAW
305-
echo -e " CLONING ${REPO_NAME^^}: REV ${REV}"
306-
echo -e " lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk"
307-
echo -e " x x"
308-
echo -e " mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj"
309-
WRITE
310-
## Fill in the gaps of the progress bar
311-
if [[ $((${REV} - ${OLD_REV} )) -gt 1 ]]
312-
then
313-
while [[ ${OLD_REV} -lt ${REV} ]]
314-
do
315-
showBar ${OLD_REV} ${REV_HEAD}
316-
((OLD_REV++))
317-
done
318-
fi
319-
showBar ${REV} ${REV_HEAD}
362+
#[[ ${CURRENT_REV} -le 5 ]] && clear
363+
#HIDECURSOR
364+
#echo -e "" && echo -e ""
365+
#DRAW
366+
#echo -e " CLONING ${REPO_NAME^^}"
367+
#echo -e " lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk"
368+
#echo -e " x x"
369+
#echo -e " mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj"
370+
#WRITE
371+
showBar ${CURRENT_REV} ${REV_COUNT}
372+
echo -e "" && echo -e " REV: ${REV}"
320373
git svn fetch -qr${REV} ${AUTHORS} &>> ${LOG_FILE} > /dev/null
321374
RESULT=$?
322375
while [[ ${RESULT} -ne 0 ]]
@@ -334,21 +387,27 @@ function _git_svn_clone()
334387
RESULT=0
335388
else
336389
clear
337-
echo "Retrying revision ${REV}..."
338390
HIDECURSOR
339391
echo -e "" && echo -e ""
340392
DRAW
341-
echo -e " CLONING ${REPO_NAME^^}: REV ${REV}"
393+
echo -e " CLONING ${REPO_NAME^^}"
342394
echo -e " lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk"
343395
echo -e " x x"
344396
echo -e " mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj"
345397
WRITE
346-
showBar ${REV} ${REV_HEAD}
398+
OLD_REV=0
399+
while [[ ${OLD_REV} -lt ${CURRENT_REV} ]]
400+
do
401+
showBar ${OLD_REV} ${REV_COUNT}
402+
((OLD_REV++))
403+
done
404+
showBar ${CURRENT_REV} ${REV_COUNT}
405+
echo -e "" && echo -e " REV: ${REV}"
347406
git svn fetch -qr${REV} ${AUTHORS} &>> ${LOG_FILE} > /dev/null
348407
RESULT=$?
349408
fi
350409
done
351-
OLD_REV=${REV}
410+
((CURRENT_REV++))
352411
done
353412
PUT 10 12
354413
echo -e ""

0 commit comments

Comments
 (0)