Skip to content

Commit b48101e

Browse files
committed
Update Linux suport.
1 parent e4601cc commit b48101e

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lib/localhost/system/linux.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,35 @@ module Localhost
77
module System
88
# Linux specific system operations.
99
module Linux
10+
# This appears to be the standard path for the system trust store on many Linux distributions.
11+
ANCHORS_PATH = "/etc/ca-certificates/trust-source/anchors/"
12+
UPDATE_CA_TRUST = "update-ca-trust"
13+
14+
# This is an older method for systems that do not use `update-ca-trust`.
15+
LOCAL_CERTIFICATES_PATH = "/usr/local/share/ca-certificates/"
16+
UPDATE_CA_CERTIFICATES = "update-ca-certificates"
17+
1018
# Install a certificate into the system trust store.
1119
#
1220
# @parameter certificate [String] The path to the certificate file.
1321
def self.install(certificate)
1422
filename = File.basename(certificate)
15-
destination = "/usr/local/share/ca-certificates/localhost-#{filename}"
23+
command = nil
1624

25+
if File.exist?(ANCHORS_PATH)
26+
# For systems using `update-ca-trust`.
27+
destination = File.join(ANCHORS_PATH, filename)
28+
command = UPDATE_CA_TRUST
29+
elsif File.exist?(LOCAL_CERTIFICATES_PATH)
30+
# For systems using `update-ca-certificates`.
31+
destination = File.join(LOCAL_CERTIFICATES_PATH, filename)
32+
command = UPDATE_CA_CERTIFICATES
33+
else
34+
raise "No known system trust store found. Please install the certificate manually."
35+
end
36+
1737
system("sudo", "cp", certificate, destination)
18-
system("sudo", "update-ca-certificates")
38+
system("sudo", command)
1939
end
2040
end
2141
end

releases.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Releases
22

3+
## Unreleased
4+
5+
- Add support for `update-ca-trust` on Linux sytems.
6+
37
## v1.4.0
48

59
- Add `localhost:purge` to delete all certificates.

0 commit comments

Comments
 (0)