make it work with repoman/vmstore. cleaned-up and robustified bash routines.