Module: Localhost::System::Linux

Defined in:
lib/localhost/system/linux.rb

Overview

Linux specific system operations.

Constant Summary collapse

ANCHORS_PATH =

This appears to be the standard path for the system trust store on many Linux distributions.

"/etc/ca-certificates/trust-source/anchors/"
UPDATE_CA_TRUST =
"update-ca-trust"
OPENSUSE_ANCHORS_PATH =

OpenSUSE/SLES use this path for certificate anchors.

"/etc/pki/trust/anchors/"
LOCAL_CERTIFICATES_PATH =

This is an older method for systems that do not use update-ca-trust.

"/usr/local/share/ca-certificates/"
UPDATE_CA_CERTIFICATES =
"update-ca-certificates"

Class Method Summary collapse

Class Method Details

.install(certificate) ⇒ Object

Install a certificate into the system trust store.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/localhost/system/linux.rb', line 24

def self.install(certificate)
  filename = File.basename(certificate)
  command = nil
  
  if File.exist?(ANCHORS_PATH)
    # For systems using `update-ca-trust` (most Linux distributions).
    destination = File.join(ANCHORS_PATH, filename)
    command = UPDATE_CA_TRUST
  elsif File.exist?(OPENSUSE_ANCHORS_PATH)
    # For systems using `update-ca-certificates` (OpenSUSE/SLES).
    destination = File.join(OPENSUSE_ANCHORS_PATH, filename)
    command = UPDATE_CA_CERTIFICATES
  elsif File.exist?(LOCAL_CERTIFICATES_PATH)
    # For systems using `update-ca-certificates`.
    destination = File.join(LOCAL_CERTIFICATES_PATH, filename)
    command = UPDATE_CA_CERTIFICATES
  else
    raise "No known system trust store found. Please install the certificate manually."
  end
  
  success = system("sudo", "cp", certificate, destination)
  success &= system("sudo", command)
  
  if success
    $stderr.puts "Installed certificate to #{destination}"
    
    return true
  else
    raise "Failed to install certificate: #{certificate}"
  end
end