Subversion Progressbar in bash

For a project i am doing i needed to checkout a subversion repo from within an installer. This ofcourse is not that hard, but i wanted something extra.
I was searching for a way to show a progressbar when doing a svn checkout (svn co) and could not find a sollution for it. So i came up with the following sollution.

First, i needed to know how many files i was going to checkout of the subversion repository. To get this number i’m going to use the following bash statement.

n=$(svn info -R svn://svn/project/trunk | grep "URL: " | uniq | wc -l)

Great, ‘$n’ now contains a number of files in my project, we can use that number to calculate the percentage. But to do that i needed to know how far the checkout is.

Subversion will output each file on a new line. We could pipe that into a while loop and keep track of the progress.

n=$(svn info -R svn://svn/project/trunk | grep "URL: " | uniq | wc -l)
i=1
while read line filename
    do
    counter=$(( 100*(++i)/n))
    echo -e "($counter %)\n"
    echo -e "filename: $filename \n"
done < <(svn co svn://svn/project/trunk /var/www/project)

The script above prints a percentage for each line.

Now let’s put all this into a dialog.

dialog --backtitle "Subversion Installer" --title "SVN Checkout" --gauge "Getting total file count" 7 120 < <(
	n=$(svn info -R svn://svn/project/trunk | grep "URL: " | uniq | wc -l)
	i=1
	while read line filename
		do
		counter=$(( 100*(++i)/n))
		echo "XXX"
		echo "$counter"
		echo "filename: $filename"
		echo "XXX"

	done < <(svn co svn://svn/project/trunk /var/www/project)
)

if you run this you’ll get a nice process indicator. Yay!