Kpm pack generate bash scripts

parent #327 
Yeah, it does make the code cleaner. Added in the latest commit. Also rebased.