Kyson posted the shell script for that in another thread here:
You will probably have to modify it though.