Search code examples
macosbashcommand-line-interfaceprovisioning-profile

Script to copy and rename file fails on Mac OS X


I followed this question: Provide xcodebuild with .mobileprovision file and used the script provided in the answer to try and copy .mobileprovision files into the directory, the only difference is I replaced the mParse dependency using grep, as per a suggestion in this link: https://gist.github.com/benvium/2568707

However, when I run this script I get the following error:

$ sh installMobileProvisionFile.sh BuilderTestNew.mobileprovision 
Found UUID 402a766e-bfc7-4f16-8ab6-a46a95361b00
copying to ~/Library/MobileDevice/Provisioning Profiles/402a766e-bfc7-4f16-8ab6-a46a95361b00.mobileprovision..
cp: ~/Library/MobileDevice/Provisioning Profiles/402a766e-bfc7-4f16-8ab6-a46a95361b00.mobileprovision: No such file or directory
done

If I just run the cp command executed in the script by myself replacing the variables for the above values it works normally, so I can't understand why it fails when using this script? I am on Yosemite by the way.

EDIT:

Here's the adapted script:

if [ ! $# == 1 ]; then
 echo "Usage: $0 (path/to/mobileprovision)"
exit
fi

mp=$1

uuid=`grep UUID -A1 -a ${mp}| grep -io "[-A-Z0-9]\{36\}"`

echo "Found UUID $uuid"

output="~/Library/MobileDevice/Provisioning Profiles/$uuid.mobileprovision"

echo "copying to $output.."
cp "${mp}" "$output"

echo "done"`

Solution

  • When using the cp command in Bash you need to provide the full path of the files. Aliases such as ~/myFolder won't work. You will need to provide a full path such as /Users/Me/myFolder.