Stole stuff from bashstrap and some other things.