-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.php
More file actions
executable file
·119 lines (103 loc) · 4.2 KB
/
Copy pathsetup.php
File metadata and controls
executable file
·119 lines (103 loc) · 4.2 KB
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
#!/usr/bin/env php
<?php
require_once __DIR__ . '/../includes/OnboardingManager.php';
if (PHP_SAPI !== 'cli') {
fwrite(STDERR, "This script must be run from the command line.\n");
exit(1);
}
$args = array_slice($argv, 1);
$showHelp = in_array('--help', $args, true) || in_array('-h', $args, true);
if ($showHelp) {
fwrite(STDOUT, "Usage: ./setup.sh [--init] [--check] [--rotate-keys] [--verbose]\n");
fwrite(STDOUT, " --init Create missing runtime state (default)\n");
fwrite(STDOUT, " --check Report health without writing files\n");
fwrite(STDOUT, " --rotate-keys Recreate stealth and secrets keys before reporting\n");
fwrite(STDOUT, " --verbose Show full actions, checks, and paths\n");
exit(0);
}
$checkOnly = in_array('--check', $args, true);
$rotateKeys = in_array('--rotate-keys', $args, true);
$verbose = in_array('--verbose', $args, true) || in_array('-v', $args, true);
$manager = new OnboardingManager();
$status = $manager->runSetup($checkOnly, $rotateKeys);
$printLine = static function(string $line = ''): void {
fwrite(STDOUT, $line . PHP_EOL);
};
$printLine('Doki setup');
$printLine('==========');
$printLine('Mode: ' . ($checkOnly ? 'check' : ($rotateKeys ? 'init + rotate keys' : 'init')));
$installState = (string)($status['install']['state'] ?? 'unknown');
$printLine('Install state: ' . $installState);
$printLine('');
if (!$checkOnly && !$rotateKeys && $installState === OnboardingManager::STATE_COMPLETE) {
$printLine('Doki is already set up. Setup refreshed runtime files and checked health.');
$printLine('Use ./start.sh to start Doki when it is stopped.');
$printLine('');
}
if (!$checkOnly && ($rotateKeys || $installState !== OnboardingManager::STATE_COMPLETE) && !empty($status['stealth']['secret'])) {
$printLine('Stealth key');
$printLine('-----------');
$printLine('Here is your stealth key. Keep it somewhere safe. You will need it after onboarding if you keep the stealth feature enabled.');
$printLine((string)$status['stealth']['secret']);
$printLine('');
}
if ($verbose && !$checkOnly && !empty($status['actions'])) {
$printLine('Actions');
$printLine('-------');
foreach ($status['actions'] as $action) {
$printLine('- ' . $action);
}
$printLine('');
}
$checks = $status['bootstrap']['checks'] ?? [];
$blockingFailures = 0;
$issues = [];
foreach ($checks as $name => $check) {
$ok = !empty($check['ok']);
$blocking = !empty($check['blocking']);
if (!$ok && $blocking) {
$blockingFailures++;
}
if (!$ok) {
$issues[$name] = $check;
}
}
if ($verbose) {
$printLine('Health checks');
$printLine('-------------');
foreach ($checks as $name => $check) {
$ok = !empty($check['ok']);
$blocking = !empty($check['blocking']);
$state = $ok ? 'OK' : ($blocking ? 'BLOCKING' : 'WARN');
$printLine(sprintf('[%s] %s: %s', $state, $name, (string)($check['message'] ?? '')));
}
$printLine('');
} elseif (!empty($issues)) {
$printLine('Issues');
$printLine('------');
foreach ($issues as $name => $check) {
$blocking = !empty($check['blocking']);
$state = $blocking ? 'BLOCKING' : 'WARN';
$printLine(sprintf('[%s] %s: %s', $state, $name, (string)($check['message'] ?? '')));
}
$printLine('');
} else {
$printLine('All health checks passed.');
$printLine('');
}
$printLine('Status');
$printLine('------');
$printLine('Bootstrap ready: ' . (!empty($status['bootstrap']['ready']) ? 'yes' : 'no'));
$printLine('Bootstrap healthy: ' . (!empty($status['bootstrap']['healthy']) ? 'yes' : 'no'));
$printLine('Local target configured: ' . (!empty($status['localTarget']['exists']) ? 'yes' : 'no'));
if ($verbose) {
$printLine('Stealth secret path: ' . (string)($status['stealth']['secretPath'] ?? 'unavailable'));
$printLine('Secrets key path: ' . (string)($status['secretsKey']['path'] ?? 'unavailable'));
} elseif (!empty($issues)) {
$printLine('Use ./setup.sh --verbose for full diagnostics.');
if ($checkOnly) {
$printLine('Run ./setup.sh while Doki is running to repair missing runtime state where possible.');
}
}
$printLine('');
exit($blockingFailures === 0 ? 0 : 1);