|
1 | | -import shell from 'shelljs'; |
| 1 | +import { execaCommandSync } from 'execa'; |
2 | 2 |
|
3 | 3 | import { getPHPErrorLogPath } from './path'; |
4 | 4 |
|
5 | 5 | import PHPVersionNotFoundError from '@/error/PHPVersionNotFoundError'; |
6 | 6 | import RestartServiceError from '@/error/RestartServiceError'; |
7 | 7 |
|
8 | 8 | export function isPHPInstalled() { |
9 | | - return shell.which('php'); |
| 9 | + return execaCommandSync('which php', { reject: false }).exitCode === 0; |
10 | 10 | } |
11 | 11 |
|
12 | 12 | export function isMySQLInstalled() { |
13 | | - return shell.which('mysqld'); |
| 13 | + return execaCommandSync('which mysqld', { reject: false }).exitCode === 0; |
14 | 14 | } |
15 | 15 |
|
16 | 16 | export function restartNginxService() { |
17 | | - if (shell.exec(`systemctl restart nginx`).code !== 0) { |
| 17 | + if (execaCommandSync('systemctl restart nginx', { reject: false }).exitCode !== 0) { |
18 | 18 | throw new RestartServiceError('nginx'); |
19 | 19 | } |
20 | 20 | } |
21 | 21 |
|
22 | 22 | export function restartPHPFPMService(phpVer: string) { |
23 | | - if (shell.exec(`systemctl restart php${phpVer}-fpm`).code !== 0) { |
| 23 | + if (execaCommandSync(`systemctl restart php${phpVer}-fpm`, { reject: false }).exitCode !== 0) { |
24 | 24 | throw new RestartServiceError('php-fpm'); |
25 | 25 | } |
26 | 26 | } |
27 | 27 |
|
28 | 28 | export function createPHPErrorLogFile(phpVer: string, identity: string) { |
29 | 29 | const path = getPHPErrorLogPath(phpVer, identity); |
30 | | - shell.touch(path); |
31 | | - shell.exec(`chown ${identity}:${identity} ${path}`); |
| 30 | + execaCommandSync(`touch ${path}`); |
| 31 | + execaCommandSync(`chown ${identity}:${identity} ${path}`); |
32 | 32 | } |
33 | 33 |
|
34 | 34 | export function setWpInstalledPathPermission(wpInstalledPath: string, identity: string) { |
35 | | - shell.exec(`chown ${identity}:${identity} -R ${wpInstalledPath}`); |
36 | | - shell.exec(`find ${wpInstalledPath} -type d -exec chmod 755 {} \;`); |
37 | | - shell.exec(`find ${wpInstalledPath} -type f -exec chmod 644 {} \;`); |
| 35 | + execaCommandSync(`chown ${identity}:${identity} -R ${wpInstalledPath}`); |
| 36 | + execaCommandSync(`find ${wpInstalledPath} -type d -exec chmod 755 {} \;`); |
| 37 | + execaCommandSync(`find ${wpInstalledPath} -type f -exec chmod 644 {} \;`); |
38 | 38 | } |
39 | 39 |
|
40 | 40 | export function createUnixUser(identity: string) { |
41 | | - if (shell.grep(identity, '/etc/passwd').code === 0) { |
| 41 | + if (execaCommandSync(`grep ${identity} /etc/passwd`, { reject: false }).exitCode === 0) { |
42 | 42 | return; |
43 | 43 | } |
44 | 44 | if ( |
45 | | - shell.exec(`adduser --system --no-create-home --group --disabled-login ${identity}`).code !== 0 |
| 45 | + execaCommandSync(`adduser --system --no-create-home --group --disabled-login ${identity}`, { |
| 46 | + reject: false, |
| 47 | + }).exitCode !== 0 |
46 | 48 | ) { |
47 | 49 | throw new Error(`Failed to create the user named ${identity}`); |
48 | 50 | } |
49 | 51 | } |
50 | 52 |
|
| 53 | +export function getPHPVersionOutput() { |
| 54 | + return execaCommandSync('php -v', { reject: false }).stdout || ''; |
| 55 | +} |
| 56 | + |
51 | 57 | export function getCurrentPHPVersion() { |
52 | | - const matches = shell.exec('php -v').stdout.match(/^PHP ([0-9]\.[0-9])/); |
| 58 | + const matches = getPHPVersionOutput().match(/^PHP ([0-9]\.[0-9])/); |
53 | 59 | if (matches === null) { |
54 | 60 | throw new PHPVersionNotFoundError('Cannot find php version using `php -v`'); |
55 | 61 | } |
|
0 commit comments