-
-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathsystem-stack.js
71 lines (61 loc) · 2.6 KB
/
system-stack.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
const chalk = require('chalk');
const execa = require('execa');
const errors = require('../../../errors');
const taskTitle = 'Checking operating system compatibility';
const nginxProgramName = process.env.NGINX_PROGRAM_NAME || 'nginx';
function systemStack(ctx, task) {
let promise;
if (!ctx.system.platform.linux) {
promise = Promise.reject({message: 'Operating system is not Linux'});
} else {
// TODO: refactor to use ctx.system.operatingSystem
promise = execa.shell('lsb_release -a').catch(
() => Promise.reject({message: 'Linux version is not Ubuntu 16 or 18'})
).then((result) => {
if (!result.stdout || !result.stdout.match(/Ubuntu (?:16|18)/)) {
return Promise.reject({message: 'Linux version is not Ubuntu 16 or 18'});
}
return ctx.ui.listr([{
title: 'Checking systemd is installed',
task: () => execa.shell('dpkg -l | grep systemd')
.catch(() => Promise.reject({missing: 'systemd'}))
}, {
title: `Checking ${nginxProgramName} is installed`,
task: () => execa.shell(`dpkg -l | grep ${nginxProgramName}`)
.catch(() => Promise.reject({missing: nginxProgramName}))
}], ctx, {
concurrent: true,
exitOnError: false,
renderer: ctx.ui.verbose ? 'verbose' : 'silent'
}).catch(error => Promise.reject({
message: `Missing package(s): ${error.errors.map(e => e.missing).join(', ')}`
}));
});
}
return promise.catch((error) => {
ctx.ui.log(
`System checks failed with message: '${error.message}'
Some features of Ghost-CLI may not work without additional configuration.
For local installs we recommend using \`ghost install local\` instead.`,
'yellow'
);
return ctx.ui.confirm(chalk.blue('Continue anyway?'), false).then((confirmed) => {
if (confirmed) {
task.skip('System stack check skipped');
return Promise.resolve();
}
return Promise.reject(new errors.SystemError({
message: `System stack checks failed with message: '${error.message}'`,
task: taskTitle
}));
});
});
}
module.exports = {
title: taskTitle,
task: systemStack,
enabled: ctx => !ctx.local && !(ctx.instance && ctx.instance.process.name === 'local'),
skip: ctx => !ctx.isDoctorCommand && ctx.argv && !ctx.argv.stack,
category: ['install']
};