#!/usr/local/rvm/rubies/ruby-2.4.2/bin/ruby #:set paste require "spaceship" if ARGV.length < 4 print "Usage : ./genProvisionProfile.rb \n" exit(1) else user = ARGV[0] pass = ARGV[1] iDevice = ARGV[2] iName = ARGV[3] end #TODO: Validate arguments. #Login to developer portals Spaceship::Portal.login(user, pass) #TODO: Check if there is currently install private key has a valid certificate. #Create new key pair for this project csr, pkey = Spaceship::Portal.certificate.create_certificate_signing_request #Create Directory FileUtils.mkdir_p "#{Dir.home}/.isign" #Save private key if (File.exists? "#{Dir.home}/.isign/key.pem") print "Removing exisitng private key\n" File.delete("#{Dir.home}/.isign/key.pem") end print "Writing new private key\n" File.write("#{Dir.home}/.isign/key.pem", pkey) #TODO: If maximum amount of certificates reached revoke the last one... certs = Spaceship::Portal.certificate.development.all if (certs.length == 1) certs.first.revoke! end #Create certificate Spaceship::Portal.certificate.development.create!(csr: csr) #Get newest certifiate cert = Spaceship::Portal.certificate.development.all.first #Save certificate if (File.exists? "#{Dir.home}/.isign/certificate.pem") print "Removing exisitng certificate\n" File.delete("#{Dir.home}/.isign/certificate.pem") end print "Writing new certificate\n" File.write("#{Dir.home}/.isign/certificate.pem", cert.download) #Check if com.sensepost.djigo4 is already registered app = Spaceship::Portal.app.find("com.sensepost.djigo4") if (app.nil?) # Create a new app Spaceship::Portal.app.create!(bundle_id: "com.sensepost.djigo4", name: "XC com sensepost djigo4") end print "Adding UDID: #{iDevice} Name: '#{iName}'\n" #Register new device #TODO: Check when maximum device limitation reached. Spaceship::Portal.device.create!(name: iName, udid: iDevice) print "Deleting old provisioning profile\n" old_profile = Spaceship::Portal.provisioning_profile.development.all.first old_profile.delete! print "Creating a new provisioning profile will all UDIDs\n" # Create a new provisioning profile with all devices (by default) profile = Spaceship::Portal.provisioning_profile.development.create!(bundle_id: "com.sensepost.djigo4", certificate: cert, name: "NLD Users") print "Repairing provisioning profiles and certificates\n" # Select all 'Invalid' or 'Expired' provisioning profiles broken_profiles = Spaceship::Portal.provisioning_profile.all.find_all do |profile| # the below could be replaced with `!profile.valid? || !profile.certificate_valid?`, which takes longer but also verifies the code signing identity (profile.status == "Invalid") end # Iterate over all broken profiles and repair them broken_profiles.each do |profile| profile.repair! # yes, that's all you need to repair a profile end print "Downloading new provisioning profile\n" # Get all Development profiles profiles_dev = Spaceship::Portal.provisioning_profile.development.all first_profile = profiles_dev.first File.write("#{Dir.home}/.isign/isign.mobileprovision", first_profile.download)