Skip to content

Instantly share code, notes, and snippets.

@ippy04
Forked from RichardBronosky/resign.sh
Created January 6, 2016 01:55
Show Gist options
  • Save ippy04/9eaddd59a19cc2769314 to your computer and use it in GitHub Desktop.
Save ippy04/9eaddd59a19cc2769314 to your computer and use it in GitHub Desktop.

Revisions

  1. @RichardBronosky RichardBronosky revised this gist Mar 29, 2013. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions resign.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    #!/usr/bin/env bash

    if [[ ! ( # any of the following are not true
    @@ -40,7 +39,7 @@ cd "$TMP"
    [[ $CLEANUP_TEMP -ne 1 ]] && echo "Using temp dir: $TMP"
    unzip -q "$IPA"
    echo App has AppID $(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' Payload/*.app/Info.plist)
    security cms -D -i /var/folders/74/kpcwmb6j1pn92kr8mtvm2mwh0000gn/T/./resign.I9DrKi7B/Payload/AtlantaJournal.app/embedded.mobileprovision > mobileprovision.plist
    security cms -D -i Payload/AtlantaJournal.app/embedded.mobileprovision > mobileprovision.plist
    echo "Trying to resign with '$(/usr/libexec/PlistBuddy -c "Print :Name" mobileprovision.plist)', which supports '$(/usr/libexec/PlistBuddy -c "Print :Entitlements:application-identifier" mobileprovision.plist)'"
    rm -rf Payload/*.app/_CodeSignature Payload/*.app/CodeResources
    cp "$PROVISION" Payload/*.app/embedded.mobileprovision
  2. @RichardBronosky RichardBronosky revised this gist Jul 18, 2012. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion resign.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@

    #!/usr/bin/env bash

    if [[ ! ( # any of the following are not true
    @@ -14,7 +15,6 @@ if [[ ! ( # any of the following are not true
    ) ]];
    then
    echo ' Usage: resign.sh Application.ipa foo/bar.mobileprovision "iPhone Distribution: I can haz code signed"'
    echo ' ## That last string argument is the name of the certificate as seen in Keychain Access.'
    exit;
    fi

    @@ -39,6 +39,9 @@ CLEANUP_TEMP=0 # Do not remove this line or "set -o nounset" will error on check
    cd "$TMP"
    [[ $CLEANUP_TEMP -ne 1 ]] && echo "Using temp dir: $TMP"
    unzip -q "$IPA"
    echo App has AppID $(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' Payload/*.app/Info.plist)
    security cms -D -i /var/folders/74/kpcwmb6j1pn92kr8mtvm2mwh0000gn/T/./resign.I9DrKi7B/Payload/AtlantaJournal.app/embedded.mobileprovision > mobileprovision.plist
    echo "Trying to resign with '$(/usr/libexec/PlistBuddy -c "Print :Name" mobileprovision.plist)', which supports '$(/usr/libexec/PlistBuddy -c "Print :Entitlements:application-identifier" mobileprovision.plist)'"
    rm -rf Payload/*.app/_CodeSignature Payload/*.app/CodeResources
    cp "$PROVISION" Payload/*.app/embedded.mobileprovision
    /usr/bin/codesign -f -s "$CERTIFICATE" --resource-rules Payload/*.app/ResourceRules.plist Payload/*.app
  3. @RichardBronosky RichardBronosky revised this gist Jul 6, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions resign.sh
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,7 @@ if [[ ! ( # any of the following are not true
    ) ]];
    then
    echo ' Usage: resign.sh Application.ipa foo/bar.mobileprovision "iPhone Distribution: I can haz code signed"'
    echo ' ## That last string argument is the name of the certificate as seen in Keychain Access.'
    exit;
    fi

  4. @RichardBronosky RichardBronosky renamed this gist Jun 5, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @RichardBronosky RichardBronosky created this gist Jun 5, 2012.
    45 changes: 45 additions & 0 deletions resign
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    #!/usr/bin/env bash

    if [[ ! ( # any of the following are not true
    # 1st arg is an existing regular file
    -f "$1" &&
    # ...and it has a .ipa extension
    "${1##*.}" == "ipa" &&
    # 2nd arg is an existing regular file
    -f "$2" &&
    # ...and it has an .mobileprovision extension
    "${2##*.}" == "mobileprovision" &&
    # 3rd arg is a non-empty string
    -n "$3"
    ) ]];
    then
    echo ' Usage: resign.sh Application.ipa foo/bar.mobileprovision "iPhone Distribution: I can haz code signed"'
    exit;
    fi

    ## Exit on use of an uninitialized variable
    set -o nounset
    ## Exit if any statement returns a non-true return value (non-zero)
    set -o errexit
    ## Announce commands
    #set -o xtrace

    realpath(){
    echo "$(cd "$(dirname "$1")"; echo -n "$(pwd)/$(basename "$1")")";
    }

    TMP="$(mktemp -d -t ./resign)"
    IPA="$(realpath $1)"
    IPA_NEW="$(pwd)/$(basename $IPA .ipa).resigned.ipa"
    PROVISION="$(realpath $2)"
    CERTIFICATE="$3"
    CLEANUP_TEMP=0 # Do not remove this line or "set -o nounset" will error on checks below
    #CLEANUP_TEMP=1 # Uncomment this line if you want this script to clean up after itself
    cd "$TMP"
    [[ $CLEANUP_TEMP -ne 1 ]] && echo "Using temp dir: $TMP"
    unzip -q "$IPA"
    rm -rf Payload/*.app/_CodeSignature Payload/*.app/CodeResources
    cp "$PROVISION" Payload/*.app/embedded.mobileprovision
    /usr/bin/codesign -f -s "$CERTIFICATE" --resource-rules Payload/*.app/ResourceRules.plist Payload/*.app
    zip -qr "$IPA_NEW" Payload
    [[ $CLEANUP_TEMP -eq 1 ]] && rm -rf "$TMP"