fixed shell bugs and integrated script into XCode build phase (tested, all works fine)