Skip to content

Instantly share code, notes, and snippets.

@pmairoldi
Last active March 23, 2017 19:00
Show Gist options
  • Save pmairoldi/c3663a0683e35ff8cc5cf3d2f3065013 to your computer and use it in GitHub Desktop.
Save pmairoldi/c3663a0683e35ff8cc5cf3d2f3065013 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
class Configuration
attr_accessor :installer_path
attr_accessor :patch_path
attr_accessor :instance
attr_accessor :site
attr_accessor :directory
attr_accessor :database_server
attr_accessor :database_name
attr_accessor :database_user
attr_accessor :database_password
attr_accessor :silent
def initialize
@silent = true
yield(self) if block_given?
end
def transform
":I#{instance}"
end
def instance
"%02d" % @instance
end
def component_directory(name)
File.join(@directory, name).gsub('/', '\\')
end
def default_parameters
{
"TRANSFORMS" => transform
}
end
def instance_parameters
{
"MSINEWINSTANCE" => instance,
"BLUEEVALUATION_SITE_VAL" => @site,
"BLUEINTEGRATION_SITE_VAL" => @site,
"BLUEWEBSERVICES_SITE_VAL" => @site,
"BLUEREPORTENGINE_SITE_VAL" => @site,
"CUSTOMBLUEPATH" => "1",
"DIR_BLUEEVALUATION" => component_directory("Blue"),
"CUSTOMGATEWAYPATH" => "1",
"DIR_BLUEINTEGRATION" => component_directory("Gateway"),
"CUSTOMWSPATH" => "1",
"DIR_BLUEWEBSERVICES" => component_directory("WebServices"),
"CUSTOMREPATH" => "1",
"DIR_BLUEREPORTENGINE" => component_directory("ReportEngine"),
"CUSTOMSCHEDULERPATH" => "1",
"DIR_BLUESCHEDULER" => component_directory("Scheduler"),
"CUSTOMNTSERVICEPATH" => "1",
"DIR_BLUENTSERVICES" => component_directory("NT Services"),
"BLUESCHEDULER_BLUE_DATABASE" => @database_name,
"BLUESCHEDULER_DBSERVER_NAME" => @database_server,
"BLUESCHEDULER_USER_ID" => @database_user,
"BLUESCHEDULER_PASSWORD" => @database_password,
"BLUENTSERVICES_BLUE_DATABASE" => @database_name,
"BLUENTSERVICES_DBSERVER_NAME" => @database_server,
"BLUENTSERVICES_USER_ID" => @database_user,
"BLUENTSERVICES_PASSWORD" => @database_password,
}
end
def command_parameters(parameters)
parameters
.map { |k, v| "#{k}=\"#{v}\""}
.join(" ")
end
def install_parameters
command_parameters(default_parameters.merge(instance_parameters))
end
def uninstall_parameters
command_parameters(default_parameters)
end
def patch_parameters
command_parameters(default_parameters)
end
def silent_paramters
silent = [1, true, '1', 'true'].include?(@silent)
silent ? "/qn" : ""
end
end
type = ARGV.shift
installer_path = ARGV.shift
patch_path = ARGV.shift
instance = ARGV.shift
site = ARGV.shift
installation_directory = ARGV.shift
database_server = ARGV.shift
database_name = ARGV.shift
database_user = ARGV.shift
database_password = ARGV.shift
if ARGV.empty?
silent = true
else
silent = ARGV.shift
end
raise "Must provide the type of command (install, uninstall, patch) as the first parameter" unless type
raise "Must provide the installer path as the second parameter" unless installer_path
raise "Must provide the installer path as the third parameter" unless installer_path
raise "Must provide the instance number as the forth parameter" unless instance
raise "Must provide the iis site name as the fifth parameter" unless site
raise "Must provide the installation directory as the sixth parameter" unless installation_directory
raise "Must provide the database server as the seventh parameter" unless database_server
raise "Must provide the database name as the eighth parameter" unless database_name
raise "Must provide the database user as the nineth parameter" unless database_user
raise "Must provide the database password as the tenth parameter" unless database_password
configuration = Configuration.new do |configuration|
configuration.installer_path = installer_path
configuration.patch_path = patch_path
configuration.instance = instance
configuration.site = site
configuration.directory = installation_directory
configuration.database_server = database_server
configuration.database_name = database_name
configuration.database_user = database_user
configuration.database_password = database_password
configuration.silent = silent
end
def run_command(command, print = true)
if print
puts command
end
exec command
end
def install(configuration)
cmd = "msiexec /i #{configuration.installer_path} #{configuration.install_parameters} #{configuration.silent_paramters}"
run_command cmd
end
def uninstall(configuration)
cmd = "msiexec /x #{configuration.installer_path} #{configuration.uninstall_parameters} #{configuration.silent_paramters}"
run_command cmd
end
def patch(configuration)
cmd = "msiexec /p #{configuration.patch_path} #{configuration.patch_parameters} #{configuration.silent_paramters}"
run_command cmd
end
case type
when "install"
install(configuration)
when "uninstall"
uninstall(configuration)
when "patch"
patch(configuration)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment