Done as a shell script. This could easily be better, but it works for now...