forked from gizmore/phpgdo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdo_adm.php
903 lines (827 loc) · 21 KB
/
gdo_adm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
<?php
use GDO\Admin\Method\Install;
use GDO\Core\Application;
use GDO\Core\Debug;
use GDO\Core\Logger;
use GDO\Core\ModuleLoader;
use GDO\Core\ModuleProviders;
use GDO\DB\Database;
use GDO\Language\Trans;
use GDO\Core\GDO_ModuleVar;
use GDO\UI\GDT_Success;
use GDO\User\GDO_User;
use GDO\User\GDO_UserPermission;
use GDO\User\GDT_UserType;
use GDO\DB\Cache;
use GDO\Install\Installer;
use GDO\Core\GDO_Module;
use GDO\Install\Method\Security;
use GDO\Core\GDT_Hook;
use GDO\Util\FileUtil;
use GDO\CLI\CLI;
use GDO\Util\Strings;
use GDO\Install\Module_Install;
use GDO\Install\Method\InstallCronjob;
use GDO\Install\Method\SystemTest;
use GDO\Crypto\BCrypt;
use GDO\UI\GDT_Error;
use GDO\Core\GDT_Expression;
use GDO\Form\GDT_Form;
use GDO\Core\GDT_Method;
use GDO\User\GDO_Permission;
use GDO\Core\Website;
/**
* The gdoadm.php executable manages modules and config via the CLI.
* It shall not be accesible to normal users!
*
* @example ./gdoadm.sh systemtest
* @example ./gdoadm.sh configure
* @example ./gdoadm.sh provide Helpdesk
* @example ./gdoadm.sh install_all
* @example ./gdoadm.sh secure
* @example ./gdoadm.sh configure perf enabled 1
*
* @author gizmore
* @version 7.0.1
* @since 6.10.0
*
* @see gdoadm.sh
* @see gdo_update.sh - to update your gdo6 installation
* @see gdo_reset.sh - to reset your installation to factory defaults. Own files are not deleted
* @see gdo_test.sh - for unit testing
* @see gdo_yarn.sh - to install javascript dependencies
* @see gdo_post_install.sh - to finish the installation process
* @see gdo_cronjob.sh - to run the module cronjobs
* @see bin/gdo - to invoke a gdo6 method via the CLI - for normal usage.
*/
/** @var $argc int **/
/** @var $argv string[] **/
/**
* Show usage of the gdoadm.sh shell command.
*
* @example gdoadm.sh install MailGPG
* @example bin/gdo mail.send giz Hi there, you wanker;This is the mail body. Parameters are separated via semicolon.
*/
function printUsage(int $code = -1)
{
global $argv;
$exe = $argv[0];
echo "Usage:\n";
echo "\n--- Spawn ---\n";
echo "php $exe systemtest - To run the installer system test.\n";
echo "php $exe configure [<config.php>] - To generate a protected/config.php.\n";
echo "php $exe test [<config.php>] - To test your protected/config.php\n";
echo "php $exe admin <username> <password> - to (re)set an admin account\n";
echo "php $exe cronjob - To print cronjob instructions\n";
echo "php $exe secure - To secure your installation after install.\n";
echo "\n--- Modules ---\n";
echo "php $exe modules [<module>] - To show a list of modules or show module details\n";
echo "php $exe provide <module> - To download all modules that are required to provide a module\n";
echo "php $exe provide_all - To download and install all available modules. This for devs who work on global module stuff and unit testing\n";
echo "php $exe install <module> - To install a module and it's dependencies\n";
echo "php $exe install_all - To install all modules inside the GDO/ folder and their dependencies\n";
echo "php $exe wipe <module> - To uninstall modules\n";
echo "php $exe wipe_all - To erase the whole database\n";
echo "php $exe update - Is automatically called after gdo_update.sh - it re-installs all installed modules.\n";
echo "php $exe confgrade - Upgrade your config.php with new config vars.\n";
echo "php $exe migrate <module> - To force-migrate gdo tables for an installed module. Handle with care.\n";
echo "php $exe migrate_all> - To force-migrate all gdo tables for all installed modules. Handle with special care.\n";
echo "\n--- Module config ---\n";
echo "php $exe config <module> - To show the config variables for a module\n";
echo "php $exe config <module> <key> - To show the description for a module variable\n";
echo "php $exe config <module> <key> <var> - To change the value of a module variable\n";
echo PHP_EOL;
echo "Tip: you can have a 'cli-only' protected/config_cli.php\n";
die($code);
}
if ($argc === 1)
{
printUsage(0);
}
require 'GDO7.php';
# forced?
if (FileUtil::isFile('protected/config_cli.php'))
{
require 'protected/config_cli.php';
}
else # try :]
{
@include 'protected/config.php';
}
final class gdo_adm extends Application
{
public function isInstall(): bool
{
return true;
}
}
$app = gdo_adm::init();
$app->cli(true)->verb(GDT_Form::POST);
# Load config defaults
if ( !defined('GDO_CONFIGURED'))
{
define('GDO_DB_ENABLED', false);
define('GDO_WEB_ROOT', '/');
\GDO\Install\Config::configure(); # autoconfig
}
// new ModuleLoader(GDO_PATH . 'GDO/');
CLI::setServerVars();
Database::init();
Cache::flush();
Cache::fileFlush();
Trans::$ISO = GDO_LANGUAGE;
Logger::init('gdo_adm', GDO_ERROR_LEVEL); # init without username
Debug::init(false, false);
$loader = ModuleLoader::instance();
define('GDO_CORE_STABLE', true);
$db = !!GDO_DB_ENABLED;
switch ($argv[1])
{
case 'configure':
case 'systemtest':
case 'wipe_all':
$db = false;
break;
}
$loader->loadModules($db, true);
$loader->loadLangFiles(true);
$loader->initModules();
if ($argv[1] === 'systemtest')
{
if ($argc !== 2)
{
printUsage(1);
}
echo SystemTest::make()->execute()->renderCLI();
echo PHP_EOL;
}
elseif ($argv[1] === 'configure')
{
# @TODO gdoadm.php: write a repl configurator.
if ($argc === 2)
{
$argc = 3;
$argv[2] = 'config.php'; # default config filename
}
$line = "install.configure --filename={$argv[2]},--save_config";
$expr = GDT_Expression::fromLine($line);
$response = $expr->execute();
echo $response->renderCLI();
if (Application::isSuccess())
{
Security::make()->protectFolders();
echo "You should now edit this file by hand.\n";
echo "Afterwards execute {$argv[0]} test config.\n";
}
}
elseif ($argv[1] === 'test')
{
if (GDO_DB_ENABLED)
{
Database::init();
}
echo \GDO\Install\Method\SystemTest::make()->execute()->renderCLI();
echo "Your configuration seems solid.\n";
echo "You can now try to php {$argv[0]} install <module>.\n";
echo "A list of official modules is shown via php {$argv[0]} modules.\n";
echo "Before you can install a module, you have to clone it.\n";
echo "Example: cd GDO; git clone --recursive https://github.com/gizmore/gdo6-session-cookie Session; cd ..\n";
echo "Please note that a Session module is *required* and you have to choose between gdo6-session-db and gdo6-session-cookie.\n";
echo "The session provider has to be cloned as a folder named GDO/Session/.\n";
}
elseif ($argv[1] === 'modules')
{
if ($argc == 2)
{
echo "List of official modules\n";
$providers = ModuleProviders::$PROVIDERS;
$git = \GDO\Core\ModuleProviders::GIT_PROVIDER;
foreach ($providers as $moduleName => $p)
{
if ( !is_array($p))
$p = [
$p
];
foreach ($p as $provider)
{
printf("%32s: cd GDO; git clone --recursive {$git}{$provider} {$moduleName}; cd ..\n", $moduleName);
}
}
}
elseif ($argc == 3)
{
$moduleName = $argv[2];
$module = ModuleLoader::instance()->getModule($moduleName, true);
if ( !$module)
{
echo "Module not found.\n";
$providers = @ModuleProviders::$PROVIDERS[$moduleName];
if ( !$providers)
{
echo "{$moduleName}: Not an official module or a typo somewhere. No Provider known.\n";
echo "Try reading docs/INSTALL.MD\n";
echo "You can get a list of modules via {$argv[0]}.\n";
}
elseif (is_array($providers))
{
echo "{$moduleName}: Choose between multiple possible providers:\n";
foreach ($providers as $provider)
{
printf("%20s: cd GDO; git clone --recursive {$git}{$provider} {$moduleName}; cd ..\n", $moduleName);
}
}
else
{
printf("%20s: cd GDO; git clone --recursive {$git}{$providers} {$moduleName}; cd ..\n", $moduleName);
}
}
else
{
$deps = implode(', ', $module->getDependencies());
echo "Module: {$moduleName}\n";
echo "License: {$module->license}\n";
echo $module->getModuleDescription();
echo "\n";
if ($deps)
{
echo "Dependencies: {$deps}\n";
}
}
}
else
{
printUsage();
}
}
elseif (($argv[1] === 'install') || ($argv[1] === 'install_all'))
{
if ( !GDO_DB_ENABLED)
{
echo "You do not have GDO_DB_ENABLED. I cannot install anything.\n";
die(1);
}
$deps = [];
if ($argv[1] === 'install')
{
$mode = 1;
if ($argc !== 3)
{
printUsage();
}
}
elseif ($argv[1] === 'install_all')
{
$mode = 2;
if ($argc !== 2)
{
printUsage();
}
}
ModuleLoader::instance()->reset()->loadModules(true, true, true);
ModuleLoader::instance()->initModules();
$git = \GDO\Core\ModuleProviders::GIT_PROVIDER;
if ($mode === 1)
{
$deps[] = 'Core';
$moduleNames = explode(',', $argv[2]);
foreach ($moduleNames as $moduleName)
{
$module = ModuleLoader::instance()->loadModuleFS($moduleName);
$deps[] = $module->getName();
if ( !$module)
{
echo "Unknown module. Try {$argv[0]} modules.\n";
die(1);
}
$deps = array_merge($deps, $module->getDependencies());
}
$deps = array_unique($deps);
}
elseif ($mode === 2)
{
$modules = ModuleLoader::instance()->loadModules(true, true, true);
$modules = array_filter($modules, function (GDO_Module $module)
{
return $module->isInstallable();
});
$deps = array_map(function (GDO_Module $mod)
{
return $mod->getName();
}, $modules);
$cnt = count($deps);
echo "Installing all {$cnt} modules.\n";
}
$deps[] = 'Core';
$deps = array_unique($deps);
$cnt = 0;
$allResolved = true; # All required modules provided?
while ($cnt !== count($deps))
{
$cnt = count($deps);
foreach ($deps as $dep)
{
$depmod = ModuleLoader::instance()->getModule($dep, true);
if ( !$depmod)
{
if ($allResolved === true)
{
echo "Missing dependencie(s)!\n";
echo "Please note that this list may not be complete, because missing modules might have more dependencies.\n";
}
$allResolved = false;
$providers = @\GDO\Core\ModuleProviders::$PROVIDERS[$dep];
if ( !$providers)
{
echo "{$dep}: Not an official module or a typo somewhere. No Provider known.\n";
}
elseif (is_array($providers))
{
echo "{$dep}: Choose between multiple possible providers.\n";
foreach ($providers as $provider)
{
printf("%20s: cd GDO; git clone --recursive {$git}{$provider} {$dep}; cd ..\n", $dep);
}
}
else
{
printf("%20s: cd GDO; git clone --recursive {$git}{$providers} {$dep}; cd ..\n", $dep);
}
continue;
}
$deps = array_unique(array_merge($depmod->getDependencies(), $deps));
}
}
$deps = array_unique($deps);
if ( !$allResolved)
{
echo "Some required modules are not provided by your current GDO/ folder.\n";
echo "Please clone the modules like stated above.\n";
echo "Repeat the process until all dependencies are resolved.\n";
die(2);
}
$deps2 = [];
foreach ($deps as $moduleName)
{
$mod = ModuleLoader::instance()->getModule($moduleName);
$deps2[$moduleName] = $mod->priority;
}
asort($deps2);
echo t('msg_installing_modules', [
implode(', ', array_keys($deps2))
]) . "\n";
$modules = array_map(function (string $moduleName)
{
return ModuleLoader::instance()->getModule($moduleName);
}, array_keys($deps2));
// $deps2 = Arrays::implodeHuman(array_keys($deps2));
// echo "Installing modules {$deps2}.\n";
Installer::installModules($modules);
Cache::flush();
Cache::fileFlush();
echo "Done.\n";
}
elseif ($argv[1] === 'admin')
{
if ($argc !== 4)
{
printUsage();
}
if ( !($user = GDO_User::getByName($argv[2])))
{
$user = GDO_User::blank([
'user_name' => $argv[2],
'user_type' => GDT_UserType::MEMBER,
])->insert();
GDT_Hook::callWithIPC('UserActivated', $user, null);
}
$user->saveVar('user_password', BCrypt::create($argv[3])->__toString());
$user->saveVar('user_deleted', null);
$user->saveVar('user_deletor', null);
foreach (GDO_Permission::table()->all() as $perm)
{
GDO_UserPermission::grant($user, $perm->getName());
}
$user->changedPermissions();
echo t('msg_admin_created', [
$argv[2]
]) . "\n";
}
elseif ($argv[1] === 'wipe_all')
{
if ($argc !== 2)
{
printUsage();
}
Database::instance()->queryWrite("DROP DATABASE " . GDO_DB_NAME);
Database::instance()->queryWrite("CREATE DATABASE " . GDO_DB_NAME);
printf("The database has been killed completely and created empty.\n");
}
elseif ($argv[1] === 'wipe')
{
if ($argc !== 3)
{
printUsage();
}
$module = ModuleLoader::instance()->loadModuleFS($argv[2]);
$response = Install::make()->executeWithInputs([
'module' => $module->getName(),
'uninstall' => '1'
]);
if (Application::isError())
{
echo $response->renderCLI();
}
else
{
if ($classes = $module->getClasses())
{
$classes = array_map(function ($class)
{
return Strings::rsubstrFrom($class, '\\');
}, $classes);
}
else
{
$classes = [];
}
printf("The %s module has been wiped from the database.\n", $module->getName());
if ($classes)
{
printf("The following GDOs have been wiped: %s.\n", implode(', ', $classes));
}
}
}
elseif ( ($argv[1] === 'config') || ($argv[1] === 'conf') )
{
if (($argc < 2) || ($argc > 5))
{
printUsage();
}
$loader->initModules();
if ($argc === 2)
{
$modules = ModuleLoader::instance()->getEnabledModules();
$names = array_map(function (GDO_Module $module)
{
return $module->getName();
}, $modules);
echo t('msg_installed_modules', [
implode(', ', $names)
]) . "";
die(0);
}
if ($argc === 3)
{
$module = ModuleLoader::instance()->loadModuleFS($argv[2], false, true);
if (( !$module) || ( !$module->isPersisted()))
{
echo t('err_module', [
html($argv[2])
]) . "\n";
die( -1);
}
if ($config = $module->getConfigCache())
{
$vars = [];
foreach ($config as $key => $gdt)
{
$vars[] = $key;
}
$keys = implode(', ', $vars);
$keys = $keys ? $keys : t('none');
echo t('msg_available_config', [
$module->getName(),
$keys
]);
echo PHP_EOL;
die(0);
}
else
{
echo t('msg_module_has_no_config');
die(1);
}
}
$key = $argv[3];
if ($argc === 4)
{
$module = ModuleLoader::instance()->loadModuleFS($argv[2], false, true);
if (( !$module) || ( !$module->isPersisted()))
{
echo t('err_module_disabled', [
html($argv[2])
]) . "\n";
die( -1);
}
$config = $module->getConfigColumn($key);
echo t('msg_set_config', [
$key,
$module->getName(),
$config->initial,
$config->gdoExampleVars()
]);
echo PHP_EOL;
die(0);
}
$var = $argv[4];
if ($argc === 5)
{
$module = ModuleLoader::instance()->loadModuleFS($argv[2], false, true);
if (( !$module) || ( !$module->isPersisted()))
{
echo t('err_module_disabled', [
html($argv[2])
]) . "\n";
die( -1);
}
$gdt = $module->getConfigColumn($key)->var($var);
if ( !$gdt->validate($gdt->toValue($var)))
{
echo json_encode($gdt->configJSON());
echo PHP_EOL;
die(1);
}
GDO_ModuleVar::createModuleVar($module, $gdt);
echo t('msg_changed_config',
[
$gdt->renderLabel(),
$module->getName(),
$gdt->displayVar($gdt->initial),
$gdt->displayVar($gdt->var),
]);
echo PHP_EOL;
Cache::flush();
GDT_Hook::callHook('ModuleVarsChanged', $module);
}
}
elseif (($argv[1] === 'provide') || ($argv[1] === 'provide_all') || ($argv[1] === 'provide_ssh') ||
($argv[1] === 'provide_all_ssh'))
{
if (($argc !== 3) && ($argc !== 2))
{
if (($argc !== 2) || (($argv[1] !== 'provide_all') && ($argv[1] !== 'provide_all_ssh')))
{
printUsage( -1);
}
}
$isall = strpos($argv[1], '_all') !== false;
$isssh = strpos($argv[1], '_ssh') !== false;
$loader = ModuleLoader::instance();
$loader->loadModules(false, true, true);
# Get all dependencies
$cd = 0;
if ($isall)
{
$deps = [
'Core'
];
foreach (ModuleProviders::$PROVIDERS as $name => $providers)
{
if ($providers)
{
$deps[] = $name;
}
}
}
else # Single
{
$deps = ModuleProviders::getDependencies($argv[2]);
if ($deps === null)
{
echo "Unknown module: {$argv[2]}\n";
die( -1);
}
$deps[] = 'Core';
$deps[] = $argv[2];
while ($cd != count($deps))
{
$cd = count($deps);
foreach ($deps as $dep)
{
if ($module = $loader->getModule($dep, false, false))
{
$moreDeps = $module->getDependencies();
}
else
{
$moreDeps = ModuleProviders::getDependencies($dep);
}
$deps = array_unique(array_merge($deps, $moreDeps));
}
}
}
$deps = array_unique($deps);
# Sort by name
sort($deps);
# Check missing in fs
$missing = [];
foreach ($deps as $dep)
{
if ( !$loader->getModule($dep, false, false))
{
$missing[] = $dep;
}
}
if (count($missing))
{
echo "The following modules are not in your filesystem:\n";
echo implode(', ', $missing) . "\n";
echo "Shall i git clone those modules? (y/n) [y]: ";
$input = readline();
$input = trim(strtolower($input));
if (($input === 'y') || ($input === ''))
{
echo "Cloning " . count($missing) . " modules...\n";
foreach ($missing as $module)
{
$providers = ModuleProviders::getProviders($module);
if ( !$providers)
{
echo "No provider for $module\n";
die(1);
}
$n = 1;
if (is_array($providers))
{
echo "The {$module} Module has more than 1 possible provider. Please choose: \n";
$n = 0;
foreach ($providers as $provider)
{
$n++;
echo "{$n}: {$provider}\n";
}
echo "Please choose: [1-{$n}]: ";
$n = (int) readline();
if (($n < 1) || ($n > count($providers)))
{
echo "Invalid choice!\nExit 1\n";
die(1);
}
}
$url = ModuleProviders::getGitUrl($module, $n, $isssh);
$module = ModuleProviders::getCleanModuleName($module);
$cmd = "cd GDO && git clone --recursive {$url} {$module}";
echo $cmd . "\n";
$output = [];
$retval = 0;
exec($cmd, $output, $retval);
echo implode("\n", $output) . "\n";
echo "Return code: " . $retval . "\n";
if ($retval != 0)
{
echo "Error upon clone. Exiting\n";
die($retval);
}
}
echo "You should now have all dependencies cloned in your GDO/ folder.\n";
if ($isall)
{
echo "You can now:\n./gdoadm.sh install_all\n";
}
else
{
echo "You can now:\n./gdoadm.sh install {$argv[2]}\n";
}
$r = readline("Shall i do this now? [Y/n]");
$r = $r ? $r : 'y';
if (($r[0] === 'y') || ($r[0] === 'Y'))
{
if ($isall)
{
system("php gdo_adm.php install_all");
}
else
{
system("php gdo_adm.php install {$argv[2]}");
}
}
}
}
else
{
if ($isall)
{
echo "Your filesystem has all the required modules. You can: ./gdoadm.sh install_all\n";
}
else
{
echo "Your filesystem has all the required modules. You can: ./gdoadm.sh install {$argv[2]}\n";
}
$r = readline("Shall i do this now? [Y/n]");
$r = $r ? $r : 'y';
if (($r[0] === 'y') || ($r[0] === 'Y'))
{
if ($isall)
{
system("php gdo_adm.php install_all");
}
else
{
system("php gdo_adm.php install {$argv[2]}");
}
}
}
}
elseif ($argv[1] === 'cronjob')
{
$module = Module_Install::instance();
$method = InstallCronjob::make();
$result = $method->executeWithInit();
echo $result->renderCLI();
}
elseif ($argv[1] === 'secure')
{
$module = Module_Install::instance();
$method = GDT_Method::make()->method(Security::make());
$result = $method->clibutton()
->noChecks()
->execute();
echo $result->renderCLI();
}
elseif ($argv[1] === 'update')
{
echo "Did you mean ./gdo_update.sh\n";
$modules = ModuleLoader::instance()->getEnabledModules();
foreach ($modules as $module)
{
Installer::installModule($module);
}
echo "Update complete.\n";
}
elseif ($argv[1] === 'migrate')
{
if (count($argv) !== 3)
{
Website::error('Admin', 'err_gdoadm_migrate');
}
else if ( !($module = ModuleLoader::instance()->getModule($argv[2], true, false)))
{
echo GDT_Error::make()->text('err_module', [
html($argv[2])
])->renderCLI();
}
else
{
Installer::installModule($module, true);
GDT_Success::make()->text('msg_gdoadm_migrated', [
$module->renderName()
]);
}
}
elseif ($argv[1] === 'migrate_all')
{
$modules = ModuleLoader::instance()->getEnabledModules();
foreach ($modules as $module)
{
Installer::installModule($module, true);
}
echo GDT_Success::make()->text('msg_gdoadm_migrated_all')->renderCLI();
}
elseif ($argv[1] === 'gizmore_setup')
{
$special = ModuleProviders::getMultiProviders();
foreach ($special as $moduleName => $providers)
{
echo "Cloning especially {$moduleName}.\n";
foreach ($providers as $i => $provider)
{
echo "Cloning provider {$provider}.\n";
$url = ModuleProviders::getGitUrl($moduleName, $i + 1, true);
$cmd = "cd GDO && git clone --recursive {$url}";
$output = [];
$return_var = 0;
echo "$cmd\n";
$result = exec($cmd, $output, $return_var);
if ($return_var !== 0)
{
CLI::error(t('err_clone_url', [
$url
]));
}
}
$dir = GDO_PATH . "GDO/{$moduleName}/.git";
echo "Cleaning provider choice in use: {$dir}.\n";
FileUtil::removeDir($dir);
}
echo "All done, gizmore sire o\"! =)\n";
}
elseif ($argv[1] === 'confgrade')
{
switch ($argc)
{
default: # fallthrough chaoz?
printUsage();
case 2:
$argv[2] = 'config.php';
case 3:
$path = $argv[2];
}
Installer::refreshConfig("protected/{$path}");
echo "All done!\n";
}
else
{
echo "Unknown command {$argv[1]}\n\n";
printUsage();
}
CLI::flushTopResponse();