class Uberinstaller::Installer

Public Class Methods

new(pkg_name, pkg_body) click to toggle source

Initialize the class

@param pkg_name [String] the name of the package @param pkg_body [Hash] an Hash containing the parsed information for the package

# File lib/uberinstaller/installer.rb, line 17
def initialize(pkg_name, pkg_body)
  @name = pkg_name
  @body = pkg_body
  
  # an Hash containing private processing info for the class
  @meta = Hash.new
  @meta[:installable] = true

  if @body.has_key? :skip and @body[:skip]
    logger.warn "#{@name} has :skip option active, skipping "
  end
end

Public Instance Methods

install(type) click to toggle source

Perform package installation based upon installation type, only if installable? is true

@param type [String] the installation type

# File lib/uberinstaller/installer.rb, line 52
def install(type)
  return unless installable?

  case type
  when 'git' then install_git
  when 'local' then install_local
  when 'system' then install_system
  end
end
installable?() click to toggle source

Return if the package is installable

@return [bool] true if the package can be installed, false otherwise

# File lib/uberinstaller/installer.rb, line 33
def installable?
  @body[:skip] ? false : true
end
preprocess(type) click to toggle source

Perform package preprocessing based upon installation type, only if installable? is true

@param type [String] the installation type

# File lib/uberinstaller/installer.rb, line 65
def preprocess(type)
  return unless installable?

  case type
  when 'git' then preprocess_git
  when 'local' then preprocess_local
  when 'system' then preprocess_system
  when 'json' then preprocess_json
  else raise Exception::NoPreprocessorException, type
  end
end
validate(type) click to toggle source

Perform package validation based upon installation type

@param type [String] the installation type

# File lib/uberinstaller/installer.rb, line 40
def validate(type)
  case type
  when 'system' then validate_system
  when 'git' then validate_git
  when 'local' then validate_local
  when 'json' then validate_json
  end
end

Private Instance Methods

git_package_manager() click to toggle source

The git package manager object

@return [Object] an instance of a PackageManager

# File lib/uberinstaller/installer.rb, line 96
def git_package_manager
  @git_package_manager ||= PackageManager.new 'git'
end
install_git() click to toggle source

Install a package using the Git package manager

# File lib/uberinstaller/installer.rb, line 146
def install_git
  if @body[:git][:url].kind_of?(String)
    git_package_manager.install @body[:git][:url] + " " + @body[:git][:folder]
  else
    raise Exception::MultipleRepositoriesNotSupported
  end
end
install_local() click to toggle source

Install a package using the Local package manager

# File lib/uberinstaller/installer.rb, line 196
def install_local
  if @body[:local][:pkg].kind_of?(String)
    if File.extname(@body[:local][:pkg]) == '.deb'
      local_package_manager.install @body[:local][:pkg]
    else
      pkg_path = File.join Config.local_pkg_path, @body[:local][:pkg]
      `sudo ./#{pkg_path}`
    end
  else
    raise Exception::MultipleLocalFilesNotSupported
  end
end
install_system() click to toggle source

Install a package using the system package manager

# File lib/uberinstaller/installer.rb, line 101
def install_system
  logger.debug 'Sytem type installation'

  if @body[:system][:pkg].kind_of?(Array)
    @body[:system][:pkg].each { |pkg| remote_package_manager.install pkg }
  elsif @body[:system][:pkg].kind_of?(String)
    remote_package_manager.install @body[:system][:pkg]
  end
end
local_package_manager() click to toggle source

The local package manager object

@return [Object] an instance of a PackageManager

# File lib/uberinstaller/installer.rb, line 89
def local_package_manager
  @local_package_manager ||= PackageManager.new 'local'
end
preprocess_git() click to toggle source

Preprocess a git type package

Launch validation

# File lib/uberinstaller/installer.rb, line 157
def preprocess_git
  logger.debug 'Git type preprocess'
  begin
    validate 'git'
  rescue Exception => e
    @body[:skip] = true
    raise e
  end
end
preprocess_json() click to toggle source
# File lib/uberinstaller/installer.rb, line 236
def preprocess_json
  logger.debug 'JSON type validation'
  begin
    validate 'json'
  rescue Exception => e
    @body[:skip] = true
    raise e
  end
end
preprocess_local() click to toggle source

Preprocess a local type package

Launch validation

# File lib/uberinstaller/installer.rb, line 212
def preprocess_local
  logger.debug 'Local type preprocess'
  begin
    validate 'local'
  rescue Exception => e
    @body[:skip] = true
    raise e
  end
end
preprocess_system() click to toggle source

