77 lines
2 KiB
PHP
77 lines
2 KiB
PHP
|
#!/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,
|
||
|
'defaultValue' => '/var/www/html'
|
||
|
],
|
||
|
'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'
|
||
|
],
|
||
|
]);
|
||
|
$climate->arguments->parse();
|
||
|
$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');
|
||
|
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;
|
||
|
}
|