bin/genZPK in genZPK-0.1.2 vs bin/genZPK in genZPK-0.1.3
- old
+ new
@@ -3,22 +3,16 @@
require 'tmpdir'
require 'erb'
require 'genZPK'
require 'xmlsimple'
include GenZPK
-=begin
-cd /var/www/uat/
-run checks
-nano deployment.xml
-rm -rf INSXCloud-UAT.zpk
-sudo /usr/local/zend/bin/zdpack pack uat/
-=end
options = {}
opt_parser = OptionParser.new do |opt|
+
opt.banner = "Usage: genZPK -s SYSTEM -v ZPK_VERSION -n PACKAGE_NAME DIR"
opt.separator "Initial configuration: genZPK --configure "
opt.separator ""
opt.on("-s","--system SYSTEM","which system should checks be performed for") do |system|
options[:system] = system
@@ -30,96 +24,109 @@
opt.on("-n","--name PACKAGE_NAME","name of application to deploy") do |name|
options[:name] = name
end
+ opt.on("-p","--pull", "run \"git pull origin master\" prior to packaging") do
+ options[:pull] = true
+ end
+
opt.on("--configure","perform the initial configuration to setup checks prior to packaging") do
GenZPK::doConfigure
exit 0
end
+
opt.on("--version", "prints the version of this application") do
puts GenZPK::VERSION
exit 0
end
opt.on("-h","--help","help") do
puts opt_parser
end
end
+
+
begin
opt_parser.parse!
rescue OptionParser::InvalidOption
warn "Required parameters not set or invalid argument. Please run genZPK --help for more info."
exit -1
end
-if not File.exists?(File.expand_path '~/.genZPK/checks.xml')
- warn "Unable to locate configuration files. Please run genZPK --configure"
- exit -1
-end
+dir = String(ARGV[0]).end_with?('/') ? String(ARGV[0]).chomp : String(ARGV[0])
-if not File.read(File.expand_path('~/.genZPK/checks.xml')).gsub(/\s+/, "") == ""
- checkHash = XmlSimple.xml_in(File.expand_path( '~/.genZPK/checks.xml'), {'KeyAttr' => 'name', 'ForceArray'=>false})
-else
- warn "Configuration empty. Please run genZPK --configure"
- exit -1
-end
+requireCondition File.exists?(File.expand_path '~/.genZPK/checks.xml'), "Unable to locate configuration files. Please run genZPK --configure"
+requireCondition (File.read(File.expand_path('~/.genZPK/checks.xml')).gsub(/\s+/, "") == ""), "Configuration empty. Please run genZPK --configure"
+requireCondition getZdpack.not_nil?, "unable to locate zdpack executable. Please check zend server installation at /usr/local/zend/"
+requireCondition dir.not_nil?,"Required parameters not set or invalid argument. Please run genZPK --help for more info."
+requireCondition options[:system].not_nil?,"Required parameters not set or invalid argument. Please run genZPK --help for more info."
+requireCondition options[:version].not_nil?,"Required parameters not set or invalid argument. Please run genZPK --help for more info."
+requireCondition options[:name].not_nil?,"Required parameters not set or invalid argument. Please run genZPK --help for more info."
+requireCondition File.exists?(dir), "Error: Directory \"#{dir}\" does not exist."
-if getZdpack.nil?
- warn "unable to locate zdpack executable. Please check zend server installation at /usr/local/zend/"
- exit -1
-end
+configHash = XmlSimple.xml_in(File.expand_path( '~/.genZPK/checks.xml'), {'KeyAttr' => 'name', 'ForceArray'=>false})
-dir = ARGV[0]
-if dir.nil? or options[:system].nil? or options[:version].nil? or options[:name].nil?
- warn "Required parameters not set or invalid argument. Please run genZPK --help for more info."
- exit -1
+if options[:pull] == true
+ Dir.chdir dir do
+ requireCondition system("git pull origin master"), "Unable to update code via git. Exiting..."
+ end
end
-if String(dir).end_with? '/'
- dir = dir.chomp
-end
-if not File.exists? dir
- warn %q{Error: Directory "#{dir}" does not exist.}
- exit -1
-end
-Dir.chdir dir
-if not system("git pull origin master")
- warn "Unable to update code via git. Exiting..."
- Dir.chdir ".."
- exit -1
-end
-Dir.chdir ".."
-if checkHash["system"].has_key? "name"
- if not checkHash["system"]["name"] == options[:system]
+
+
+if configHash["system"].has_key? "name"
+ if not configHash["system"]["name"] == options[:system]
warn "Could not find system \"#{options[:system]}\" in configuration. Please run genZPK --configure to setup checks for this system or verify the system name."
exit -1
end
- if checkHash["system"]["check"].is_a? Array
- checks = checkHash["system"]["check"]
+ if configHash["system"]["checks"]["check"].is_a? Array
+ checks = configHash["system"]["checks"]["check"]
else
checks = Array.new
- checks.push checkHash["system"]["check"]
+ checks.push configHash["system"]["checks"]["check"]
end
+
+ if configHash["system"].has_key? "subdomains"
+ if configHash["system"]["subdomains"]["file"].is_a? Array
+ subdomainChecks = configHash["system"]["subdomains"]["file"]
+ else
+ subdomainChecks = Array.new
+ subdomainChecks.push configHash["system"]["subdomains"]["file"]
+ end
+ else
+ subdomainChecks = nil
+ end
else
- if not checkHash["system"].has_key? options[:system]
+ if not configHash["system"].has_key? options[:system]
warn "Could not find system \"#{options[:system]}\" in configuration. Please run genZPK --configure to setup checks for this system or verify the system name."
exit -1
end
- if checkHash["system"][options[:system]]["check"].is_a? Array
- checks = checkHash["system"][options[:system]]["check"]
+ if configHash["system"][options[:system]]["checks"]["check"].is_a? Array
+ checks = configHash["system"][options[:system]]["checks"]["check"]
else
checks = Array.new
- checks.push checkHash["system"][options[:system]]["check"]
+ checks.push configHash["system"][options[:system]]["checks"]["check"]
end
+
+ if configHash["system"][options[:system]].has_key? "subdomains"
+ if configHash["system"][options[:system]]["subdomains"]["file"].is_a? Array
+ subdomainChecks = configHash["system"][options[:system]]["subdomains"]["file"]
+ else
+ subdomainChecks = Array.new
+ subdomainChecks.push configHash["system"][options[:system]]["subdomains"]["file"]
+ end
+ else
+ subdomainChecks = nil
+ end
end
puts "Running checks"
puts "-" * 80
@@ -179,9 +186,93 @@
puts "#{successes} of #{checks.size} checks passed. Please check files listed above and try again."
exit -1
end
puts "All checks passed. Continuing..."
+
+puts "-" * 80
+puts "Verifying subdomains"
+puts "-" * 80
+
+successes = 0
+
+for i in 0..(subdomainChecks.size - 1)
+
+ check = subdomainChecks[i]
+ path = check["path"]
+
+ display = path
+
+ if File.exists?(dir + path)
+ contents = File.read(dir + path)
+ fieldPasses = 0
+
+ check.each do |field, value|
+ if not field == "path"
+ if not configHash["definitions"]["definition"][field].nil?
+ begin
+ regex = /#{configHash["definitions"]["definition"][field]["regex"]["content"]}/
+ rescue RegexpError => e
+ puts "Invalid regular in configuration. Please run genZPK --configure\n#{e.message}"
+ exit -1
+ end
+
+ matchgrp = Integer(configHash["definitions"]["definition"][field]["regex"]["group"]) - 1
+ matches = contents.scan(regex)
+
+ if matches[0][0] == value
+ fieldPasses += 1
+ else
+ if display.end_with? "\n"
+ display << "\tField Failed: #{field}\n"
+ display << "\t\tValue: #{matches[0][0]}\n"
+ display << "\t\tDefined value: #{value}\n"
+ else
+ display << "\n\tField Failed: #{field}\n"
+ display << "\t\tValue: #{matches[0][0]}\n"
+ display << "\t\tDefined value: #{value}\n"
+ end
+ end
+ else
+ if display.end_with? "\n"
+ display << "\tField not defined: #{field}\n"
+ else
+ display << "\n\tField not defined: #{field}\n"
+ end
+ end
+ end
+ end
+
+
+ if fieldPasses == (check.size - 1)
+ display << "." * (80 - "SUCCESS".size - display.size)
+ display << "SUCCESS"
+ puts display
+ successes += 1
+ else
+ tmpString = "#{fieldPasses} of #{check.size - 1} fields verified"
+ display << tmpString
+ display << "." * (80 - "#{fieldPasses} of #{check.size - 1} fields verified".size - "FAIL".size)
+ display << "FAIL"
+ puts display
+ end
+ else
+ display << "." * (80 - "FAIL".size - display.size)
+ display << "FAIL\n"
+ display << "\tFile not found: #{dir + path}"
+ puts display
+ end
+end
+
+puts "-" * 80
+
+if not successes == subdomainChecks.size
+ puts "#{successes} of #{subdomainChecks.size} subdomains passed. Please check files listed above and try again."
+ exit -1
+end
+
+puts "All subdomains passed. Continuing..."
+
if not File.exists? dir + "/scripts"
FileUtils.mkpath dir + "/scripts"
end
\ No newline at end of file