#!/bin/bash # BearVPN macOS 公证脚本 # 作者: Collins set -e # 配置变量 APP_NAME="BearVPN" APP_VERSION="1.0.0" APP_PATH="build/macos/Build/Products/Release/${APP_NAME}.app" DMG_PATH="build/macos/Build/Products/Release/${APP_NAME}-${APP_VERSION}-macOS-Signed.dmg" # 颜色输出 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # 日志函数 log_info() { echo -e "${BLUE}[INFO]${NC} $1" } log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } # 检查文件是否存在 check_files() { if [ ! -d "$APP_PATH" ]; then log_error "应用文件不存在: $APP_PATH" log_info "请先运行 ./sign_and_package.sh 构建应用" exit 1 fi if [ ! -f "$DMG_PATH" ]; then log_error "DMG 文件不存在: $DMG_PATH" log_info "请先运行 ./sign_and_package.sh 构建 DMG" exit 1 fi log_success "找到应用和 DMG 文件" } # 公证应用 notarize_app() { log_info "开始公证应用..." # 创建 ZIP 文件用于公证 ZIP_PATH="build/macos/Build/Products/Release/${APP_NAME}-${APP_VERSION}.zip" log_info "创建 ZIP 文件: $ZIP_PATH" ditto -c -k --keepParent "$APP_PATH" "$ZIP_PATH" log_warning "请确保您已生成应用专用密码:" log_warning "1. 访问 https://appleid.apple.com" log_warning "2. 登录您的 Apple ID" log_warning "3. 在'安全'部分生成应用专用密码" log_warning "4. 使用该密码进行公证" echo "" # 上传进行公证 log_info "上传应用进行公证..." xcrun notarytool submit "$ZIP_PATH" \ --apple-id "xxxxxxxx@example.com" \ --password "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ --team-id "XXXXXXXXXX" \ --wait if [ $? -eq 0 ]; then log_success "应用公证成功" # 装订公证票据 log_info "装订公证票据到应用..." xcrun stapler staple "$APP_PATH" if [ $? -eq 0 ]; then log_success "公证票据装订成功" else log_warning "公证票据装订失败,但应用已公证" fi else log_error "应用公证失败" log_info "请检查 Apple ID 和应用专用密码是否正确" exit 1 fi # 清理 ZIP 文件 rm -f "$ZIP_PATH" } # 公证 DMG notarize_dmg() { log_info "开始公证 DMG..." # 上传 DMG 进行公证 log_info "上传 DMG 进行公证..." xcrun notarytool submit "$DMG_PATH" \ --apple-id "xxxxxxxx@example.com" \ --password "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ --team-id "XXXXXXXXXX" \ --wait if [ $? -eq 0 ]; then log_success "DMG 公证成功" # 装订公证票据 log_info "装订公证票据到 DMG..." xcrun stapler staple "$DMG_PATH" if [ $? -eq 0 ]; then log_success "DMG 公证票据装订成功" else log_warning "DMG 公证票据装订失败,但 DMG 已公证" fi else log_error "DMG 公证失败" log_info "请检查 Apple ID 和应用专用密码是否正确" exit 1 fi } # 验证公证状态 verify_notarization() { log_info "验证公证状态..." # 验证应用公证 log_info "应用公证状态:" xcrun stapler validate "$APP_PATH" # 验证 DMG 公证 log_info "DMG 公证状态:" xcrun stapler validate "$DMG_PATH" } # 显示结果 show_result() { log_success "==========================================" log_success "公证完成!" log_success "==========================================" log_info "应用: $APP_PATH" log_info "DMG: $DMG_PATH" log_success "==========================================" log_info "现在应用已通过 Apple 公证" log_info "可以在任何 Mac 上安全运行" log_success "==========================================" } # 主函数 main() { log_info "开始 BearVPN macOS 公证流程..." log_info "==========================================" check_files notarize_app notarize_dmg verify_notarization show_result log_success "公证完成!" } # 运行主函数 main "$@"