Based on felclef's vagooze shell script.