Created
March 4, 2023 09:33
-
-
Save MojtabaHs/4c62aaac67ce82b32e2ea07e3a44b5f1 to your computer and use it in GitHub Desktop.
An archive helper for changing the Archived files and with the given options and generating the corresponding IPAs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Created by Seyed Mojtaba Hosseini Zeidabadi. | |
# | |
# StackOverflow: https://stackoverflow.com/story/mojtabahosseini | |
# Linkedin: https://linkedin.com/in/MojtabaHosseini | |
# GitHub: https://github.com/MojtabaHs | |
# | |
COLOR='\033[1;36m' | |
NO_COLOR='\033[0m' | |
# 1. Get the XCArchive | |
echo Enter the path to the ${COLOR}xcarchive${NO_COLOR} file | |
read ARCHIVE_PATH | |
echo ; | |
cd "$ARCHIVE_PATH" | |
cd .. | |
ARCHIVE_DIRECTORY=`pwd` | |
# 2. Check the XCArchive | |
if [ ! -d "$ARCHIVE_PATH" ]; then | |
echo "${COLOR}xcarchive${NO_COLOR} not found! π" | |
exit | |
fi | |
# 3. Check PlistBuddy | |
PLISTBUDDY="/usr/libexec/PlistBuddy" | |
if [ ! -f "$PLISTBUDDY" ]; then | |
echo "${COLOR}PlistBuddy${NO_COLOR} not found! π" | |
exit | |
fi | |
BASH_FILE_DIRECTORY="$(dirname "$0")" | |
# 4. Check Configurations | |
CONFIG_PLIST_FILE="Configs.plist" | |
CONFIG_PLIST="$BASH_FILE_DIRECTORY"/"$CONFIG_PLIST_FILE" | |
if [ ! -f "$CONFIG_PLIST" ]; then | |
echo ${COLOR}"$CONFIG_PLIST_FILE"${NO_COLOR} not found! π | |
exit | |
fi | |
echo Import Configurations: π₯βοΈ ; | |
echo `"$PLISTBUDDY" -c "Print" "$CONFIG_PLIST"` | |
echo ; | |
# 5. Check Export Options | |
EXPORT_OPTIONS_PLIST_FILE="ExportOptions.plist" | |
EXPORT_OPTIONS_PLIST="$BASH_FILE_DIRECTORY"/$"$EXPORT_OPTIONS_PLIST_FILE" | |
if [ ! -f "$EXPORT_OPTIONS_PLIST" ]; then | |
echo ${COLOR}"$EXPORT_OPTIONS_PLIST"${NO_COLOR} not found! π | |
exit | |
fi | |
echo Export Configurations: π€βοΈ ; | |
echo `"$PLISTBUDDY" -c "Print :" "$EXPORT_OPTIONS_PLIST"` | |
echo ; | |
# 6. Do this for each configuration | |
INDEX=0 | |
while true ; do | |
"$PLISTBUDDY" -c "Print :$INDEX" "$CONFIG_PLIST" >/dev/null 2>/dev/null | |
if [ $? -ne 0 ]; then | |
COUNT=$INDEX | |
echo All $COUNT items have been generated successfully π | |
break | |
fi | |
DESTINATION_NAME=`"$PLISTBUDDY" -c "Print :$INDEX:'name'" "$CONFIG_PLIST"` | |
APP_ID=`"$PLISTBUDDY" -c "Print :$INDEX:'id'" "$CONFIG_PLIST"` | |
DUPLICATED_ARCHIVE="$DESTINATION_NAME".xcarchive | |
DUPLICATED_ARCHIVE_PATH="$ARCHIVE_DIRECTORY"/"$DUPLICATED_ARCHIVE" | |
# 7. Check new XCArchive existence | |
if [ -d "$DUPLICATED_ARCHIVE_PATH" ]; then | |
echo ${COLOR}"$DUPLICATED_ARCHIVE"${NO_COLOR} already exists! Ignore this one and continue... β οΈ ; | |
INDEX=$(($INDEX + 1)) | |
continue | |
fi | |
echo Creating "$DUPLICATED_ARCHIVE"... β³ ; | |
# 8. Duplicate the XCArchive | |
cp -R "$ARCHIVE_PATH" "$DUPLICATED_ARCHIVE_PATH" | |
ARCHIVE_INFO_PLIST="$DUPLICATED_ARCHIVE_PATH"/Info.plist | |
# TODO: Make the product name dynamic and get rid of the hard coded `TravelingWorld` | |
SETTINGS_DEVELOPER_OPTIONS_PLIST="$DUPLICATED_ARCHIVE_PATH"/Products/Applications/TravelingWorld.app/Settings.bundle/DeveloperOptions.plist | |
SETTINGS_ROOT="$DUPLICATED_ARCHIVE_PATH"/Products/Applications/TravelingWorld.app/Settings.bundle/Root.plist | |
# 9. Set preferences | |
echo "$DUPLICATED_ARCHIVE" is being configure... βοΈ ; | |
"$PLISTBUDDY" -c "Set :'Name' '$DESTINATION_NAME'" "$ARCHIVE_INFO_PLIST" | |
"$PLISTBUDDY" -c "Set :'SchemeName' '$DESTINATION_NAME'" "$ARCHIVE_INFO_PLIST" | |
# TODO: Make it find the correct key instead of using the index | |
"$PLISTBUDDY" -c "Set :'PreferenceSpecifiers':0:'DefaultValue' '$APP_ID'" "$SETTINGS_DEVELOPER_OPTIONS_PLIST" | |
"$PLISTBUDDY" -c "Set :'PreferenceSpecifiers':3:'DefaultValue' '$DESTINATION_NAME'" "$SETTINGS_ROOT" | |
echo "$DUPLICATED_ARCHIVE" created and configured successfully! β ; | |
echo ; | |
# 10. Export ipa | |
echo Exporting "$DESTINATION_NAME".ipa... π€ ; | |
EXPORTS="$ARCHIVE_DIRECTORY"/"EXPORTS" | |
IPA_DESTINATION="$EXPORTS"/"$DESTINATION_NAME" | |
xcodebuild -exportArchive -archivePath "$DUPLICATED_ARCHIVE_PATH" -exportPath "$IPA_DESTINATION" -exportOptionsPlist "$EXPORT_OPTIONS_PLIST" | |
echo "$DESTINATION_NAME".ipa exported successfully! β ; | |
echo ; | |
# 11. Zip the ipa container | |
echo Zipping "$DESTINATION_NAME"... π ; | |
DATE=$(date '+%Y-%m-%d %H.%M.%S') | |
ZIP_NAME="$DESTINATION_NAME - $DATE" | |
ZIP_DESTINATION="$EXPORTS"/"$ZIP_NAME".zip | |
cd "$EXPORTS" | |
#TODO: use $IPA_DESTINATION but without embedding all subtree path into the zip | |
zip -r "$ZIP_DESTINATION" "$DESTINATION_NAME" | |
echo "$DESTINATION_NAME".zip created successfully... β ; | |
echo ; | |
INDEX=$(($INDEX + 1)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment