Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'optparse'
- require 'ostruct'
- require 'builder'
- require 'fileutils'
- require 'date'
- options = {}
- optparse = OptionParser.new do |opts|
- opts.on('c', '--cert CERT_FILE', "Certificate File") do |f|
- options[:cert] = f
- end
- opts.on('a', '--alias ALIAS', "Cert Alias") do |f|
- options[:alias] = f
- end
- opts.on('k', '--keystore_folder KEYSTORE Folder', "Keystore Folder") do |f|
- options[:keystore] = f
- end
- end
- optparse.parse!
- output = ""
- if options[:cert].to_s == ''
- raise "-c Certificate is required"
- end
- if options[:alias].to_s == ''
- raise "-a Alias is required"
- end
- if options[:keystore].to_s == ''
- raise "-k Keystore Folder Path is required"
- end
- puts "Creating Backup Directory"
- folder_name = Time.now.strftime("%Y-%m-%d_%I-%M-%S%p")
- backup_dir = "#{options[:keystore]}\\prod\\#{folder_name}"
- cmd = "mkdir #{backup_dir}"
- %x{ #{cmd} }
- puts "Backup Directory Created"
- puts "Backing up Current Keystore File to Backup Directory"
- keystore_file_path = "#{options[:keystore]}\\prod\\.keystore"
- puts "#{options[:keystore]}"
- cmd = "copy #{keystore_file_path} #{backup_dir}"
- %x{ #{cmd} }
- puts "Current Keystore Backed up"
- puts "Copying Uploaded certificate file to certificate folder"
- cmd = "copy #{options[:cert]} #{options[:keystore]}\\prod"
- %x{ #{cmd} }
- puts "Uploaded cert copied to Certificate folder"
- cmd = "copy #{keystore_file_path} ."
- %x{ #{cmd} }
- puts "Importing Certificate..."
- cmd = "\"%JAVA_HOME%\\bin\\keytool\" -importcert -keystore .keystore -storepass password -alias #{options[:alias]}_#{folder_name} -file #{options[:cert]} -noprompt"
- %x{ #{cmd} }
- cmd = "copy .keystore #{keystore_file_path}"
- %x{ #{cmd} }
- cmd = "copy .keystore #{options[:keystore]}\\dr\\.keystore"
- %x{ #{cmd} }
- cmd = 'knife search "role:esb AND (chef_environment:prod OR chef_environment:dr)" -i -a ipaddress'
- resp = `#{cmd}`
- resp.split(/\n/).each do |line|
- tline = line.tap{|x| x.strip!}
- #puts tline
- if tline.start_with?("ipaddress: ")
- ipad = tline.sub("ipaddress: ", "")
- cmd = "copy .keystore \\\\#{ipad}\\e$\\progress\\fuse-esb-7.1.0.fuse-047\\etc\\keystore"
- puts("Copying Keystore to #{ipad}")
- resp = `#{cmd}`
- puts(resp)
- end
- end
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement