Add support for SAPI setup

This commit is contained in:
Shivam Mathur 2020-12-14 08:30:55 +05:30
parent 7e68292070
commit 6e94dfca93
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
17 changed files with 495 additions and 28 deletions

View File

@ -107,16 +107,16 @@ describe('Utils tests', () => {
await cleanup(script_path); await cleanup(script_path);
}); });
it('checking extensionArray', async () => { it('checking packageArray', async () => {
expect(await utils.extensionArray('a, b, php_c, php-d')).toEqual([ expect(await utils.packageArray('a, b, php_c, php-d')).toEqual([
'a', 'a',
'b', 'b',
'c', 'c',
'd' 'd'
]); ]);
expect(await utils.extensionArray('')).toEqual([]); expect(await utils.packageArray('')).toEqual([]);
expect(await utils.extensionArray(' ')).toEqual([]); expect(await utils.packageArray(' ')).toEqual([]);
}); });
it('checking INIArray', async () => { it('checking INIArray', async () => {

View File

@ -18,6 +18,9 @@ inputs:
coverage: coverage:
description: 'Setup code coverage driver.' description: 'Setup code coverage driver.'
required: false required: false
sapi:
description: 'Setup PHP Server API.'
required: false
tools: tools:
description: 'Setup popular tools globally.' description: 'Setup popular tools globally.'
required: false required: false

98
dist/index.js vendored
View File

@ -1808,7 +1808,7 @@ const utils = __importStar(__nccwpck_require__(314));
* @param version * @param version
*/ */
async function addExtensionDarwin(extension_csv, version) { async function addExtensionDarwin(extension_csv, version) {
const extensions = await utils.extensionArray(extension_csv); const extensions = await utils.packageArray(extension_csv);
let add_script = '\n'; let add_script = '\n';
let remove_script = ''; let remove_script = '';
await utils.asyncForEach(extensions, async function (extension) { await utils.asyncForEach(extensions, async function (extension) {
@ -1877,7 +1877,7 @@ exports.addExtensionDarwin = addExtensionDarwin;
* @param version * @param version
*/ */
async function addExtensionWindows(extension_csv, version) { async function addExtensionWindows(extension_csv, version) {
const extensions = await utils.extensionArray(extension_csv); const extensions = await utils.packageArray(extension_csv);
let add_script = '\n'; let add_script = '\n';
let remove_script = ''; let remove_script = '';
await utils.asyncForEach(extensions, async function (extension) { await utils.asyncForEach(extensions, async function (extension) {
@ -1961,7 +1961,7 @@ exports.addExtensionWindows = addExtensionWindows;
* @param version * @param version
*/ */
async function addExtensionLinux(extension_csv, version) { async function addExtensionLinux(extension_csv, version) {
const extensions = await utils.extensionArray(extension_csv); const extensions = await utils.packageArray(extension_csv);
let add_script = '\n'; let add_script = '\n';
let remove_script = ''; let remove_script = '';
await utils.asyncForEach(extensions, async function (extension) { await utils.asyncForEach(extensions, async function (extension) {
@ -2095,6 +2095,7 @@ const core = __importStar(__nccwpck_require__(186));
const config = __importStar(__nccwpck_require__(373)); const config = __importStar(__nccwpck_require__(373));
const coverage = __importStar(__nccwpck_require__(84)); const coverage = __importStar(__nccwpck_require__(84));
const extensions = __importStar(__nccwpck_require__(587)); const extensions = __importStar(__nccwpck_require__(587));
const sapi = __importStar(__nccwpck_require__(489));
const tools = __importStar(__nccwpck_require__(905)); const tools = __importStar(__nccwpck_require__(905));
const utils = __importStar(__nccwpck_require__(314)); const utils = __importStar(__nccwpck_require__(314));
/** /**
@ -2113,7 +2114,11 @@ async function getScript(filename, version, os_version) {
const ini_values_csv = await utils.getInput('ini-values', false); const ini_values_csv = await utils.getInput('ini-values', false);
const coverage_driver = await utils.getInput('coverage', false); const coverage_driver = await utils.getInput('coverage', false);
const tools_csv = await utils.getInput('tools', false); const tools_csv = await utils.getInput('tools', false);
const sapi_csv = await utils.getInput('sapi', false);
let script = await utils.readScript(filename); let script = await utils.readScript(filename);
if (sapi_csv) {
script += await sapi.addSAPI(sapi_csv, os_version);
}
script += await tools.addTools(tools_csv, version, os_version); script += await tools.addTools(tools_csv, version, os_version);
if (extension_csv) { if (extension_csv) {
script += await extensions.addExtension(extension_csv, version, os_version); script += await extensions.addExtension(extension_csv, version, os_version);
@ -2159,6 +2164,77 @@ exports.run = run;
}); });
/***/ }),
/***/ 489:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.addSAPI = exports.getSapiList = void 0;
const utils = __importStar(__nccwpck_require__(314));
async function getSapiList(sapi_csv) {
const sapi_list = await utils.packageArray(sapi_csv);
const servers = sapi_list.filter(sapi => /.*:.*/.test(sapi));
return [servers[servers.length - 1]].concat(sapi_list.filter(sapi => /.*[^:].*/.test(sapi)));
}
exports.getSapiList = getSapiList;
/**
* Function to set sapi
*
* @param sapi_csv
* @param os_version
*/
async function addSAPI(sapi_csv, os_version) {
let script = '\n' + (await utils.stepLog('Setup SAPI', os_version));
let sapi_list;
switch (true) {
case sapi_csv.split(':').length - 1 > 1:
sapi_list = await getSapiList(sapi_csv);
script +=
'\n' +
utils.log('Multiple SAPI with web servers specified, choosing the last one ' +
sapi_list[0], os_version, 'warning');
break;
default:
sapi_list = await utils.packageArray(sapi_csv);
}
await utils.asyncForEach(sapi_list, async function (sapi) {
sapi = sapi.toLowerCase();
switch (os_version) {
case 'linux':
case 'darwin':
script += '\nadd_sapi ' + sapi;
break;
case 'win32':
script += '\nAdd-Sapi ' + sapi;
break;
}
});
return script;
}
exports.addSAPI = addSAPI;
/***/ }), /***/ }),
/***/ 905: /***/ 905:
@ -2654,7 +2730,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.customPackage = exports.scriptTool = exports.scriptExtension = exports.joins = exports.getCommand = exports.getUnsupportedLog = exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.writeScript = exports.readScript = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.parseVersion = exports.fetch = exports.getInput = exports.readEnv = void 0; exports.customPackage = exports.scriptTool = exports.scriptExtension = exports.joins = exports.getCommand = exports.getUnsupportedLog = exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.packageArray = exports.writeScript = exports.readScript = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.parseVersion = exports.fetch = exports.getInput = exports.readEnv = void 0;
const fs = __importStar(__nccwpck_require__(747)); const fs = __importStar(__nccwpck_require__(747));
const https = __importStar(__nccwpck_require__(211)); const https = __importStar(__nccwpck_require__(211));
const path = __importStar(__nccwpck_require__(622)); const path = __importStar(__nccwpck_require__(622));
@ -2847,18 +2923,18 @@ exports.writeScript = writeScript;
/** /**
* Function to break extension csv into an array * Function to break extension csv into an array
* *
* @param extension_csv * @param package_csv
*/ */
async function extensionArray(extension_csv) { async function packageArray(package_csv) {
switch (extension_csv) { switch (package_csv) {
case '': case '':
case ' ': case ' ':
return []; return [];
default: default:
return extension_csv return package_csv
.split(',') .split(',')
.map(function (extension) { .map(function (package_name) {
return extension return package_name
.trim() .trim()
.toLowerCase() .toLowerCase()
.replace(/^php[-_]/, ''); .replace(/^php[-_]/, '');
@ -2866,7 +2942,7 @@ async function extensionArray(extension_csv) {
.filter(Boolean); .filter(Boolean);
} }
} }
exports.extensionArray = extensionArray; exports.packageArray = packageArray;
/** /**
* Function to break csv into an array * Function to break csv into an array
* *

View File

@ -0,0 +1,3 @@
LoadModule phpPHP_MAJOR_module PHP_DIR\PHP_APACHE_DLL
AddHandler application/x-httpd-php .php
PHPIniDir PHP_DIR

View File

@ -0,0 +1,8 @@
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule authnz_fcgi_module modules/mod_authnz_fcgi.so
<FilesMatch "\.php$">
<If "-f %{REQUEST_FILENAME}">
SetHandler "proxy:fcgi://127.0.0.1:9000/"
</If>
</FilesMatch>

36
src/configs/nginx.conf Normal file
View File

@ -0,0 +1,36 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}

View File

@ -0,0 +1,5 @@
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "/var/www/html"
ServerName localhost
</VirtualHost>

View File

@ -0,0 +1,7 @@
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

View File

@ -0,0 +1,22 @@
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.php;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/phpPHP_VERSION-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}

View File

@ -10,7 +10,7 @@ export async function addExtensionDarwin(
extension_csv: string, extension_csv: string,
version: string version: string
): Promise<string> { ): Promise<string> {
const extensions: Array<string> = await utils.extensionArray(extension_csv); const extensions: Array<string> = await utils.packageArray(extension_csv);
let add_script = '\n'; let add_script = '\n';
let remove_script = ''; let remove_script = '';
await utils.asyncForEach(extensions, async function (extension: string) { await utils.asyncForEach(extensions, async function (extension: string) {
@ -115,7 +115,7 @@ export async function addExtensionWindows(
extension_csv: string, extension_csv: string,
version: string version: string
): Promise<string> { ): Promise<string> {
const extensions: Array<string> = await utils.extensionArray(extension_csv); const extensions: Array<string> = await utils.packageArray(extension_csv);
let add_script = '\n'; let add_script = '\n';
let remove_script = ''; let remove_script = '';
await utils.asyncForEach(extensions, async function (extension: string) { await utils.asyncForEach(extensions, async function (extension: string) {
@ -229,7 +229,7 @@ export async function addExtensionLinux(
extension_csv: string, extension_csv: string,
version: string version: string
): Promise<string> { ): Promise<string> {
const extensions: Array<string> = await utils.extensionArray(extension_csv); const extensions: Array<string> = await utils.packageArray(extension_csv);
let add_script = '\n'; let add_script = '\n';
let remove_script = ''; let remove_script = '';
await utils.asyncForEach(extensions, async function (extension: string) { await utils.asyncForEach(extensions, async function (extension: string) {

View File

@ -3,6 +3,7 @@ import * as core from '@actions/core';
import * as config from './config'; import * as config from './config';
import * as coverage from './coverage'; import * as coverage from './coverage';
import * as extensions from './extensions'; import * as extensions from './extensions';
import * as sapi from './sapi';
import * as tools from './tools'; import * as tools from './tools';
import * as utils from './utils'; import * as utils from './utils';
@ -26,10 +27,13 @@ export async function getScript(
const ini_values_csv: string = await utils.getInput('ini-values', false); const ini_values_csv: string = await utils.getInput('ini-values', false);
const coverage_driver: string = await utils.getInput('coverage', false); const coverage_driver: string = await utils.getInput('coverage', false);
const tools_csv: string = await utils.getInput('tools', false); const tools_csv: string = await utils.getInput('tools', false);
const sapi_csv: string = await utils.getInput('sapi', false);
let script: string = await utils.readScript(filename); let script: string = await utils.readScript(filename);
if (sapi_csv) {
script += await sapi.addSAPI(sapi_csv, os_version);
}
script += await tools.addTools(tools_csv, version, os_version); script += await tools.addTools(tools_csv, version, os_version);
if (extension_csv) { if (extension_csv) {
script += await extensions.addExtension(extension_csv, version, os_version); script += await extensions.addExtension(extension_csv, version, os_version);
} }

51
src/sapi.ts Normal file
View File

@ -0,0 +1,51 @@
import * as utils from './utils';
export async function getSapiList(sapi_csv: string): Promise<Array<string>> {
const sapi_list: Array<string> = await utils.packageArray(sapi_csv);
const servers: Array<string> = sapi_list.filter(sapi => /.*:.*/.test(sapi));
return [servers[servers.length - 1]].concat(
sapi_list.filter(sapi => /.*[^:].*/.test(sapi))
);
}
/**
* Function to set sapi
*
* @param sapi_csv
* @param os_version
*/
export async function addSAPI(
sapi_csv: string,
os_version: string
): Promise<string> {
let script: string = '\n' + (await utils.stepLog('Setup SAPI', os_version));
let sapi_list: Array<string>;
switch (true) {
case sapi_csv.split(':').length - 1 > 1:
sapi_list = await getSapiList(sapi_csv);
script +=
'\n' +
utils.log(
'Multiple SAPI with web servers specified, choosing the last one ' +
sapi_list[0],
os_version,
'warning'
);
break;
default:
sapi_list = await utils.packageArray(sapi_csv);
}
await utils.asyncForEach(sapi_list, async function (sapi: string) {
sapi = sapi.toLowerCase();
switch (os_version) {
case 'linux':
case 'darwin':
script += '\nadd_sapi ' + sapi;
break;
case 'win32':
script += '\nAdd-Sapi ' + sapi;
break;
}
});
return script;
}

View File

@ -257,9 +257,11 @@ add_composertool() {
fi fi
} }
# Function to get PHP version in semver format. # Function to get versions of PHP binaries in semver format.
php_semver() { php_semver() {
php"$version" -v | grep -Eo -m 1 "[0-9]+\.[0-9]+\.[0-9]+" | head -n 1 binary=${1:-"php$version"}
arg=${2:-'-v'}
"$binary" "$arg" | grep -Eo -m 1 "[0-9]+\.[0-9]+\.[0-9]+" | head -n 1
} }
# Function to get the tag for a php version. # Function to get the tag for a php version.

View File

@ -31,6 +31,23 @@ add_ppa() {
fi fi
} }
# Function to add SAPI
add_sapi() {
sapi=$1
status='true'
if [ "$sapi" != "cli" ]; then
# shellcheck source=.
. "${dist}"/../src/scripts/sapi.sh
setup_sapi "$sapi" >/dev/null 2>&1
fi
check_sapi "$sapi"
if check_sapi "$sapi"; then
add_log "${tick:?}" "$sapi" "Added $sapi"
else
add_log "${cross:?}" "$sapi" "Could not setup $sapi"
fi
}
# Function to update the package lists. # Function to update the package lists.
update_lists() { update_lists() {
if [ ! -e /tmp/setup_php ]; then if [ ! -e /tmp/setup_php ]; then

View File

@ -0,0 +1,116 @@
#!/bin/bash
install_httpd() {
sudo mkdir -p /var/www/html
sudo chown -R _www:_www /var/www
brew services stop nginx 2>/dev/null || true
if ! command -v httpd >/dev/null; then
brew install httpd
fi
sudo sed -Ei '' 's/Listen.*/Listen 80/' "$httpd_conf"
sudo sed -Ei '' 's/DirectoryIndex.*/DirectoryIndex index.php index.html/' "$httpd_conf"
}
install_nginx() {
sudo mkdir -p /var/www/html
sudo chown -R "$(id -un)":"$(id -gn)" /var/www
brew services stop httpd 2>/dev/null || true
if ! command -v nginx >/dev/null; then
brew install nginx
fi
sudo sed -Ei '' 's/listen.*/listen 80;/' "$nginx_conf"
}
setup_sapi() {
sapi=$1
conf_dir="${dist:?}"/../src/configs
case $sapi in
apache*:apache*)
install_httpd
(
echo "LoadModule proxy_module lib/httpd/modules/mod_proxy.so"
echo "LoadModule proxy_module lib/httpd/modules/mod_proxy_fcgi.so"
) | sudo tee -a "$httpd_conf"
echo "Include $httpd_extra/httpd-php.conf" | sudo tee -a "$httpd_conf"
sudo cp "$conf_dir"/default_apache /etc/apache2/sites-available/000-default.conf
sudo a2dismod mpm_event 2>/dev/null || true
sudo a2enmod mpm_prefork php"${version:?}"
sudo service apache2 restart
;;
fpm:apache*)
install_httpd
sudo cp "$conf_dir"/default_apache /etc/apache2/sites-available/000-default.conf
sudo a2dismod php"${version:?}" 2>/dev/null || true
sudo a2enmod proxy_fcgi
sudo a2enconf php"${version:?}"-fpm
sudo service apache2 restart
;;
cgi:apache*)
install_httpd
sudo cp "$conf_dir"/default_apache /etc/apache2/sites-available/000-default.conf
echo "Action application/x-httpd-php /cgi-bin/php${version:?}" | sudo tee -a /etc/apache2/conf-available/php"${version:?}"-cgi.conf
sudo a2dismod php"${version:?}" mpm_event 2>/dev/null || true
sudo a2enmod mpm_prefork actions cgi
sudo a2disconf php"${version:?}"-fpm 2>/dev/null || true
sudo a2enconf php"${version:?}"-cgi
sudo service apache2 restart
;;
fpm:nginx)
install_nginx
sudo cp "$conf_dir"/default_nginx /etc/nginx/sites-available/default
sudo sed -i "s/PHP_VERSION/${version:?}/" /etc/nginx/sites-available/default
sudo service nginx restart
;;
apache* | fpm | cgi | phpdbg) ;;
esac
}
check_service() {
service=$1
if ! pidof "$service"; then
return 1
fi
(
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "$service" "Click to check $service status"
sudo service "$service" status
echo "::endgroup::"
) | sudo tee -a /tmp/sapi.log >/dev/null 2>&1
return 0
}
check_version() {
sapi=$1
sapi_version=$(php_semver "$sapi")
if [ ${sapi_version%.*} != "${version:?}" ]; then
return 1
fi
add_log "${tick:?}" "$sapi" "Added $sapi $sapi_version" | sudo tee -a /tmp/sapi.log >/dev/null 2>&1
return 0
}
check_sapi() {
sapi=$1
sudo rm /tmp/sapi.log
if [[ "$sapi" =~ fpm|cgi ]]; then status=$(check_version php-"$sapi"); fi
if [[ "$sapi" =~ ^phpdbg$ ]]; then status=$(check_version phpdbg); fi
if [[ "$sapi" =~ .*fpm.* ]]; then status=$(check_service php"${version:?}"-fpm); fi
if [[ "$sapi" =~ .*:apache.* ]]; then status=$(check_service apache2); fi
if [[ "$sapi" =~ .*:nginx.* ]]; then status=$(check_service nginx); fi
if [ "$status" = "0" ]; then
if [[ "$sapi" =~ .*:.* ]]; then
add_log "${tick:?}" "$sapi" "Added $sapi"
fi
cat /tmp/sapi.log && sudo rm /tmp/sapi.log
else
add_log "${cross:?}" "$sapi" "Could not setup $sapi"
fi
}
httpd_conf=${brew_prefix:?}/etc/httpd/httpd.conf
httpd_extra=${brew_prefix:?}/etc/httpd/extra
nginx_conf=${brew_prefix:?}/etc/nginx/nginx.conf

View File

@ -0,0 +1,117 @@
#!/bin/bash
install_apache2() {
sudo mkdir -p /var/www/html
sudo service nginx stop 2>/dev/null || true
if ! command -v apache2 >/dev/null; then
install_packages apache2-bin apache2 -y;
else
if ! [[ "$(apache2 -v 2>/dev/null | grep -Eo "([0-9]+\.[0-9]+)")" =~ 2.[4-9] ]]; then
sudo "${debconf_fix:?}" apt-get purge apache* apache-* >/dev/null
install_packages apache2-bin apache2 -y;
fi
fi
}
install_nginx() {
sudo mkdir -p /var/www/html
sudo service apache2 stop 2>/dev/null || true
if ! command -v nginx >/dev/null; then
install_packages nginx -y
fi
}
setup_sapi() {
sapi=$1
conf_dir="${dist:?}"/../src/configs
if [[ "${version:?}" =~ ${old_versions:?}|${nightly_versions:?} ]]; then
switch_sapi "$sapi"
else
case $sapi in
apache*:apache*)
install_apache2
sudo cp "$conf_dir"/default_apache /etc/apache2/sites-available/000-default.conf
install_packages libapache2-mod-php"${version:?}" -y
sudo a2dismod mpm_event 2>/dev/null || true
sudo a2enmod mpm_prefork php"${version:?}"
sudo service apache2 restart
;;
fpm:apache*)
install_apache2
sudo cp "$conf_dir"/default_apache /etc/apache2/sites-available/000-default.conf
install_packages libapache2-mod-fcgid php"${version:?}"-fpm -y
sudo a2dismod php"${version:?}" 2>/dev/null || true
sudo a2enmod proxy_fcgi
sudo a2enconf php"${version:?}"-fpm
sudo service apache2 restart
;;
cgi:apache*)
install_apache2
install_packages php"${version:?}"-cgi -y
sudo cp "$conf_dir"/default_apache /etc/apache2/sites-available/000-default.conf
echo "Action application/x-httpd-php /cgi-bin/php${version:?}" | sudo tee -a /etc/apache2/conf-available/php"${version:?}"-cgi.conf
sudo a2dismod php"${version:?}" mpm_event 2>/dev/null || true
sudo a2enmod mpm_prefork actions cgi
sudo a2disconf php"${version:?}"-fpm 2>/dev/null || true
sudo a2enconf php"${version:?}"-cgi
sudo service apache2 restart
;;
fpm:nginx)
install_nginx
install_packages php"${version:?}"-fpm -y
sudo cp "$conf_dir"/default_nginx /etc/nginx/sites-available/default
sudo sed -i "s/PHP_VERSION/${version:?}/" /etc/nginx/sites-available/default
sudo service nginx restart
;;
apache*)
install_packages libapache2-mod-php"${version:?}" -y
;;
fpm|embed|cgi|phpdbg)
install_packages php"${version:?}"-"$sapi" -y
;;
esac
fi
}
check_service() {
service=$1
if ! pidof "$service"; then
return 1
fi
(
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "$service" "Click to check $service status"
sudo service "$service" status
echo "::endgroup::"
) | sudo tee -a /tmp/sapi.log >/dev/null 2>&1
return 0
}
check_version() {
sapi=$1
sapi_version=$(php_semver "$sapi")
if [ "${sapi_version%.*}" != "${version:?}" ]; then
return 1;
fi
add_log "${tick:?}" "$sapi" "Added $sapi $sapi_version" | sudo tee -a /tmp/sapi.log >/dev/null 2>&1
return 0
}
check_sapi() {
sapi=$1
sudo rm /tmp/sapi.log
if [[ "$sapi" =~ fpm|cgi ]]; then status=$(check_version php-"$sapi"); fi
if [[ "$sapi" =~ ^phpdbg$ ]]; then status=$(check_version phpdbg); fi
if [[ "$sapi" =~ .*fpm.* ]]; then status=$(check_service php"${version:?}"-fpm); fi
if [[ "$sapi" =~ .*:apache.* ]]; then status=$(check_service apache2); fi
if [[ "$sapi" =~ .*:nginx.* ]]; then status=$(check_service nginx); fi
if [ "$status" = "0" ]; then
if [[ "$sapi" =~ .*:.* ]]; then
add_log "${tick:?}" "$sapi" "Added $sapi"
fi
cat /tmp/sapi.log && sudo rm /tmp/sapi.log
else
add_log "${cross:?}" "$sapi" "Could not setup $sapi"
fi
}

View File

@ -234,20 +234,20 @@ export async function writeScript(
/** /**
* Function to break extension csv into an array * Function to break extension csv into an array
* *
* @param extension_csv * @param package_csv
*/ */
export async function extensionArray( export async function packageArray(
extension_csv: string package_csv: string
): Promise<Array<string>> { ): Promise<Array<string>> {
switch (extension_csv) { switch (package_csv) {
case '': case '':
case ' ': case ' ':
return []; return [];
default: default:
return extension_csv return package_csv
.split(',') .split(',')
.map(function (extension: string) { .map(function (package_name: string) {
return extension return package_name
.trim() .trim()
.toLowerCase() .toLowerCase()
.replace(/^php[-_]/, ''); .replace(/^php[-_]/, '');