forked from romaninsh/dokku-alt-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
96 lines (66 loc) · 2.3 KB
/
bootstrap.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
<?php
include'vendor/autoload.php';
$app = new App_CLI();
//$app->pathfinder->addRelativeLocation(['php','shared/lib']);
try {
$app->add('Logger');
$app->pathfinder->base_location->addRelativeLocation('shared',[
'php'=>'lib',
'addons'=>'addons',
]);
if (PHP_SAPI !== 'cli' || !empty($_SERVER['REMOTE_ADDR']))
throw new Exception('Execute from command-line only');
$options = getopt("k:rha:n:", ['key:','reset','help','addr:','name:']);
if(
isset($options['h'])
|| isset($options['help'])
) {
echo <<<EOF
Usage:
php bootstrap.php [-k <key> -i <ip> [-n <name>]] [-r] [-h]
-k, --key <file>
-a, --addr <addr>
-n, --name <name>
Read private key from file and add it as default host. <addr>
must be also specified. If you omit the name, addr will be used.
-r, --reset
Reset user information
-h, --help
Display this message
EOF;
exit;
}
echo "Bootstrapping Dokku-alt-manager\n";
// First lets test database
echo "Connecting do database: ";
$app->dbConnect();
echo "OK\n";
// See if database needs updating
echo "Updating Database: ";
$app->add('Controller_Migrator_MySQL')->migrate();
echo "OK\n";
// Should we reset users?
if(isset($options['r']) || isset($options['reset'])){
$app->add('Model_User')->each('delete');
echo "User access list emptied.\n";
}
// Should we import key
if(isset($options['k']) || isset($options['key'])){
$file = $options['k'] ?: $options['key'];
if($file == '-')$file='php://stdin';
$addr = $options['a']?:$options['addr'];
if(!$addr)throw $app->exception('Addr must be specified');
$name = $options['n']?:$options['name']?:$addr;
if(!$file || !is_readable($file)) die("Specify a valid key file\n");
echo "Importing key from ".($file=='-'?'STDIN':$file)." for $addr ($name)\n";
$private_key = file_get_contents($file=='-'?STDIN:$file);
$host = $app->add('dokku_alt/Model_Host');
$host->tryLoadBy('addr',$addr);
$host['addr']=$addr;
$host['name']=$name;
$host['private_key']=$private_key;
$host->saveAndUnload();
}
}catch(Exception $e){
$app->caughtException($e);
}