yeswiki-installer/yeswiki-updater.php
2024-01-09 16:17:21 +03:00

84 lines
2.3 KiB
PHP
Executable file

#!/usr/bin/php
<?php
require_once('vendor/autoload.php');
require_once('utils.inc.php');
use DevCoder\DotEnv;
$climate = new League\CLImate\CLImate();
$climate->description('yeswiki-updater, find and update YesWiki like a professionnal 🌈🦄');
if (0 == posix_getuid()) {
$absolutePathToEnvFile = __DIR__ . '/.env';
if (file_exists($absolutePathToEnvFile)) {
(new DotEnv($absolutePathToEnvFile))->load();
} else {
$climate->error('ERROR : No .env file found.');
exit;
}
$climate->arguments->add([
'path' => [
'prefix' => 'p',
'longPrefix' => 'path',
'description' => 'Path to scan for wikis',
'required' => true,
],
'output' => [
'prefix' => 'o',
'longPrefix' => 'output',
'description' => 'Output results in table format, json or csv',
'defaultValue' => 'table'
],
'update' => [
'prefix' => 'u',
'longPrefix' => 'update',
'description' => 'Update to latest version of stable yeswiki',
'defaultValue' => '0'
],
]);
try {
$climate->arguments->parse();
} catch (\Throwable $th) {
if (!$climate->arguments->defined('path')) {
$climate->error('This command needs a valid path argument for example : -p /var/www/html');
$climate->usage();
return;
}
}
$path = $climate->arguments->get('path');
if (!empty($path) && is_dir($path)) {
try {
$update = $climate->arguments->get('update');
$output = $climate->arguments->get('output');
$matches = searchWikis($path, 'wakka.config.php');
$climate->info(count($matches) . ' yeswikis found on ' . $path);
switch ($output) {
case 'table':
$climate->table($matches);
break;
case 'json':
$climate->json($matches);
break;
case 'csv':
$fileName = 'yeswiki-list.csv';
$file = fopen($fileName, "w");
foreach ($matches as $line) {
fputcsv($file, $line);
}
$climate->info($fileName . ' was created.');
break;
}
} catch (Exception $e) {
$climate->error('ERROR : ' . $e->getMessage());
}
} else {
$climate->usage();
}
} else {
$climate->error('ERROR : this script needs root privilege to run.');
exit;
}