Sha256: 092626ec112b39837aacd17f8018139e416c32239d3a9128d04a6a71d5205543

Contents?: true

Size: 798 Bytes

Versions: 14

Compression:

Stored size: 798 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
      "sudo apt update && sudo apt install -y #{deps_to_install.join(' ')}"
    end
  end

  private

  def deps_to_install
    installed_deps = `apt list #{deps.join(' ')} --installed 2>/dev/null`.chomp.split("\n")[1..]
      .map { |line| line.split("/")[0] }
    deps - installed_deps
  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

14 entries across 14 versions & 1 rubygems

Version Path
bard-0.62.0 install_files/apt_dependencies.rb
bard-0.61.0 install_files/apt_dependencies.rb
bard-0.60.0 install_files/apt_dependencies.rb
bard-0.59.3 install_files/apt_dependencies.rb
bard-0.59.2 install_files/apt_dependencies.rb
bard-0.59.1 install_files/apt_dependencies.rb
bard-0.59.0 install_files/apt_dependencies.rb
bard-0.58.0 install_files/apt_dependencies.rb
bard-0.57.0 install_files/apt_dependencies.rb
bard-0.56.0 install_files/apt_dependencies.rb
bard-0.55.0 install_files/apt_dependencies.rb
bard-0.54.0 install_files/apt_dependencies.rb
bard-0.53.0 install_files/apt_dependencies.rb
bard-0.52.2 install_files/apt_dependencies.rb