Skip to content

Instantly share code, notes, and snippets.

@ggerard
Forked from wmerrifield/build+archive.sh
Created March 13, 2013 02:26
Show Gist options
  • Save ggerard/5148908 to your computer and use it in GitHub Desktop.
Save ggerard/5148908 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Nov 8, 2010.
    92 changes: 92 additions & 0 deletions build+archive.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,92 @@
    #!/bin/sh
    #
    # Copyright (c) 2010 Warren Merrifield
    #
    # Permission is hereby granted, free of charge, to any person obtaining a copy
    # of this software and associated documentation files (the "Software"), to deal
    # in the Software without restriction, including without limitation the rights
    # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    # copies of the Software, and to permit persons to whom the Software is
    # furnished to do so, subject to the following conditions:
    #
    # The above copyright notice and this permission notice shall be included in
    # all copies or substantial portions of the Software.
    #
    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    # THE SOFTWARE.

    die() {
    echo "$*" >&2
    exit 1
    }

    appname='AppName' # The App Name here
    sdk='iphoneos4.2'
    project_dir=$(pwd)
    adhoc_profile_uid='01234567-890A-BCDE-F012-34567890ABCD' # The Ad-Hoc Unique ID here
    uuid=$(uuidgen)
    dateString=$(date -u +"%a %b %d %T GMT %Y") #Bloody picky plistbuddy
    archive_root='Library/Application Support/Developer/Shared/Archived Applications' # No tilde!
    archive_dir=~/"$archive_root/"$uuid".apparchive"

    # Switch to the Xcode beta
    # xcode-select -print-path
    #sudo xcode-select -switch /DeveloperBeta

    # Clean build all the configurations
    xcodebuild -alltargets -configuration AdHoc -sdk $sdk clean
    xcodebuild -alltargets -configuration AdHoc -sdk $sdk build || die "Ad Hoc Distribution build failed"

    echo making ipa...
    # packaging
    cd build/AdHoc-iphoneos || die "no such directory"
    rm -rf Payload
    rm -f "$appname".*.ipa
    mkdir Payload
    cp -Rp "$appname.app" Payload/
    if [ -f "$project_dir"/iTunesArtwork ] ; then
    cp -f "$project_dir"/iTunesArtwork Payload/iTunesArtwork
    fi

    # Package up the payload as into an IPA
    ipaname="$appname.$(date -u +%Y%m%d)-$(date -u +%H%M%S).ipa"
    zip -r $ipaname Payload
    rm -rf Payload
    echo finished making $ipaname

    # Copy the .ipa into the shared directory
    cp -Rp $ipaname ~/Public/Builds/$appname/$ipaname

    # And into the built products directory
    echo copying to $CC_BUILD_ARTFACTS
    mv -f $ipaname $CC_BUILD_ARTFACTS

    # Create the archive directory and copy the Info.plist into it
    mkdir -p "$archive_dir"

    # Now we can copy everything we've made out the build directory
    cp -Rp . "$archive_dir"

    # And now let's modify the ArchiveInfo.plist as required.
    echo Making the ArchiveInfo.plist
    cd "$archive_dir"
    unzip -p $ipaname Payload/"$appname".app/Info.plist > AppInfo.plist
    /usr/libexec/PlistBuddy -c "Add :XCApplicationFilename string '$appname.app'" ArchiveInfo.plist
    /usr/libexec/PlistBuddy -c "Add :XCApplicationName string '$appname'" ArchiveInfo.plist
    /usr/libexec/PlistBuddy -c "Add :XCArchivePlatform string 'com.apple.platform.iphoneos'" ArchiveInfo.plist
    /usr/libexec/PlistBuddy -c "Add :XCArchiveUUID string '$uuid'" ArchiveInfo.plist
    /usr/libexec/PlistBuddy -c "Add :XCProfileUUID string '$adhoc_profile_uid'" ArchiveInfo.plist
    /usr/libexec/PlistBuddy -c "Add :XCArchivedDate date '$dateString'" ArchiveInfo.plist
    /usr/libexec/PlistBuddy -c "Add :XCInfoPlist dict" ArchiveInfo.plist
    /usr/libexec/PlistBuddy -c "Merge ./AppInfo.plist :XCInfoPlist" ArchiveInfo.plist
    /usr/libexec/PlistBuddy -c "Copy :XCInfoPlist:CFBundleIdentifier :CFBundleIdentifier" ArchiveInfo.plist
    /usr/libexec/PlistBuddy -c "Copy :XCInfoPlist:CFBundleVersion :CFBundleVersion" ArchiveInfo.plist
    rm -f AppInfo.plist

    echo All Complete
    exit 0