Verified Commit d49e4a5c authored by Aral Balkan's avatar Aral Balkan
Browse files

Improve console output for consistency

parent 9a683efd
......@@ -6,6 +6,7 @@ import { log, print } from './util/log.js'
// and on macOS for Firefox. Ensure it exists.
// Source: https://github.com/FiloSottile/mkcert/blob/master/README.md#installation
export default function installCertutil () {
process.stdout.write(` ╰─ Installing certutil if necessary… `)
const platform = os.platform()
if (platform === 'linux') {
installCertutilOnLinux()
......@@ -16,7 +17,7 @@ export default function installCertutil () {
// required on Windows.
} else {
// Unknown platform. This should have been caught earlier. Panic.
throw new Error(' 🤯 ❨auto-encrypt-localhost❩ Panic: Unknown platform detected.', platform)
throw new Error(' ╰─ 🤯 Panic: Unknown platform detected.', platform)
}
}
......@@ -28,9 +29,13 @@ export default function installCertutil () {
// Depending on the platform we try to do so using apt, yum, or pacman. If none of
// those exist, we fail.
function installCertutilOnLinux () {
if (commandExists('certutil')) return // Already installed
if (commandExists('certutil')) {
// Already installed
process.stdout.write('done.\n')
return
}
print(' 📜 ❨auto-encrypt-localhost❩ Installing certutil dependency (Linux) ')
print('\n ╰─ Installing certutil dependency (Linux) ')
let options = { env: process.env }
try {
if (commandExists('apt')) {
......@@ -39,19 +44,19 @@ function installCertutilOnLinux () {
childProcess.execSync('sudo apt-get install -y -q libnss3-tools', options)
} else if (commandExists('yum')) {
// Untested: if you test this, please let me know https://github.com/indie-mirror/https-server/issues
log('\n 🤪 ❨auto-encrypt-localhost❩ Attempting to install required dependency using yum. This is currently untested. If it works (or blows up) for you, I’d appreciate it if you could open an issue at https://github.com/indie-mirror/https-server/issues and let me know. Thanks! – Aral\n')
log(' ╰─ 🤪 Attempting to install required dependency using yum. This is currently untested. If it works (or blows up) for you, I’d appreciate it if you could open an issue at https://github.com/indie-mirror/https-server/issues and let me know. Thanks! – Aral\n')
childProcess.execSync('sudo yum install nss-tools', options)
log(' 📜 ❨auto-encrypt-localhost❩ Certutil installed using yum.')
log(' ╰─ Certutil installed using yum.')
} else if (commandExists('pacman')) {
childProcess.execSync('sudo pacman -S nss', options)
log(' 📜 ❨auto-encrypt-localhost❩ Certutil installed using pacman.')
log(' ╰─ Certutil installed using pacman.')
} else {
// Neither Homebrew nor MacPorts is installed. Warn the person.
log('\n ⚠️ ❨auto-encrypt-localhost❩ Linux: No supported package manager found for installing certutil on Linux (tried apt, yum, and pacman. Please install certutil manually and run Auto Encrypt Localhost again. For more instructions on installing mkcert dependencies, please see https://github.com/FiloSottile/mkcert/\n')
log(' ╰─ ⚠️ Linux: No supported package manager found for installing certutil on Linux (tried apt, yum, and pacman. Please install certutil manually and run Auto Encrypt Localhost again. For more instructions on installing mkcert dependencies, please see https://github.com/FiloSottile/mkcert/\n')
}
} catch (error) {
// There was an error and we couldn’t install the dependency. Warn the person.
log('\n ⚠️ ❨auto-encrypt-localhost❩ Linux: Failed to install nss. Please install it manually and run Auto Encrypt Localhost again if you want your certificate to work in Chrome and Firefox', error)
log(' ╰─ ⚠️ Linux: Failed to install nss. Please install it manually and run Auto Encrypt Localhost again if you want your certificate to work in Chrome and Firefox', error)
}
}
......@@ -70,17 +75,16 @@ function installCertutilOnDarwin() {
// with Firefox crashing).
try {
// Homebrew can take a long time start, show current status.
print(' 📜 ❨auto-encrypt-localhost❩ Checking if certutil dependency is installed (Darwin) using Homebrew… ')
childProcess.execSync('brew list nss >/dev/null 2>&1', options)
log(' ok.')
log(' done.')
} catch (error) {
// NSS is not installed. Install it.
try {
print(' 📜 ❨auto-encrypt-localhost❩ Installing certutil dependency (Darwin) using Homebrew… ')
print(' ╰─ Installing certutil dependency (Darwin) using Homebrew… ')
childProcess.execSync('brew install nss >/dev/null 2>&1', options)
log('done.')
} catch (error) {
log('\n ⚠️ ❨auto-encrypt-localhost❩ macOS: Failed to install nss via Homebrew. Please install it manually and run Auto Encrypt Localhost again if you want your certificate to work in Firefox', error)
log(' ╰─ ⚠️ macOS: Failed to install nss via Homebrew. Please install it manually and run Auto Encrypt Localhost again if you want your certificate to work in Firefox', error)
return
}
}
......@@ -88,7 +92,7 @@ function installCertutilOnDarwin() {
// Untested. This is based on the documentation at https://guide.macports.org/#using.port.installed. I don’t have MacPorts installed
// and it doesn’t play well with Homebrew so I won’t be testing this anytime soon. If you do, please let me know how it works
// by opening an issue on https://github.com/indie-mirror/https-server/issues
log('\n 🤪 ❨auto-encrypt-localhost❩ Attempting to install required dependency using MacPorts. This is currently untested. If it works (or blows up) for you, I’d appreciate it if you could open an issue at https://github.com/indie-mirror/https-server/issues and let me know. Thanks! – Aral\n')
log(' ╰─ 🤪 Attempting to install required dependency using MacPorts. This is currently untested. If it works (or blows up) for you, I’d appreciate it if you could open an issue at https://github.com/indie-mirror/https-server/issues and let me know. Thanks! – Aral\n')
try {
childProcess.execSync('port installed nss', options)
......@@ -97,13 +101,13 @@ function installCertutilOnDarwin() {
try {
childProcess.execSync('sudo port install nss', options)
} catch (error) {
log('\n ⚠️ ❨auto-encrypt-localhost❩ macOS: Failed to install nss via MacPorts. Please install it manually and run Auto Encrypt Localhost again if you want your certificate to work in Firefox', error)
log(' ╰─ ⚠️ macOS: Failed to install nss via MacPorts. Please install it manually and run Auto Encrypt Localhost again if you want your certificate to work in Firefox', error)
return
}
}
} else {
// Neither Homebrew nor MacPorts is installed. Warn the person.
log('\n ⚠️ ❨auto-encrypt-localhost❩ macOS: Cannot install certutil (nss) as you don’t have Homebrew or MacPorts installed.\n\n If you want your certificate to work in Firefox, please install one of those package managers and then install nss manually:\n\n * Homebrew (https://brew.sh): brew install nss\n * MacPorts(https://macports.org): sudo port install nss\n')
log(' ╰─ ⚠️ macOS: Cannot install certutil (nss) as you don’t have Homebrew or MacPorts installed.\n\n If you want your certificate to work in Firefox, please install one of those package managers and then install nss manually:\n ╰─ * Homebrew (https://brew.sh): brew install nss ╰─ * MacPorts(https://macports.org): sudo port install nss\n')
return
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment