Skip to content

Instantly share code, notes, and snippets.

@0x8badf00d
Last active August 29, 2015 14:22
Show Gist options
  • Save 0x8badf00d/01b26098c6ad2b278d68 to your computer and use it in GitHub Desktop.
Save 0x8badf00d/01b26098c6ad2b278d68 to your computer and use it in GitHub Desktop.
Script to codesign app
# Script to codesign ipa with AdHoc or distribution certificate
# Execute script from the folder you have provisioning profile you want to be embedded with the IPA and name it as embedded.mobileprovision
#
# To change the bundle identifier pass it as argument to this script first argument is taken as bundle identifier, if more than one arguments are passed then its ignored
# usage script.sh com.appid.bundleid 1.2 45 FinalIPAName
echo "Start the codesigning the app"
mv *.ipa testapp.zip # Rename ipa file to .zip
tar -xf testapp.zip # unzip the file to reveal Payload folder
cd Payload/*.app/ # Go to Payload folder then into .app folder
# Set first argument passed with this script as bundle identifier
if [ $1 != 0 ]
then
echo "Overriding App bundle identifier...."
/usr/libexec/PlistBuddy -c "Set CFBundleIdentifier $1" info.plist # Set the CFBundleIdentifier of info.plist to first argument of the script
fi
# Set second argument passed with this script as bundle ShortVersionString
if [ $2 != 0 ]
then
echo "Overriding App bundle ShortVersionString...."
/usr/libexec/PlistBuddy -c "Set CFBundleShortVersionString $2" info.plist # Set the CFBundleShortVersionString of info.plist to second argument of the script
fi
# Set third argument passed with this script as bundle version
if [ $3 != 0 ]
then
echo "Overriding App bundle version...."
/usr/libexec/PlistBuddy -c "Set CFBundleVersion $3" info.plist # Set the CFBundleVersion of info.plist to third argument of the script
fi
/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" info.plist # Print CFBundleIdentifier info.plist file"
/usr/libexec/PlistBuddy -c "print CFBundleVersion" info.plist
rm -rf _CodeSignature # Remove _CodeSignature folder and its contents
rm -rf CodeResources # Remove CodeResources file
cp ../../*.mobileprovision . # Copy embdedded provisioning profile from parent folder to .app folder
mv *.mobileprovision embedded.mobileprovision #Rename Provisioning profile in this folder to embedded.mobileprovision
echo "Removing .DS_Store files"
rm -rf .DS_Store # Remove any .DS_Store files from .app folder
cd ../ # Go to Payload folder
rm -rf .DS_Store # Remove any .DS_Store files from Payload folder
cd ../ # Go to parent folder
echo "Codesigning App..."
/usr/bin/codesign -f -s "<Your Cert Name here. Get it from keychain>" Payload/*.app/ # Force Codesign the Application with Distribution certificate, name of distribution certificate should match with one in keychain access and give app path name
echo "Zipping the app contained in Payload folder"
if [ $4 != 0 ]
then
echo "Compressing payload to $4.ipa"
zip -r $4.ipa Payload >/dev/null #Zip the codesigned .app into an ipa file
else
echo "compressing the payload to app.ipa"
zip -r App.ipa Payload >/dev/null #Zip the codesigned .app into an ipa file
fi
rm -rf Payload
rm -rf testapp.zip
echo "Codesigning completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment