Skip to content

Instantly share code, notes, and snippets.

@nerik
Created September 6, 2012 15:07
Show Gist options
  • Save nerik/3657149 to your computer and use it in GitHub Desktop.
Save nerik/3657149 to your computer and use it in GitHub Desktop.
Automation of iOs apps ad-hoc distribution
#!/bin/sh
# Allows full automation for ad-hoc "over the air" distribution of iOs apps
# 1. creates a signed ipa file from an already built .app file
# 2. generates a plist file
# 3. generates a php file allowing users to install the app with a link (this php files replaces in the plist the url part with the url of the php file)
# 4. (optional) makes a zip file of all the files which you can give to the client
# 5. uploads all the files to a webserver via FTP
# Erik Escoffier http://nerik.me
# Original idea by Vincent Daubry
# http://blog.octo.com/en/automating-over-the-air-deployment-for-iphone/
# Copyright 2010 OCTO. All rights reserved.
APPLICATION_NAME="Test"
BUNDLE_ID="me.nerik.test"
PROJECT_DIR="/Users/nerik/Dropbox/taf/test"
EXPORT_DIR="package"
DEVELOPPER_NAME="iPhone Developer: Erik Escoffier (XXXXX)" #get this info using Keychain for example
PROVISIONING_PROFILE="test.mobileprovision"
FTP_HOST="ftp.domain.com"
FTP_USER="***"
FTP_PWD="***"
FTP_REMOTE_DIR="www/Test"
# compile project
# project build should be already done by NME
#xcodebuild -target "${PROJECT_NAME}" -sdk "${TARGET_SDK}" -configuration Release
#Check if build succeeded
#if [ $? != 0 ]
#then
# exit 1
#fi
#build ipa w/ embedded provisioning profile
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${PROJECT_DIR}/build/ios/build/Release-iphoneos/${APPLICATION_NAME}.app" -o "${PROJECT_DIR}/${EXPORT_DIR}/${APPLICATION_NAME}.ipa" --sign "${DEVELOPPER_NAME}" --embed "${PROJECT_DIR}/${PROVISIONING_PROFILE}"
cd "${PROJECT_DIR}/${EXPORT_DIR}"
#generate plist file
echo "<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC '-//Apple//DTD PLIST 1.0//EN' 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'>
<plist version='1.0'>
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>_URL_</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>${BUNDLE_ID}</string>
<key>bundle-version</key>
<string>1.0.0</string>
<key>kind</key>
<string>software</string>
<key>title</key>
<string>${APPLICATION_NAME}</string>
</dict>
</dict>
</array>
</dict>
</plist>" > "${APPLICATION_NAME}.plist"
#generate php file
echo "<?php
\$sr = stristr( \$_SERVER['SCRIPT_URI'], '.php' ) === false ? \$_SERVER['SCRIPT_URI'] : dirname(\$_SERVER['SCRIPT_URI']) . '/';
\$itmsUrl = urlencode( \$sr . 'index.php?plist=true');
if (\$_GET['plist']=='true')
{
\$plist = file_get_contents( dirname(__FILE__)
. DIRECTORY_SEPARATOR
. '${APPLICATION_NAME}.plist');
\$plist = str_replace('_URL_', \$sr . '${APPLICATION_NAME}.ipa', \$plist);
header('content-type: application/xml');
echo \$plist;
die();
}
?>
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
<html>
</head>
<body>
<a href='itms-services://?action=download-manifest&url=<? echo \$itmsUrl; ?>'>Install ${APPLICATION_NAME}</a>
</body>
</html>" > "index.php"
#make archive
zip "${APPLICATION_NAME}.zip" *
#upload files to FTP
ftp -n $FTP_HOST <<END_SCRIPT
quote USER $FTP_USER
quote PASS $FTP_PWD
cd $FTP_REMOTE_DIR
put index.php
put ${APPLICATION_NAME}.plist
binary
put ${APPLICATION_NAME}.ipa
put ${APPLICATION_NAME}.zip
quit
END_SCRIPT
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment