Sha256: 96bd9ef780d75f974e285822d6100848ad344c75cf6927979d3a3e530a78d974

Contents?: true

Size: 993 Bytes

Versions: 3

Compression:

Stored size: 993 Bytes

Contents

require 'server_tools/support/ssh'

module ServerTools
  class InstallDebPackage
    include SSH
    def initialize(hostname, options)
      @hostname = hostname
      @options = options
    end

    def copy_command
      [
        "rsync -avz",
        %(-e "ssh #{ssh_opts(options)}"),
        "--progress --partial",
        "#{options[:deb_package_file]}",
        "#{options[:ssh_user]}@#{hostname}:~/"
      ].join(' ')
    end

    def install_command
      ["ssh #{hostname}", "#{ssh_opts(options)}"].tap do |command|
        if options[:purge_older_version]
          command << %('#{purge_command} && #{_install_command}')
        else
          command << %('#{_install_command}')
        end
      end.join(' ')
    end

    private

    def purge_command
      "sudo dpkg -P #{options[:deb_package_name]}"
    end

    def _install_command
      "sudo dpkg --force-confnew -i ~/#{File.basename(options[:deb_package_file])}"
    end

    attr_reader :hostname, :options
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
server_tools-0.2.0 lib/server_tools/install_deb_package.rb
server_tools-0.1.6 lib/server_tools/install_deb_package.rb
server_tools-0.1.5 lib/server_tools/install_deb_package.rb