Preprocess a system type package.

Launch validation and on success add the ppa to the system, if any

# File lib/uberinstaller/installer.rb, line 114
def preprocess_system
  logger.debug 'Sytem type preprocess'

  begin
    validate 'system'
  rescue Exception => e
    @body[:skip] = true
    raise e
  else
    remote_package_manager.add_repository @body[:system][:ppa] if @body[:system].has_key? :ppa
  end
end
remote_package_manager() click to toggle source

The remote package manager object

@return [Object] an instance of a PackageManager

# File lib/uberinstaller/installer.rb, line 82
def remote_package_manager
  @remote_package_manager ||= PackageManager.new 'remote'
end
valid_local_pkg?() click to toggle source

Check if a local package is valid

A local package is valid when :pkg key is a string corresponding to a existing file path

@return [bool] true if the package is validw, false otherwise

# File lib/uberinstaller/installer.rb, line 283
def valid_local_pkg?
  logger.debug 'Validate local pkg'
  File.file?(File.join Uberinstaller::Config.local_pkg_path, @body[:local][:pkg])
end
valid_pkg?() click to toggle source

Check if a system package is valid

A package is valid when the :pkg key is a non-empty string or a non-empty array

@return [bool] true if the package is valid, false otherwise

# File lib/uberinstaller/installer.rb, line 273
def valid_pkg?
  logger.debug 'Validate :pkg'
  !(@body[:system][:pkg].empty? or @body[:system][:pkg].any? { |a| a.empty? })
end
valid_repository?(repository) click to toggle source

Check if the string is a valid repository

TODO: chack for repo, not only ppa @param repository [String] a valid string repository/PPA URL

@return [bool] true if the string is a valid repository, false otherwise

# File lib/uberinstaller/installer.rb, line 263
def valid_repository?(repository)
  logger.debug 'Validate repository'
  repository =~ /ppa:[a-z0-9-]+(\/[a-z0-9-]+)?/
end
validate_git() click to toggle source

Validate a git type package

Check for :folder and :url keys and perform validation on :url

@raise [Uberinstaller::Exception::InvalidFolder] if no :folder is specified @raise [Uberinstaller::Exception::MissingUrl] if no :url is specified @raise [Uberinstaller::Exception::Invalid] if :url is not a valid Github repository

# File lib/uberinstaller/installer.rb, line 174
def validate_git
  logger.debug 'Git type validation'

  if !@body[:git].has_key? :folder
    raise Uberinstaller::Exception::InvalidFolder, @name
  end

  if !@body[:git].has_key? :url
    raise Uberinstaller::Exception::MissingUrl, @name
  # else
  #   repo_url = @body[:git][:url].split('github.com')[1].split('.git')[0]
  #   repo_url[0] = ''

  #   begin
  #     Octokit.repo repo_url
  #   rescue
  #     raise Uberinstaller::Exception::InvalidUrl, @name
  #   end
  end
end
validate_json() click to toggle source
# File lib/uberinstaller/installer.rb, line 246
def validate_json
  if @body[:json].kind_of? String
    file = File.join Config::json_path, @body[:json] + '.json'
    raise Exception::JsonFileNotFound, @body[:json] unless File.exists? file
  else
    raise Exception::InvalidJson, @name
  end
end
validate_local() click to toggle source

Validate local type package

@raise [Uberinstaller::Exception::MissingLocalPackage] if the local package has no :pkg @raise [Uberinstaller::Exception::InvalidLocalPackage] if the local package has an invalid :pkg

# File lib/uberinstaller/installer.rb, line 226
def validate_local
  logger.debug 'Local type validation'

  if !@body[:local].has_key? :pkg
    raise Exception::MissingLocalPackage, @name
  else
    raise Exception::InvalidLocalPackage, @name if !valid_local_pkg?
  end
end
validate_system() click to toggle source

Validate a system type package

Check if package has a :pkg key and if if is valid; check if package has a :ppa key and perform validation on the ppa string.

@raise [Uberinstaller::Exception::InvalidPackage] if the package is not valid @raise [Uberinstaller::Exception::InvalidPpa] if the ppa is not valid

# File lib/uberinstaller/installer.rb, line 133
def validate_system
  logger.debug 'Sytem type validation'

  if !@body[:system].has_key? :pkg or !valid_pkg?
    raise Uberinstaller::Exception::InvalidPackage, @name
  end

  if @body[:system].has_key? :ppa
    raise Uberinstaller::Exception::InvalidPpa, @name unless valid_repository? @body[:system][:ppa]
  end
end