Sha256: 3e792ea04329ea5ca4256fdb3c290579094d03cee317b17a0425c7251b951d90

Contents?: true

Size: 823 Bytes

Versions: 35

Compression:

Stored size: 823 Bytes

Contents

module AptDependencies
  extend self

  def self.ensure!
    return "true" if deps_to_install.none?
    if sudo_password_required? && ENV["RAILS_ENV"] != "development"
      $stderr.puts "sudo requires password! cannot install #{deps_to_install.join(' ')}"
      exit 1
    else
      system "sudo DEBIAN_FRONTEND=noninteractive apt-get update -y && sudo DEBIAN_FRONTEND=noninteractive apt-get install -y #{deps_to_install.join(' ')}"
    end
  end

  private

  def deps_to_install
    deps.reject do |dep|
      system("dpkg-query -W -f='${Status}' #{dep} 2>/dev/null > /dev/null")
    end
  end

  def deps
    @deps ||= File.readlines("Aptfile", chomp: true).select { |line| line.length > 0 }
  rescue Errno::ENOENT
    @deps = []
  end

  def sudo_password_required?
    !system("sudo -n true 2>/dev/null")
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
bard-1.0.2 install_files/apt_dependencies.rb
bard-1.0.1 install_files/apt_dependencies.rb
bard-1.0.0 install_files/apt_dependencies.rb
bard-0.69.2 install_files/apt_dependencies.rb
bard-0.69.1 install_files/apt_dependencies.rb
bard-0.69.0 install_files/apt_dependencies.rb
bard-0.68.0 install_files/apt_dependencies.rb
bard-0.67.0 install_files/apt_dependencies.rb
bard-0.66.0 install_files/apt_dependencies.rb
bard-0.65.0 install_files/apt_dependencies.rb
bard-0.64.1 install_files/apt_dependencies.rb
bard-0.64.0 install_files/apt_dependencies.rb
bard-0.63.0 install_files/apt_dependencies.rb
bard-0.62.2 install_files/apt_dependencies.rb
bard-0.62.1 install_files/apt_dependencies.rb