Move shell logic into perl script

Move the chdist commands and other stuff in the shell script into
the Perl script.  Delete the shell script, and call the perlscript
directly from debian/rules