Class: Uberinstaller::Runner
- Inherits:
-
Object
- Object
- Uberinstaller::Runner
- Includes:
- Loggable
- Defined in:
- lib/uberinstaller/runner.rb
Instance Attribute Summary collapse
-
#packages ⇒ Object
readonly
the list of packages after configuration file is parsed.
-
#parser ⇒ Object
readonly
the parser class used to parse configuration file.
-
#platform ⇒ Object
readonly
the platform on which UberInstaller is running.
-
#unprocessed ⇒ Object
readonly
Returns the value of attribute unprocessed.
Instance Method Summary collapse
-
#initialize(file) ⇒ Runner
constructor
Initialize the Runner class.
- #install ⇒ Object
-
#preprocess ⇒ Object
Preprocess all packages performing validation.
-
#verify_architecture ⇒ Object
Verify that platform architecture match the one specified in the config file.
-
#verify_os_version ⇒ Object
Verify that the OS version match the one specified in the config file.
Methods included from Loggable
configure_logger_for, #logger, logger_for
Constructor Details
#initialize(file) ⇒ Runner
Initialize the Runner class
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/uberinstaller/runner.rb', line 22 def initialize(file) logger.debug Config.command_path logger.debug Config.local_pkg_path logger.debug Config.json_path logger.info "Processing JSON file: #{file}" # check if element has already been processed @unprocessed = true @parser = Parser.new file @platform = Platform.new logger.warn "Platform is not Ubuntu, please report any inconvenient behaviour" unless platform.is_ubuntu? verify_architecture verify_os_version # This dummy commander is used to launch before all and after all scripts @global_commander = Commander.new("Dummy package", { :cmd => { :after => "all.sh", :before => "all.sh" }}) @packages = parser.data[:packages] get_nested_json end |
Instance Attribute Details
#packages ⇒ Object (readonly)
the list of packages after configuration file is parsed
17 18 19 |
# File 'lib/uberinstaller/runner.rb', line 17 def packages @packages end |
#parser ⇒ Object (readonly)
the parser class used to parse configuration file
17 |
# File 'lib/uberinstaller/runner.rb', line 17 attr_reader :packages, :parser, :platform, :unprocessed |
#platform ⇒ Object (readonly)
the platform on which UberInstaller is running
17 |
# File 'lib/uberinstaller/runner.rb', line 17 attr_reader :packages, :parser, :platform, :unprocessed |
#unprocessed ⇒ Object (readonly)
Returns the value of attribute unprocessed.
17 |
# File 'lib/uberinstaller/runner.rb', line 17 attr_reader :packages, :parser, :platform, :unprocessed |
Instance Method Details
#install ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/uberinstaller/runner.rb', line 48 def install logger.info 'Installing packages...' @packages.each do |p| pkg_name = p[0].to_s pkg = p[1] installer = Installer.new(pkg_name, pkg) commander = Commander.new(pkg_name, pkg) logger.info "Installing #{pkg_name}" commander.before case pkg[:type] when 'system' begin installer.install 'system' rescue Exception => e logger.error e. pkg[:errors] = Array.new # add array to store errors pkg[:errors] << e. end when 'git' begin installer.install 'git' rescue Exception => e logger.error e. pkg[:errors] = Array.new # add array to store errors pkg[:errors] << e. end when 'local' begin installer.install 'local' rescue Exception::MultipleLocalFilesNotSupported => e logger.error e. pkg[:errors] = Array.new # add array to store errors pkg[:errors] << e. end else logger.error "#{pkg_name} :type is not supported" end commander.after end logger.info 'Executing after all commands...' @global_commander.after end |
#preprocess ⇒ Object
Preprocess all packages performing validation
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/uberinstaller/runner.rb', line 102 def preprocess logger.info 'Executing before all commands...' @global_commander.before logger.info 'Preprocessing packages...' @packages.each do |p| pkg_name = p[0].to_s pkg = p[1] logger.info "Package: #{pkg_name}" logger.debug "Package content: #{pkg}" # set pkg installation type based on existing key in the package definition pkg[:type] = get_package_type pkg installer = Installer.new(pkg_name, pkg) case pkg[:type] when 'system' begin installer.preprocess 'system' rescue Exception::InvalidPackage, Exception::InvalidPpa => e logger.error e. pkg[:skip] = true pkg[:errors] = Array.new # add array to store errors pkg[:errors] << e. end when 'git' begin installer.preprocess 'git' rescue Exception::InvalidFolder, Exception::MissingUrl, Exception::InvalidUrl => e logger.error e. pkg[:skip] = true pkg[:errors] = Array.new # add array to store errors pkg[:errors] << e. end when 'local' begin installer.preprocess 'local' rescue Exception::MissingLocalPackage, Exception::InvalidLocalPackage => e logger.error e. pkg[:skip] = true pkg[:errors] = Array.new # add array to store errors pkg[:errors] << e. end else logger.error "#{pkg_name} :type is not supported" end end PackageManager.new('remote').update end |
#verify_architecture ⇒ Object
Verify that platform architecture match the one specified in the config file
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/uberinstaller/runner.rb', line 161 def verify_architecture if parser.data[:meta][:arch] unless parser.data[:meta][:arch] == 'system' logger.debug 'Verifying architecture...' unless parser.data[:meta][:arch] == platform.architecture raise Exception::WrongArchitecture, parser.data[:meta][:arch] else logger.info "Architecture match installation file requirements" end end else logger.warn "Installation file does not specify a required architecture" end end |
#verify_os_version ⇒ Object
Verify that the OS version match the one specified in the config file
180 181 182 |
# File 'lib/uberinstaller/runner.rb', line 180 def verify_os_version raise Exception::WrongVersion, parser.data[:meta][:version] unless parser.data[:meta][:version] == platform.lsb[:codename] end |