#!/bin/bash set -euo pipefail # Xcode Run Script Phase (Post) for Archive obfuscation. # Add this as a late Build Phase (after Compile Sources / near end). # It restores original files backed up by archive_obfuscate_pre.sh. if [[ "${ACTION:-}" != "install" || "${CONFIGURATION:-}" != "Release" ]]; then echo "[obf-post] Skip: ACTION=${ACTION:-}, CONFIGURATION=${CONFIGURATION:-}" exit 0 fi DERIVED_DIR="${DERIVED_FILE_DIR:-/tmp}" MARKER_FILE="${DERIVED_DIR}/rd_obf_marker_${TARGET_NAME:-app}.env" if [[ ! -f "${MARKER_FILE}" ]]; then echo "[obf-post] No marker file found. Skip restore." exit 0 fi # shellcheck disable=SC1090 source "${MARKER_FILE}" if [[ -z "${BACKUP_DIR:-}" || -z "${ROOT:-}" ]]; then echo "[obf-post] Marker invalid, skip restore." exit 0 fi if [[ ! -d "${BACKUP_DIR}" ]]; then echo "[obf-post] Backup dir missing: ${BACKUP_DIR}" exit 0 fi echo "[obf-post] Restoring source files from ${BACKUP_DIR}" cd "${ROOT}" while IFS= read -r file; do rel="${file#${BACKUP_DIR}/}" mkdir -p "$(dirname "${ROOT}/$rel")" cp -f "$file" "${ROOT}/$rel" done < <(find "${BACKUP_DIR}" -type f) rm -rf "${BACKUP_DIR}" "${MARKER_FILE}" echo "[obf-post] Done."