Skip to content

Instantly share code, notes, and snippets.

@kam800
Created May 26, 2018 12:21
Show Gist options
  • Save kam800/7e9b0fd55a3fbcd455695aab3ffa08ac to your computer and use it in GitHub Desktop.
Save kam800/7e9b0fd55a3fbcd455695aab3ffa08ac to your computer and use it in GitHub Desktop.
#!/bin/bash
source_framework_path="$1"
target_bundle_dir="$2"
framework_name="$(basename "${source_framework_path}")"
module_name="$(basename -s .framework "${framework_name}")"
bundle_name="${module_name}.bundle"
target_bundle_path="${target_bundle_dir}/${bundle_name}"
print_usage() {
echo "Usage: $0 IN_FRAMEWORK_PATH OUT_RESOURCE_BUNDLE_DIR"
exit 1
}
print_source_framework_path_error() {
echo "ERROR: '${source_framework_path}' framework directory does not exist."
exit 1
}
print_target_bundle_dir_error() {
echo "ERROR: '${target_bundle_dir}' directory does not exist."
exit 1
}
get_framework_executable_name() {
/usr/libexec/PlistBuddy -c 'print CFBundleExecutable' "${source_framework_path}/Info.plist" || exit 1
}
copy_target_framework_as_destination_bundle() {
local executable_name="$(get_framework_executable_name)"
rsync -au "${source_framework_path}/"\
--exclude '/_CodeSignature/'\
--exclude '/Headers/'\
--exclude '/Modules/'\
--exclude "/${executable_name}"\
"${target_bundle_path}" || exit 1
}
cleanup_bundle_plist() {
plutil -remove 'CFBundleExecutable' "${target_bundle_path}/Info.plist" @> /dev/null
}
update_bundle_plist_package_type() {
plutil -replace 'CFBundlePackageType' -string 'BNDL' "${target_bundle_path}/Info.plist"
}
cleanup_bundle() {
cleanup_bundle_plist
update_bundle_plist_package_type
}
codesign_bundle() {
/usr/bin/codesign --force --sign - --preserve-metadata=identifier,entitlements,flags --timestamp=none "${target_bundle_path}"
}
[ $# == 2 ] || print_usage
[ -d "${source_framework_path}" ] || print_source_framework_path_error
[ -d "${target_bundle_dir}" ] || print_target_bundle_dir_error
echo "Converting '${source_framework_path}' to '${target_bundle_path}'..."
copy_target_framework_as_destination_bundle
cleanup_bundle
codesign_bundle
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment