Commit 93ee00bb authored by Aral Balkan's avatar Aral Balkan
Browse files

Make console output consistent again

parent b4c48b50
......@@ -21,6 +21,7 @@
import https from 'https'
import os from 'os'
import path from 'path'
import { log, print } from '../lib/util/log.js'
import { version, binaryName } from '../lib/mkcert.js'
......@@ -72,9 +73,9 @@ async function secureStreamToFile (url, filePath) {
const settingsPath = path.join(os.homedir(), '.small-tech.org', 'auto-encrypt-localhost')
console.log(' 🔒️ Auto Encrypt Localhost (postinstall)')
console.log(' ────────────────────────────────────────────────────────────────────────')
process.stdout.write(` ╰─ Installing mkcert v${version} binary… `)
log(' 🔒️ Auto Encrypt Localhost (postinstall)')
log(' ────────────────────────────────────────────────────────────────────────')
print(` ╰─ Installing mkcert v${version} binary… `)
// Delete and recreate the mkcert-bin folder.
fs.removeSync(settingsPath)
......@@ -89,6 +90,6 @@ await secureStreamToFile(binaryRedirectUrl, binaryPath)
// Make the binary executable.
fs.chmodSync(binaryPath, 0o755)
process.stdout.write('done.\n')
print('done.\n')
console.log(' ────────────────────────────────────────────────────────────────────────')
log(' ────────────────────────────────────────────────────────────────────────')
......@@ -6,7 +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(` 📜 ❨auto-encrypt-localhost❩ Installing certutil if necessary… `)
print(` 📜 ❨auto-encrypt-localhost❩ Installing certutil if necessary… `)
const platform = os.platform()
if (platform === 'linux') {
installCertutilOnLinux()
......@@ -15,10 +15,9 @@ export default function installCertutil () {
} else if (platform === 'win32') {
// Do nothing. According to the mkcert documentation, certutil is not
// required on Windows.
console.log('done.')
} else {
// Unknown platform. This should have been caught earlier. Panic.
throw new Error(' ╰─ 🤯 Panic: Unknown platform detected.', platform)
throw new Error(' 🤯 ❨auto-encrypt-localhost❩ Panic: Unknown platform detected.', platform)
}
}
......@@ -32,11 +31,11 @@ export default function installCertutil () {
function installCertutilOnLinux () {
if (commandExists('certutil')) {
// Already installed
process.stdout.write('done.\n')
return
print('done.\n')
return
}
print('\n ╰─ Installing certutil dependency (Linux) ')
print(' 💽️ ❨auto-encrypt-localhost❩ Installing certutil dependency (Linux) ')
let options = { env: process.env }
try {
if (commandExists('apt')) {
......@@ -45,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(' ╰─ 🤪 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(' 🤪 ❨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')
childProcess.execSync('sudo yum install nss-tools', options)
log(' ╰─ Certutil installed using yum.')
log(' ✔️ ❨auto-encrypt-localhost❩ Certutil installed using yum.')
} else if (commandExists('pacman')) {
childProcess.execSync('sudo pacman -S nss', options)
log(' ╰─ Certutil installed using pacman.')
log(' ✔️ ❨auto-encrypt-localhost❩ Certutil installed using pacman.')
} else {
// Neither Homebrew nor MacPorts is installed. Warn the person.
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')
log(' ⚠️ ❨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')
}
} catch (error) {
// There was an error and we couldn’t install the dependency. Warn the person.
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)
log(' ⚠️ ❨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)
}
}
......@@ -81,11 +80,11 @@ function installCertutilOnDarwin() {
} catch (error) {
// NSS is not installed. Install it.
try {
print(' ╰─ Installing certutil dependency (Darwin) using Homebrew… ')
print(' 💽️ ❨auto-encrypt-localhost❩Installing certutil dependency (Darwin) using Homebrew… ')
childProcess.execSync('brew install nss >/dev/null 2>&1', options)
log('done.')
} catch (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)
log(' ⚠️ ❨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)
return
}
}
......@@ -93,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(' ╰─ 🤪 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(' 🤪 ❨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')
try {
childProcess.execSync('port installed nss', options)
......@@ -102,13 +101,13 @@ function installCertutilOnDarwin() {
try {
childProcess.execSync('sudo port install nss', options)
} catch (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)
log(' ⚠️ ❨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)
return
}
}
} else {
// Neither Homebrew nor MacPorts is installed. Warn the person.
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')
log(' ⚠️ ❨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 ╰─ * 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