Skip to content

Commit

Permalink
⚙️ Update Webserver Install Script
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradSollitt committed Apr 28, 2021
1 parent bb67d8a commit 575aa78
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions scripts/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* third-party tools. Composer handles already downloaded projects so you
* can use this file first and then later switch to Composer if adding
* additional dependencies to your site.
*
*
* This specific install script is for the playground and is used
* to generate a required [app_data/.env] file.
*
Expand Down Expand Up @@ -132,7 +132,7 @@ function createVendorDir() {
/**
* Download and verify a [cacert.pem] file for HTTPS requests.
* The file will downloaded via an HTTP request and then saved
* to the system's temp directory. Everytime the file is used
* to the system's temp directory. Every time the file is used
* the contents are verified using a SHA-256 hash.
*/
function downloadCACert() {
Expand Down Expand Up @@ -276,14 +276,31 @@ function extractZip($download) {
echo 'Extracting: ' . $path . LINE_BREAK;

// Extract from Zip
$zip = new \ZipArchive;
$zip->open($path);
$success = $zip->extractTo(VENDOR_DIR);
$zip->close();
$error = null;
if (class_exists('ZipArchive')) {
$zip = new \ZipArchive;
$zip->open($path);
$success = $zip->extractTo(VENDOR_DIR);
$zip->close();
} else if (PHP_OS === 'Darwin') {
// As of early 2021 Mac includes PHP, however ZipArchive is not enabled by default
$cmd = 'unzip -o ' . escapeshellarg($path) . ' -d ' . escapeshellarg(VENDOR_DIR);
exec($cmd, $output, $return_var);
$success = ($return_var === 0);
if ($return_var !== 0) {
$error = 'Error: ' . $return_var . ', output: [' . implode(', ', $output) . ']';
}
} else {
$success = false;
$error = 'Missing PHP built-in class ZipArchive. Please check your [php.ini] file to enable or install it.';
}

// Check Result
if ($success) {
echo 'File extracted successfully' . LINE_BREAK;
if ($error !== null) {
echo $error . LINE_BREAK;
}
} else {
echo 'Error extracting Zip' . LINE_BREAK;
exit(ERR_SCRIPT_FAILED);
Expand Down

0 comments on commit 575aa78

Please sign in to comment.