hi-client/setup_ios_signing.sh
2025-10-13 18:08:02 +08:00

167 lines
4.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# iOS 签名设置助手脚本
set -e
# 颜色输出
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_certificates() {
log_info "检查已安装的证书..."
local identities=$(security find-identity -v -p codesigning 2>/dev/null)
if [ -n "$identities" ] && echo "$identities" | grep -q "iPhone Developer\|Apple Development"; then
log_success "找到可用的开发证书:"
echo "$identities" | grep "iPhone Developer\|Apple Development"
return 0
else
log_warning "未找到可用的开发证书"
return 1
fi
}
# 安装证书
install_certificate() {
local cert_file=$1
if [ -z "$cert_file" ]; then
log_error "请提供证书文件路径"
return 1
fi
if [ ! -f "$cert_file" ]; then
log_error "证书文件不存在: $cert_file"
return 1
fi
log_info "安装证书: $cert_file"
# 安装证书到钥匙串
security import "$cert_file" -k ~/Library/Keychains/login.keychain
if [ $? -eq 0 ]; then
log_success "证书安装成功"
else
log_error "证书安装失败"
return 1
fi
}
# 打开 Apple Developer Portal
open_developer_portal() {
log_info "打开 Apple Developer Portal..."
# 打开 App IDs 页面
open "https://developer.apple.com/account/resources/identifiers/list"
# 打开 Profiles 页面
open "https://developer.apple.com/account/resources/profiles/list"
log_info "请在浏览器中完成以下步骤:"
echo "1. 创建 App ID (Bundle ID: com.bearvpn.app)"
echo "2. 创建 Provisioning Profile"
echo "3. 下载并安装 Provisioning Profile"
}
# 验证完整设置
verify_setup() {
log_info "验证签名设置..."
# 检查证书
if ! check_certificates; then
log_error "证书检查失败"
return 1
fi
# 检查 Provisioning Profile
local profiles_dir="$HOME/Library/MobileDevice/Provisioning Profiles"
if [ -d "$profiles_dir" ] && [ "$(ls -A "$profiles_dir" 2>/dev/null)" ]; then
log_success "找到 Provisioning Profile"
ls -la "$profiles_dir"
else
log_warning "未找到 Provisioning Profile"
log_info "请确保已下载并安装了 Provisioning Profile"
fi
return 0
}
# 显示使用说明
show_instructions() {
log_info "iOS 签名设置说明"
echo "=========================================="
echo "1. 证书安装:"
echo " - 双击桌面上的 .cer 文件安装到钥匙串"
echo " - 或运行: ./setup_ios_signing.sh install ~/Desktop/your_cert.cer"
echo ""
echo "2. 创建 App ID"
echo " - Bundle ID: com.bearvpn.app"
echo " - 选择需要的功能(如 Network Extensions"
echo ""
echo "3. 创建 Provisioning Profile"
echo " - 选择 iOS App Development"
echo " - 选择刚创建的 App ID"
echo " - 选择您的证书"
echo " - 下载并双击安装 .mobileprovision 文件"
echo ""
echo "4. 验证设置:"
echo " - 运行: ./setup_ios_signing.sh verify"
echo ""
echo "5. 构建签名应用:"
echo " - 运行: source ios_signing_config.sh"
echo " - 运行: ./build_ios_dmg.sh"
echo "=========================================="
}
# 主函数
main() {
case "${1:-}" in
"install")
if [ -z "$2" ]; then
log_error "请提供证书文件路径"
echo "用法: $0 install <certificate_file>"
exit 1
fi
install_certificate "$2"
;;
"verify")
verify_setup
;;
"open")
open_developer_portal
;;
"check")
check_certificates
;;
*)
show_instructions
;;
esac
}
# 运行主函数
main "$@"