Skip to content

Instantly share code, notes, and snippets.

@linyize
Last active December 31, 2015 19:38
Show Gist options
  • Save linyize/8034386 to your computer and use it in GitHub Desktop.
Save linyize/8034386 to your computer and use it in GitHub Desktop.

Revisions

  1. linyize revised this gist Jul 4, 2015. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -34,6 +34,7 @@ fi
    plist=/tmp/"${scheme}".plist
    rm -f "${plist}"
    plutil -convert xml1 -o "${plist}" "${projectpath}"/"${projectname}".xcodeproj/project.pbxproj
    customArchiveName=$(xmllint --xpath Scheme/ArchiveAction/@customArchiveName "${schemefile}" | cut -d '"' -f2)
    targetid=$(xmllint --xpath Scheme/BuildAction/BuildActionEntries/BuildActionEntry/BuildableReference/@BlueprintIdentifier "${schemefile}" | cut -d '"' -f2)
    buildConfigurationList=$(/usr/libexec/PlistBuddy -c "Print objects:"${targetid}":buildConfigurationList" "${plist}")
    buildConfiguration=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfigurationList}":buildConfigurations:1" "${plist}")
    @@ -45,6 +46,10 @@ then
    exit 1
    fi

    if [ ! -n "${customArchiveName}" ]
    then
    customArchiveName="${scheme}"
    fi

    # find certname (first valid certificate in mobileprovision file)
    mpplist=/tmp/"${profileuuid}".plist
    @@ -73,7 +78,7 @@ fi


    # package ipa
    archive=$(ls -dt ~/Library/Developer/Xcode/Archives/*/"${scheme}"*.xcarchive|head -1)
    archive=$(ls -dt ~/Library/Developer/Xcode/Archives/*/"${customArchiveName}"*.xcarchive|head -1)
    app=$(ls -dt "${archive}"/Products/Applications/*.app|head -1)
    ipa=/tmp/"${scheme}".ipa
    rm -f "${ipa}"
  2. linyize revised this gist Dec 26, 2013. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -39,6 +39,11 @@ buildConfigurationList=$(/usr/libexec/PlistBuddy -c "Print objects:"${targetid}"
    buildConfiguration=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfigurationList}":buildConfigurations:1" "${plist}")
    profileuuid=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfiguration}":buildSettings:PROVISIONING_PROFILE" "${plist}")
    profile=~/Library/MobileDevice/Provisioning\ Profiles/"${profileuuid}".mobileprovision
    if [ ! -f "${profile}" ]
    then
    echo "mobileprovision file not found!"
    exit 1
    fi


    # find certname (first valid certificate in mobileprovision file)
  3. linyize revised this gist Dec 24, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -41,7 +41,7 @@ profileuuid=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfiguration}":
    profile=~/Library/MobileDevice/Provisioning\ Profiles/"${profileuuid}".mobileprovision


    # find certname
    # find certname (first valid certificate in mobileprovision file)
    mpplist=/tmp/"${profileuuid}".plist
    certdata=/tmp/"${profileuuid}".cer
    validcerts=/tmp/"${profileuuid}".txt
  4. linyize revised this gist Dec 24, 2013. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -40,28 +40,27 @@ buildConfiguration=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfigura
    profileuuid=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfiguration}":buildSettings:PROVISIONING_PROFILE" "${plist}")
    profile=~/Library/MobileDevice/Provisioning\ Profiles/"${profileuuid}".mobileprovision

    # find certname (first valid certificate in mobileprovision file)

    # find certname
    mpplist=/tmp/"${profileuuid}".plist
    certdata=/tmp/"${profileuuid}".cer
    validcerts=/tmp/"${profileuuid}".txt
    security cms -D -i "${profile}" > "${mpplist}"
    security find-identity -v -p codesigning | cut -d ' ' -f4 > "${validcerts}"
    foundvalidcert=0
    count=$(xmllint --xpath "count(plist/dict/array/data)" "${mpplist}")
    maxidx=$[${count} - 1]
    for idx in $(seq 0 ${maxidx})
    do
    /usr/libexec/PlistBuddy -c "Print DeveloperCertificates:${idx}" "${mpplist}" > "${certdata}"
    certsubject=$(openssl x509 -inform der -in "${certdata}" -noout -subject)
    certfingerprint=$(openssl x509 -inform der -in "${certdata}" -noout -fingerprint | cut -d '=' -f2 | sed 's/://g')
    certname=$(echo "${certsubject}" | cut -d '/' -f3 | cut -d '=' -f2)
    if [ $(cat "${validcerts}" | grep "${certfingerprint}" | wc -l) -gt 0 ]
    then
    foundvalidcert=1
    certsubject=$(openssl x509 -inform der -in "${certdata}" -noout -subject)
    certname=$(echo "${certsubject}" | cut -d '/' -f3 | cut -d '=' -f2)
    break
    fi
    done
    if [ foundvalidcert -eq 0 ]
    if [ ! -n "${certname}" ]
    then
    echo "valid certificate not found!"
    exit 1
  5. linyize revised this gist Dec 24, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -81,4 +81,4 @@ rm -f "${ipa}"


    # upload ipa to inhouse webserver
    #curl -F "ipa=@"${ipa}"" "${inhouseserver}"
    #curl -F ipa=@"${ipa}" "${inhouseserver}"
  6. linyize revised this gist Dec 24, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@ buildConfiguration=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfigura
    profileuuid=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfiguration}":buildSettings:PROVISIONING_PROFILE" "${plist}")
    profile=~/Library/MobileDevice/Provisioning\ Profiles/"${profileuuid}".mobileprovision

    # find certname (first certificate in mobileprovision file)
    # find certname (first valid certificate in mobileprovision file)
    mpplist=/tmp/"${profileuuid}".plist
    certdata=/tmp/"${profileuuid}".cer
    validcerts=/tmp/"${profileuuid}".txt
  7. linyize revised this gist Dec 24, 2013. 1 changed file with 23 additions and 3 deletions.
    26 changes: 23 additions & 3 deletions xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -29,6 +29,7 @@ then
    exit 1
    fi


    # find mobileprovision file
    plist=/tmp/"${scheme}".plist
    rm -f "${plist}"
    @@ -42,10 +43,29 @@ profile=~/Library/MobileDevice/Provisioning\ Profiles/"${profileuuid}".mobilepro
    # find certname (first certificate in mobileprovision file)
    mpplist=/tmp/"${profileuuid}".plist
    certdata=/tmp/"${profileuuid}".cer
    validcerts=/tmp/"${profileuuid}".txt
    security cms -D -i "${profile}" > "${mpplist}"
    /usr/libexec/PlistBuddy -c "Print DeveloperCertificates:0" "${mpplist}" > "${certdata}"
    certsubject=$(openssl x509 -inform der -in "${certdata}" -noout -subject)
    certname=$(echo "${certsubject}" | cut -d '/' -f3 | cut -d '=' -f2)
    security find-identity -v -p codesigning | cut -d ' ' -f4 > "${validcerts}"
    foundvalidcert=0
    count=$(xmllint --xpath "count(plist/dict/array/data)" "${mpplist}")
    maxidx=$[${count} - 1]
    for idx in $(seq 0 ${maxidx})
    do
    /usr/libexec/PlistBuddy -c "Print DeveloperCertificates:${idx}" "${mpplist}" > "${certdata}"
    certsubject=$(openssl x509 -inform der -in "${certdata}" -noout -subject)
    certfingerprint=$(openssl x509 -inform der -in "${certdata}" -noout -fingerprint | cut -d '=' -f2 | sed 's/://g')
    certname=$(echo "${certsubject}" | cut -d '/' -f3 | cut -d '=' -f2)
    if [ $(cat "${validcerts}" | grep "${certfingerprint}" | wc -l) -gt 0 ]
    then
    foundvalidcert=1
    break
    fi
    done
    if [ foundvalidcert -eq 0 ]
    then
    echo "valid certificate not found!"
    exit 1
    fi


    # package ipa
  8. linyize revised this gist Dec 24, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -18,9 +18,6 @@ xctool -project "${projectname}".xcodeproj -scheme "${scheme}" clean archive -sd


    # find xcscheme file
    plist=/tmp/"${scheme}".plist
    rm -f "${plist}"
    plutil -convert xml1 -o "${plist}" "${projectpath}"/"${projectname}".xcodeproj/project.pbxproj
    schemefile="${projectpath}"/"${projectname}".xcodeproj/xcshareddata/xcschemes/"${scheme}".xcscheme
    if [ ! -f "${schemefile}" ]
    then
    @@ -33,6 +30,9 @@ then
    fi

    # find mobileprovision file
    plist=/tmp/"${scheme}".plist
    rm -f "${plist}"
    plutil -convert xml1 -o "${plist}" "${projectpath}"/"${projectname}".xcodeproj/project.pbxproj
    targetid=$(xmllint --xpath Scheme/BuildAction/BuildActionEntries/BuildActionEntry/BuildableReference/@BlueprintIdentifier "${schemefile}" | cut -d '"' -f2)
    buildConfigurationList=$(/usr/libexec/PlistBuddy -c "Print objects:"${targetid}":buildConfigurationList" "${plist}")
    buildConfiguration=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfigurationList}":buildConfigurations:1" "${plist}")
  9. linyize revised this gist Dec 24, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,7 @@ fi
    targetid=$(xmllint --xpath Scheme/BuildAction/BuildActionEntries/BuildActionEntry/BuildableReference/@BlueprintIdentifier "${schemefile}" | cut -d '"' -f2)
    buildConfigurationList=$(/usr/libexec/PlistBuddy -c "Print objects:"${targetid}":buildConfigurationList" "${plist}")
    buildConfiguration=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfigurationList}":buildConfigurations:1" "${plist}")
    profileuuid=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfiguration}":buildSettings:PROVISIONING_PROFILE[sdk=iphoneos*]" "${plist}")
    profileuuid=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfiguration}":buildSettings:PROVISIONING_PROFILE" "${plist}")
    profile=~/Library/MobileDevice/Provisioning\ Profiles/"${profileuuid}".mobileprovision

    # find certname (first certificate in mobileprovision file)
  10. linyize revised this gist Dec 23, 2013. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,5 @@
    #!/bin/sh -ex
    # install xctool : brew install xctool
    # must be shared scheme

    inhouseserver="http://inhouse.xxx.com/upload"

    @@ -23,6 +22,15 @@ plist=/tmp/"${scheme}".plist
    rm -f "${plist}"
    plutil -convert xml1 -o "${plist}" "${projectpath}"/"${projectname}".xcodeproj/project.pbxproj
    schemefile="${projectpath}"/"${projectname}".xcodeproj/xcshareddata/xcschemes/"${scheme}".xcscheme
    if [ ! -f "${schemefile}" ]
    then
    schemefile=$(ls -dt "${projectpath}"/"${projectname}".xcodeproj/xcuserdata/*.xcuserdatad/xcschemes/"${scheme}".xcscheme | head -1)
    fi
    if [ ! -f "${schemefile}" ]
    then
    echo "scheme not found!"
    exit 1
    fi

    # find mobileprovision file
    targetid=$(xmllint --xpath Scheme/BuildAction/BuildActionEntries/BuildActionEntry/BuildableReference/@BlueprintIdentifier "${schemefile}" | cut -d '"' -f2)
  11. linyize revised this gist Dec 23, 2013. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    #!/bin/sh -ex
    # install xctool : brew install xctool
    # must be shared scheme
    # must be inhouse app

    inhouseserver="http://inhouse.xxx.com/upload"

    @@ -32,7 +31,7 @@ buildConfiguration=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfigura
    profileuuid=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfiguration}":buildSettings:PROVISIONING_PROFILE[sdk=iphoneos*]" "${plist}")
    profile=~/Library/MobileDevice/Provisioning\ Profiles/"${profileuuid}".mobileprovision

    # find certname
    # find certname (first certificate in mobileprovision file)
    mpplist=/tmp/"${profileuuid}".plist
    certdata=/tmp/"${profileuuid}".cer
    security cms -D -i "${profile}" > "${mpplist}"
  12. linyize revised this gist Dec 23, 2013. 1 changed file with 13 additions and 5 deletions.
    18 changes: 13 additions & 5 deletions xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -19,18 +19,26 @@ projectpath=$(pwd)
    xctool -project "${projectname}".xcodeproj -scheme "${scheme}" clean archive -sdk iphoneos


    # find certname and mobileprovision filepath
    # find xcscheme file
    plist=/tmp/"${scheme}".plist
    rm -f "${plist}"
    plutil -convert xml1 -o "${plist}" "${projectpath}"/"${projectname}".xcodeproj/project.pbxproj
    schemefile="${projectpath}"/"${projectname}".xcodeproj/xcshareddata/xcschemes/"${scheme}".xcscheme

    # find mobileprovision file
    targetid=$(xmllint --xpath Scheme/BuildAction/BuildActionEntries/BuildActionEntry/BuildableReference/@BlueprintIdentifier "${schemefile}" | cut -d '"' -f2)
    buildConfigurationList=$(/usr/libexec/PlistBuddy -c "Print objects:"${targetid}":buildConfigurationList" "${plist}")
    buildConfiguration=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfigurationList}":buildConfigurations:1" "${plist}")
    profileuuid=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfiguration}":buildSettings:PROVISIONING_PROFILE[sdk=iphoneos*]" "${plist}")
    profileuuid=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfiguration}":buildSettings:PROVISIONING_PROFILE[sdk=iphoneos*]" "${plist}")
    profile=~/Library/MobileDevice/Provisioning\ Profiles/"${profileuuid}".mobileprovision
    teamname=$(egrep -a -A 1 TeamName "${profile}" | grep string | cut -d '>' -f2 | cut -d '<' -f1)
    cert=iPhone\ Distribution:\ "${teamname}"

    # find certname
    mpplist=/tmp/"${profileuuid}".plist
    certdata=/tmp/"${profileuuid}".cer
    security cms -D -i "${profile}" > "${mpplist}"
    /usr/libexec/PlistBuddy -c "Print DeveloperCertificates:0" "${mpplist}" > "${certdata}"
    certsubject=$(openssl x509 -inform der -in "${certdata}" -noout -subject)
    certname=$(echo "${certsubject}" | cut -d '/' -f3 | cut -d '=' -f2)


    # package ipa
    @@ -41,7 +49,7 @@ rm -f "${ipa}"
    /usr/bin/xcrun -sdk iphoneos PackageApplication \
    -o "${ipa}" \
    -v "${app}" \
    -s "${cert}" \
    -s "${certname}" \
    --embed "${profile}"


  13. linyize revised this gist Dec 19, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/sh -ex
    # install xctool : brew install xctool
    # scheme must be shared scheme
    # must be shared scheme
    # must be inhouse app

    inhouseserver="http://inhouse.xxx.com/upload"
  14. linyize revised this gist Dec 19, 2013. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,12 @@
    #!/bin/sh -ex
    # install xctool : brew install xctool
    # scheme must be shared scheme
    # must be inhouse app

    inhouseserver="http://inhouse.xxx.com/upload"

    export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer

    # scheme must be shared scheme
    # must be inhouse app
    projectpath=$1
    scheme=$2
    projectname=$(basename "${projectpath}")
  15. linyize revised this gist Dec 19, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@ inhouseserver="http://inhouse.xxx.com/upload"
    export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer

    # scheme must be shared scheme
    # must be inhouse app
    projectpath=$1
    scheme=$2
    projectname=$(basename "${projectpath}")
  16. linyize revised this gist Dec 19, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@ inhouseserver="http://inhouse.xxx.com/upload"

    export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer

    # scheme must be shared scheme
    projectpath=$1
    scheme=$2
    projectname=$(basename "${projectpath}")
  17. linyize created this gist Dec 19, 2013.
    46 changes: 46 additions & 0 deletions xctool_archive.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    #!/bin/sh -ex

    inhouseserver="http://inhouse.xxx.com/upload"

    export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer

    projectpath=$1
    scheme=$2
    projectname=$(basename "${projectpath}")

    cd "${projectpath}"
    projectpath=$(pwd)


    # archive
    xctool -project "${projectname}".xcodeproj -scheme "${scheme}" clean archive -sdk iphoneos


    # find certname and mobileprovision filepath
    plist=/tmp/"${scheme}".plist
    rm -f "${plist}"
    plutil -convert xml1 -o "${plist}" "${projectpath}"/"${projectname}".xcodeproj/project.pbxproj
    schemefile="${projectpath}"/"${projectname}".xcodeproj/xcshareddata/xcschemes/"${scheme}".xcscheme
    targetid=$(xmllint --xpath Scheme/BuildAction/BuildActionEntries/BuildActionEntry/BuildableReference/@BlueprintIdentifier "${schemefile}" | cut -d '"' -f2)
    buildConfigurationList=$(/usr/libexec/PlistBuddy -c "Print objects:"${targetid}":buildConfigurationList" "${plist}")
    buildConfiguration=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfigurationList}":buildConfigurations:1" "${plist}")
    profileuuid=$(/usr/libexec/PlistBuddy -c "Print objects:"${buildConfiguration}":buildSettings:PROVISIONING_PROFILE[sdk=iphoneos*]" "${plist}")
    profile=~/Library/MobileDevice/Provisioning\ Profiles/"${profileuuid}".mobileprovision
    teamname=$(egrep -a -A 1 TeamName "${profile}" | grep string | cut -d '>' -f2 | cut -d '<' -f1)
    cert=iPhone\ Distribution:\ "${teamname}"


    # package ipa
    archive=$(ls -dt ~/Library/Developer/Xcode/Archives/*/"${scheme}"*.xcarchive|head -1)
    app=$(ls -dt "${archive}"/Products/Applications/*.app|head -1)
    ipa=/tmp/"${scheme}".ipa
    rm -f "${ipa}"
    /usr/bin/xcrun -sdk iphoneos PackageApplication \
    -o "${ipa}" \
    -v "${app}" \
    -s "${cert}" \
    --embed "${profile}"


    # upload ipa to inhouse webserver
    #curl -F "ipa=@"${ipa}"" "${inhouseserver}"