Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. require 'optparse'
  2. require 'ostruct'
  3. require 'builder'
  4. require 'fileutils'
  5. require 'date'
  6.  
  7. options = {}
  8. optparse = OptionParser.new do |opts|
  9. opts.on('c', '--cert CERT_FILE', "Certificate File") do |f|
  10. options[:cert] = f
  11. end
  12.  
  13. opts.on('a', '--alias ALIAS', "Cert Alias") do |f|
  14. options[:alias] = f
  15. end
  16.  
  17. opts.on('k', '--keystore_folder KEYSTORE Folder', "Keystore Folder") do |f|
  18. options[:keystore] = f
  19. end
  20. end
  21. optparse.parse!
  22.  
  23. output = ""
  24. if options[:cert].to_s == ''
  25. raise "-c Certificate is required"
  26. end
  27. if options[:alias].to_s == ''
  28. raise "-a Alias is required"
  29. end
  30. if options[:keystore].to_s == ''
  31. raise "-k Keystore Folder Path is required"
  32. end
  33.  
  34. puts "Creating Backup Directory"
  35. folder_name = Time.now.strftime("%Y-%m-%d_%I-%M-%S%p")
  36. backup_dir = "#{options[:keystore]}\\prod\\#{folder_name}"
  37.  
  38. cmd = "mkdir #{backup_dir}"
  39. %x{ #{cmd} }
  40. puts "Backup Directory Created"
  41.  
  42. puts "Backing up Current Keystore File to Backup Directory"
  43. keystore_file_path = "#{options[:keystore]}\\prod\\.keystore"
  44. puts "#{options[:keystore]}"
  45. cmd = "copy #{keystore_file_path} #{backup_dir}"
  46. %x{ #{cmd} }
  47. puts "Current Keystore Backed up"
  48.  
  49. puts "Copying Uploaded certificate file to certificate folder"
  50. cmd = "copy #{options[:cert]} #{options[:keystore]}\\prod"
  51. %x{ #{cmd} }
  52. puts "Uploaded cert copied to Certificate folder"
  53.  
  54. cmd = "copy #{keystore_file_path} ."
  55. %x{ #{cmd} }
  56.  
  57. puts "Importing Certificate..."
  58. cmd = "\"%JAVA_HOME%\\bin\\keytool\" -importcert -keystore .keystore -storepass password -alias #{options[:alias]}_#{folder_name} -file #{options[:cert]} -noprompt"
  59. %x{ #{cmd} }
  60.  
  61. cmd = "copy .keystore #{keystore_file_path}"
  62. %x{ #{cmd} }
  63.  
  64. cmd = "copy .keystore #{options[:keystore]}\\dr\\.keystore"
  65. %x{ #{cmd} }
  66.  
  67. cmd = 'knife search "role:esb AND (chef_environment:prod OR chef_environment:dr)" -i -a ipaddress'
  68. resp = `#{cmd}`
  69. resp.split(/\n/).each do |line|
  70. tline = line.tap{|x| x.strip!}
  71. #puts tline
  72.  
  73. if tline.start_with?("ipaddress: ")
  74. ipad = tline.sub("ipaddress: ", "")
  75. cmd = "copy .keystore \\\\#{ipad}\\e$\\progress\\fuse-esb-7.1.0.fuse-047\\etc\\keystore"
  76. puts("Copying Keystore to #{ipad}")
  77. resp = `#{cmd}`
  78. puts(resp)
  79. end
  80. end
  81.  
  82. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement