Files
AppsManager27/source/build_app.sh
T

110 lines
3.8 KiB
Bash
Executable File

#!/bin/sh
# Build and sign AppsManager.app after build_dylib.sh has produced the dylib.
#
# Required environment:
# APP_SOURCE Path to the original extracted ADManager.app
# PROVISION Path to a .mobileprovision for the target device(s)
# SIGN_IDENTITY Code signing identity, e.g. "Apple Distribution: Name (TEAMID)"
#
# Optional:
# ENTITLEMENTS Path to an entitlements plist (needed for App Group access)
# KEYCHAIN Keychain path for codesign
# INSERT_DYLIB Path to the insert_dylib/idylib tool (default: idylib)
# OUT_DIR Output directory (default: <source>/out)
# BUNDLE_ID CFBundleIdentifier (default: com.jbjf.appsmanager)
set -eu
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
APP_SOURCE=${APP_SOURCE:?Set APP_SOURCE to the extracted original ADManager.app}
PROVISION=${PROVISION:?Set PROVISION to your .mobileprovision}
SIGN_IDENTITY=${SIGN_IDENTITY:?Set SIGN_IDENTITY to your code signing identity}
ENTITLEMENTS=${ENTITLEMENTS:-}
KEYCHAIN=${KEYCHAIN:-}
INSERT_DYLIB=${INSERT_DYLIB:-idylib}
OUT_DIR=${OUT_DIR:-"$ROOT/out"}
BUNDLE_ID=${BUNDLE_ID:-com.jbjf.appsmanager}
DYLIB="$ROOT/hook/AppsManagerHook.dylib"
APP="$OUT_DIR/AppsManager.app"
FRAMEWORK="$APP/Frameworks/AppsManagerHook.framework"
if [ ! -f "$DYLIB" ]; then
echo "Missing $DYLIB; run build_dylib.sh first." >&2
exit 1
fi
if [ ! -d "$APP_SOURCE" ]; then
echo "APP_SOURCE is not a directory: $APP_SOURCE" >&2
exit 1
fi
if ! command -v "$INSERT_DYLIB" >/dev/null 2>&1; then
echo "insert_dylib tool not found: $INSERT_DYLIB" >&2
exit 1
fi
rm -rf "$APP"
mkdir -p "$OUT_DIR"
cp -R "$APP_SOURCE" "$APP"
mkdir -p "$FRAMEWORK"
cp "$DYLIB" "$FRAMEWORK/AppsManagerHook"
cp "$PROVISION" "$APP/embedded.mobileprovision"
plutil -replace CFBundleIdentifier -string "$BUNDLE_ID" "$APP/Info.plist"
plutil -replace CFBundleDisplayName -string "Apps Manager" "$APP/Info.plist"
plutil -replace CFBundleName -string "AppsManager" "$APP/Info.plist"
cat > "$FRAMEWORK/Info.plist" <<'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>AppsManagerHook</string>
<key>CFBundleIdentifier</key>
<string>com.jbjf.appsmanager.hook</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>AppsManagerHook</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>MinimumOSVersion</key>
<string>15.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
</array>
</dict>
</plist>
EOF
# Keep the hook in Frameworks so standard signing tools treat it as nested
# code and re-sign it together with the app.
install_name_tool -id "@rpath/AppsManagerHook.framework/AppsManagerHook" "$FRAMEWORK/AppsManagerHook"
cp "$APP/ADManager" "$APP/ADManager.orig"
"$INSERT_DYLIB" --inplace --overwrite --strip-codesig --all-yes \
"@rpath/AppsManagerHook.framework/AppsManagerHook" "$APP/ADManager"
rm -f "$APP/ADManager.orig"
if ! otool -l "$APP/ADManager" | grep -q "@executable_path/Frameworks"; then
install_name_tool -add_rpath "@executable_path/Frameworks" "$APP/ADManager"
fi
set -- -f -s "$SIGN_IDENTITY"
if [ -n "$KEYCHAIN" ]; then
set -- "$@" --keychain "$KEYCHAIN"
fi
if [ -n "$ENTITLEMENTS" ]; then
set -- "$@" --entitlements "$ENTITLEMENTS" --generate-entitlement-der
fi
codesign "$@" "$FRAMEWORK"
codesign "$@" "$APP"
echo "built $APP"
otool -L "$APP/ADManager" | head -8
otool -l "$APP/ADManager" | grep -A2 LC_RPATH | head -6