2021-05-10 14:18:05 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
const os = require("os")
|
|
|
|
const exec = require("child_process").exec
|
|
|
|
const fs = require("fs")
|
|
|
|
const platform = os.platform()
|
|
|
|
|
|
|
|
const windows = platform === "win32"
|
|
|
|
const mac = platform === "darwin"
|
|
|
|
const linux = platform === "linux"
|
|
|
|
|
|
|
|
function execute(command) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
exec(command, (err, stdout) => resolve(linux ? !!stdout : true))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-10 14:19:09 +02:00
|
|
|
async function commandExistsUnix(command) {
|
2021-05-10 14:18:05 +02:00
|
|
|
const unixCmd = `command -v ${command} 2>/dev/null && { echo >&1 ${command}; exit 0; }`
|
|
|
|
return execute(command)
|
|
|
|
}
|
|
|
|
|
2021-05-10 14:19:09 +02:00
|
|
|
async function commandExistsWindows(command) {
|
2021-05-10 14:18:05 +02:00
|
|
|
if (/[\x00-\x1f<>:"|?*]/.test(command)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return execute(`where ${command}`)
|
|
|
|
}
|
|
|
|
|
2021-05-10 14:19:09 +02:00
|
|
|
function commandExists(command) {
|
|
|
|
return windows ? commandExistsWindows(command) : commandExistsUnix(command)
|
2021-05-10 14:18:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function init() {
|
|
|
|
const docker = commandExists("docker")
|
|
|
|
const dockerCompose = commandExists("docker-compose")
|
|
|
|
if (docker && dockerCompose) {
|
|
|
|
console.log("Docker installed - continuing.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (mac) {
|
2021-05-10 14:19:09 +02:00
|
|
|
console.log(
|
|
|
|
"Please install docker by visiting: https://docs.docker.com/docker-for-mac/install/"
|
|
|
|
)
|
2021-05-10 14:18:05 +02:00
|
|
|
} else if (windows) {
|
2021-05-10 14:19:09 +02:00
|
|
|
console.log(
|
|
|
|
"Please install docker by visiting: https://docs.docker.com/docker-for-windows/install/"
|
|
|
|
)
|
2021-05-10 14:18:05 +02:00
|
|
|
} else if (linux) {
|
|
|
|
console.log("Beginning automated linux installation.")
|
|
|
|
await execute(`./hosting/scripts/linux/get-docker.sh`)
|
|
|
|
await execute(`./hosting/scripts/linux/get-docker-compose.sh`)
|
|
|
|
} else {
|
2021-05-10 14:19:09 +02:00
|
|
|
console.error(
|
|
|
|
"Platform unknown - please look online for information about installing docker for our OS."
|
|
|
|
)
|
2021-05-10 14:18:05 +02:00
|
|
|
}
|
|
|
|
console.log("Once installation complete please re-run the setup script.")
|
|
|
|
process.exit(-1)
|
|
|
|
}
|
|
|
|
init()
|