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.3.9 install_files/apt_dependencies.rb
bard-1.3.8 install_files/apt_dependencies.rb
bard-1.3.7 install_files/apt_dependencies.rb
bard-1.3.6 install_files/apt_dependencies.rb
bard-1.3.5 install_files/apt_dependencies.rb
bard-1.3.4 install_files/apt_dependencies.rb
bard-1.3.3 install_files/apt_dependencies.rb
bard-1.3.2 install_files/apt_dependencies.rb
bard-1.3.1 install_files/apt_dependencies.rb
bard-1.3.0 install_files/apt_dependencies.rb
bard-1.2.0 install_files/apt_dependencies.rb
bard-1.1.2 install_files/apt_dependencies.rb
bard-1.1.1 install_files/apt_dependencies.rb
bard-1.1.0 install_files/apt_dependencies.rb
bard-1.0.8 install_files/apt_dependencies.rb
bard-1.0.7 install_files/apt_dependencies.rb
bard-1.0.6 install_files/apt_dependencies.rb
bard-1.0.5 install_files/apt_dependencies.rb
bard-1.0.4 install_files/apt_dependencies.rb
bard-1.0.3 install_files/apt_dependencies.rb