# # 一键注册设备生成签名文件 # 使用ruby generate_provision.rb 来执行 需要安装ruby 命令 # # require "spaceship" class PortalHandle # 初始化参数 def initialize(appid,username,password,teamId,uuid,csrFile,provisionFile,crtFile) @appid = appid # 新的appid @username = username # apple账号 @password = password # apple账号密码 @teamId = teamId # apple 团队id @registerUuid = uuid # 需要注册的设备uuid @csrFile = csrFile # 生成的csr文件,需要和签名用的key 成对 @provisionFile = provisionFile # 保存新profile路径 @certificateFile = crtFile # 保存新certificate路径 end # 登录苹果账号 def login() Spaceship::Portal.login(@username,@password) Spaceship.client.team_id = @teamId say 'Login Success!' end # 注册新设备到此账号 def registerDevice() current_device = Spaceship::Portal.device.find_by_udid(@registerUuid, include_disabled: true) if current_device == nil then Spaceship::Portal.device.create!(name: @registerUuid, udid: @registerUuid) say 'Register device into account' else current_device.enable! say 'Device exist in account. enable it' end end # 查找或者创建appid def createAppid() app = Spaceship::Portal.app.find(@appid) if app == nil then app = Spaceship::Portal.app.create!(bundle_id: @appid, name: "fastlane App") say 'Appid not exist generate...' end #app.update_service(Spaceship::Portal.app_service.push_notification.on) end # 创建证书 如果存在则不创建 def createCertificate() prod_cert = Spaceship::Portal.certificate.production prod_certs = prod_cert.all if 0 == prod_certs.length then say 'create certificate ~~~~~~~~~ ' # Create a new certificate signing request # csr, pkey = Spaceship::Portal.certificate.create_certificate_signing_request # Use the signing request to create a new distribution certificate # Spaceship::Portal.certificate.apple_distribution.create!(csr: csr) # csrFile = File.new('ios.certificateSignRequest','w') # csrFile.syswrite(csr) # csrFile.close # say 'Download csr Success...!' # keyFile = File.new('ios.key','w') # keyFile.syswrite(pkey) # keyFile.close # say 'Download privateKey success...!' # File.write('ios_producttion.cer',Spaceship::Portal.certificate.apple_distribution.all.first.download) # 从文件中读取csr 由于多个账号共享同一个csr和key csr = File.read(@csrFile) prod_cert.create!(csr: csr) end # 下载certificate File.write(@certificateFile,prod_certs.first.download) # 返回证书 return prod_certs.first end # 生成ad_hoc profile def createAdhocProfile() # 创建并获得线上证书 cert = createCertificate() # 获取 # 创建最新的证书 matching_profiles = Spaceship::Portal.provisioning_profile.ad_hoc.find_by_bundle_id(bundle_id: @appid) profile = nil if 0 == matching_profiles.length then profile = Spaceship::Portal.provisioning_profile.ad_hoc.create!(bundle_id: @appid, certificate: cert, name: 'profile_production_adhoc'+@appid) else devices = Spaceship::Portal.device.all profile = matching_profiles.first profile.devices = devices profile.update! say 'update devices ~~' end profile = Spaceship::Portal.provisioning_profile.ad_hoc.find_by_bundle_id(bundle_id: @appid).first provisionFileName = @provisionFile File.write(provisionFileName, profile.download) say 'write prov file success !!' end end appid = ARGV[0] username = ARGV[1] password = ARGV[2] teamId = ARGV[3] uuid = ARGV[4] csrFile = ARGV[5] provisionFile = ARGV[6] certificateFile = ARGV[7] handler = PortalHandle.new(appid,username,password,teamId,uuid,csrFile,provisionFile,certificateFile) # 登录 handler.login() # 注册这个设备 handler.registerDevice() # 查找或者创建appid handler.createAppid() # 创建证书 handler.createAdhocProfile()