Skip to content

Instantly share code, notes, and snippets.

@brbowden
Created October 25, 2019 03:01
Show Gist options
  • Save brbowden/565966282d92609b42340ee7814e7032 to your computer and use it in GitHub Desktop.
Save brbowden/565966282d92609b42340ee7814e7032 to your computer and use it in GitHub Desktop.
Resign IPA and include Swift Support libraries
#!/usr/bin/env bash
# Usage: sh resign_ipa.sh <IPA file> <full build version>
# i.e.: sh resign_ipa.sh ~/Downloads/Wolf.ipa 2.6.11.914
# Repackages and resigns the ~/Downloads/Wolf.ipa file and deposits the resulting file at ~/WolfBuilds/Wolf.2.6.11.914.ipa
# fail if any commands fails
set -e
# debug log
set -x
if [ $1 -eq 0 ]; then
if [ -z "$BITRISE_IPA_PATH" ]; then
echo "Need to provide an IPA path"
exit 1
else
echo "IPA path argument not provided, using BITRISE_IPA_PATH"
IPA_PATH=$BITRISE_IPA_PATH
fi
else
IPA_PATH=$1
fi
if [ $2 -eq 0 ]; then
echo "Version argument not provided, using CURRENT_IOS_VERSION"
IPA_VERSION=$CURRENT_IOS_VERSION
else
IPA_VERSION=$2
fi
IPA_FILES="ipa_files"
if [ -d "${IPA_FILES}" ];
then
rm -rf "${IPA_FILES}"
fi
#First, change the ipa name
mv $IPA_PATH tmp_wolf_ipa.zip
#Then unzip it
mkdir $IPA_FILES
unzip tmp_wolf_ipa.zip -d $IPA_FILES
APP="$IPA_FILES/Payload/Wolf.iOS.app"
IPA="Wolf.$IPA_VERSION.ipa"
TEMP_IPA_BUILT="/tmp/ipabuild"
DEVELOPER_DIR=`xcode-select --print-path`
if [ ! -d "${DEVELOPER_DIR}" ]; then
echo "No developer directory found!"
exit 1
fi
if [ ! -d "${APP}" ]; then
echo "Wolf.iOS.app not found at ${APP}"
exit 1
fi
echo "+ Packaging ${APP} into ${IPA}"
if [ -f "${IPA}" ];
then
/bin/rm "${IPA}"
fi
if [ -d "${TEMP_IPA_BUILT}" ];
then
rm -rf "${TEMP_IPA_BUILT}"
fi
echo "+ Preparing folder tree for IPA"
mkdir -p "${TEMP_IPA_BUILT}/Payload"
cp -Rp "${APP}" "${TEMP_IPA_BUILT}/Payload/Wolf.iOS.app"
echo "+ Adding SWIFT support (if necessary)"
echo "Directory: ${APP}/Frameworks"
if [ -d "${APP}/Frameworks" ];
then
mkdir -p "${TEMP_IPA_BUILT}/SwiftSupport"
mkdir -p "${TEMP_IPA_BUILT}/SwiftSupport/iphoneos"
for SWIFT_LIB in $(ls -1 "${APP}/Frameworks/"); do
COPY_FILE="${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/${SWIFT_LIB}"
if [ -e "${COPY_FILE}" ]
then
echo "Copying ${SWIFT_LIB}"
cp "${COPY_FILE}" "${TEMP_IPA_BUILT}/SwiftSupport/iphoneos"
else
echo "Skipping ${SWIFT_LIB} - file not found in Swift Libraries"
fi
done
fi
echo "+ zip --symlinks --verbose --recurse-paths ${IPA} ."
cd "${TEMP_IPA_BUILT}"
zip --symlinks --recurse-paths "${IPA}" .
mkdir -p "WolfBuilds"
#Copy it back so it can be deployed
mv ${IPA} ~/WolfBuilds/$IPA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment