2019-03-03 22:51:52 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
var { exec } = require('./utils/exec');
|
|
|
|
var fs = require('fs');
|
|
|
|
|
2019-03-24 15:37:31 +00:00
|
|
|
async function buildDockerImages() {
|
|
|
|
console.log("[BOOTSTRAP] Building required Docker images...");
|
|
|
|
|
2019-03-03 22:51:52 +00:00
|
|
|
console.log('Build authelia-example-backend docker image.')
|
|
|
|
await exec('docker build -t authelia-example-backend example/compose/nginx/backend');
|
|
|
|
|
2019-03-24 14:15:49 +00:00
|
|
|
console.log('Build authelia-duo-api docker image.')
|
|
|
|
await exec('docker build -t authelia-duo-api example/compose/duo-api');
|
2019-03-24 15:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function checkHostsFile() {
|
|
|
|
async function checkAndFixEntry(entries, domain, ip) {
|
|
|
|
const foundEntry = entries.filter(l => l[1] == domain);
|
|
|
|
if (foundEntry.length > 0) {
|
|
|
|
if (foundEntry[0][0] == ip) {
|
|
|
|
// The entry exists and is correct.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We need to remove the entry and replace it.
|
|
|
|
console.log(`Update entry for ${domain}.`);
|
|
|
|
await exec(`cat /etc/hosts | grep -v "${domain}" | /usr/bin/sudo tee /etc/hosts > /dev/null`);
|
|
|
|
await exec(`echo "${ip} ${domain}" | /usr/bin/sudo tee -a /etc/hosts > /dev/null`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We need to add the new entry.
|
|
|
|
console.log(`Add entry for ${domain}.`);
|
|
|
|
await exec(`echo "${ip} ${domain}" | /usr/bin/sudo tee -a /etc/hosts > /dev/null`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("[BOOTSTRAP] Checking if example.com domain is forwarded to your machine...");
|
|
|
|
const actualEntries = fs.readFileSync("/etc/hosts").toString("utf-8")
|
|
|
|
.split("\n").filter(l => l !== '').map(l => l.split(" ").filter(w => w !== ''));
|
|
|
|
|
2019-03-27 22:09:01 +00:00
|
|
|
await checkAndFixEntry(actualEntries, 'login.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'admin.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'singlefactor.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'dev.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'home.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'mx1.mail.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'mx2.mail.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'public.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'secure.example.com', '192.168.240.100');
|
|
|
|
await checkAndFixEntry(actualEntries, 'mail.example.com', '192.168.240.100');
|
2019-03-24 15:37:31 +00:00
|
|
|
await checkAndFixEntry(actualEntries, 'duo.example.com', '192.168.240.100');
|
2019-03-27 22:09:01 +00:00
|
|
|
|
|
|
|
// For testing network ACLs.
|
|
|
|
await checkAndFixEntry(actualEntries, 'proxy-client1.example.com', '192.168.240.201');
|
|
|
|
await checkAndFixEntry(actualEntries, 'proxy-client2.example.com', '192.168.240.202');
|
|
|
|
await checkAndFixEntry(actualEntries, 'proxy-client3.example.com', '192.168.240.203');
|
2019-03-24 15:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function checkKubernetesDependencies() {
|
|
|
|
console.log("[BOOTSTRAP] Checking Kubernetes tools in /tmp to allow testing a Kube cluster... (no junk installed on host)");
|
2019-03-24 14:15:49 +00:00
|
|
|
|
2019-03-03 22:51:52 +00:00
|
|
|
if (!fs.existsSync('/tmp/kind')) {
|
|
|
|
console.log('Install Kind for spawning a Kubernetes cluster.');
|
|
|
|
await exec('wget https://github.com/clems4ever/kind/releases/download/0.1.0-cmic1/kind-linux-amd64 -O /tmp/kind && chmod +x /tmp/kind');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fs.existsSync('/tmp/kubectl')) {
|
|
|
|
console.log('Install Kubectl for interacting with Kubernetes.');
|
|
|
|
await exec('wget https://storage.googleapis.com/kubernetes-release/release/v1.13.0/bin/linux/amd64/kubectl -O /tmp/kubectl && chmod +x /tmp/kubectl');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 15:37:31 +00:00
|
|
|
async function main() {
|
|
|
|
await checkHostsFile();
|
|
|
|
await buildDockerImages();
|
|
|
|
await checkKubernetesDependencies();
|
|
|
|
}
|
|
|
|
|
2019-03-03 22:51:52 +00:00
|
|
|
main().catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
})
|