-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnexusUpdate.php
More file actions
628 lines (532 loc) · 24.1 KB
/
Copy pathnexusUpdate.php
File metadata and controls
628 lines (532 loc) · 24.1 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
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
#!/usr/bin/env php
<?php
// nexus_tool.php - Skrip All-in-One untuk Instalasi dan Manajemen Nexus Node
// Dijalankan dengan: sudo php nexus_tool.php
declare(strict_types=1);
// Variabel global
$nodeId = null;
$walletAddress = null;
$configFile = '';
$userHome = '';
$screenPath = ''; // Path absolut ke executable 'screen'
$nexusCliPath = ''; // Path absolut ke nexus-network CLI
// --- Helper Functions ---
function colorLog(string $text, string $color): string {
$colors = [
'green' => "\033[0;32m",
'red' => "\033[0;31m",
'yellow'=> "\033[1;33m",
'blue' => "\033[0;34m",
'cyan' => "\033[0;36m",
'reset' => "\033[0m"
];
return ($colors[$color] ?? '') . $text . $colors['reset'];
}
function runCommand(string $command): void {
echo colorLog("\n▶️ Menjalankan: ", 'yellow') . $command . "\n";
passthru($command, $result_code);
if ($result_code !== 0) {
echo colorLog("❌ Perintah gagal dengan kode error: $result_code\n", 'red');
} else {
echo colorLog("✅ Perintah selesai.\n", 'green');
}
echo "--------------------------------------------------------\n";
}
function getUserHome(): string {
$user = getenv('SUDO_USER');
if ($user && function_exists('posix_getpwnam')) {
$userInfo = posix_getpwnam($user);
if ($userInfo && isset($userInfo['dir'])) {
return $userInfo['dir'];
}
}
return getenv('HOME');
}
/**
* Mencari path absolut dari sebuah executable command.
*/
function findExecutable(string $command, ?string $userHome = null): ?string {
if (is_executable($command)) return $command;
$paths = explode(':', getenv('PATH') ?: '');
$paths = array_merge($paths, ['/usr/bin', '/bin', '/usr/local/bin', '/sbin', '/usr/sbin', '/snap/bin']);
if ($userHome) {
$paths[] = $userHome . '/.local/bin';
}
$paths = array_unique(array_filter($paths));
foreach ($paths as $path) {
$fullPath = rtrim($path, '/') . '/' . $command;
if (is_executable($fullPath)) return $fullPath;
}
$whichOutput = shell_exec('which ' . escapeshellarg($command));
if ($whichOutput && is_executable(trim($whichOutput))) return trim($whichOutput);
return null;
}
// --- Fungsi untuk Manajemen Konfigurasi ---
function saveConfiguration(): void {
global $configFile, $walletAddress, $nodeId;
$config = ['walletAddress' => $walletAddress, 'nodeId' => $nodeId];
file_put_contents($configFile, json_encode($config, JSON_PRETTY_PRINT));
}
function loadConfiguration(): void {
global $configFile, $walletAddress, $nodeId;
if (file_exists($configFile)) {
$config = json_decode(file_get_contents($configFile), true);
$walletAddress = $config['walletAddress'] ?? null;
$nodeId = $config['nodeId'] ?? null;
echo colorLog("Konfigurasi sebelumnya berhasil dimuat.\n", 'green');
}
}
// --- Fungsi untuk setiap bagian menu ---
function checkStatus(): void {
global $userHome, $screenPath, $nexusCliPath;
echo colorLog("🔍 Memeriksa Status Dependensi...\n", 'cyan');
echo "- Perintah 'screen': ";
if ($screenPath) {
echo colorLog("DITEMUKAN", 'green') . " di " . colorLog($screenPath, 'yellow') . "\n";
} else {
echo colorLog("TIDAK DITEMUKAN", 'red') . ". Jalankan 'sudo apt install screen'.\n";
}
$rustc_path = $userHome . '/.cargo/bin/rustc';
echo "- Perintah 'rustc': ";
if (is_executable($rustc_path)) {
echo colorLog("DITEMUKAN", 'green') . " di " . colorLog($rustc_path, 'yellow') . "\n";
} else {
echo colorLog("TIDAK DITEMUKAN", 'red') . ". Jalankan instalasi awal (Menu Utama -> 1).\n";
}
echo "- Perintah 'nexus-network': ";
if ($nexusCliPath && is_executable($nexusCliPath)) {
echo colorLog("DITEMUKAN", 'green') . " di " . colorLog($nexusCliPath, 'yellow') . "\n";
} else {
echo colorLog("TIDAK DITEMUKAN", 'red') . ". Jalankan 'Update versi Nexus CLI' (Menu Utama -> 2).\n";
}
}
function initialSetup(): void {
global $userHome;
echo colorLog("🚀 Memulai Instalasi Awal & Setup Dependensi...\n", 'cyan');
runCommand("sudo apt update && sudo apt upgrade -y");
runCommand("sudo apt install screen curl build-essential pkg-config libssl-dev git-all -y");
runCommand("sudo apt install protobuf-compiler -y");
runCommand("sudo apt update");
echo colorLog("\n Rust akan diinstal...\n", 'yellow');
runCommand("curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y");
$cargo_path = $userHome . '/.cargo/bin';
runCommand("PATH={$cargo_path}:\$PATH rustup target add riscv32i-unknown-none-elf");
echo colorLog("\n Menginstal Nexus CLI...\n", 'cyan');
updateNexusCLI();
echo colorLog("🎉 Instalasi Awal Selesai! Jalankan ulang skrip untuk masuk ke menu utama.\n", 'green');
exit;
}
function updateNexusCLI(): void {
echo colorLog("🔄 Memperbarui versi Nexus CLI...\n", 'cyan');
runCommand("curl https://cli.nexus.xyz/ | sh");
echo colorLog("Nexus CLI telah diperbarui. Mohon jalankan ulang skrip agar path terdeteksi.\n", 'yellow');
}
function registerWallet(): void {
global $walletAddress, $nexusCliPath;
if (!$nexusCliPath) {
echo colorLog("Perintah 'nexus-network' tidak ditemukan. Jalankan 'Cek Status' (#1) dan 'Update CLI' (#2).\n", 'red');
return;
}
echo colorLog("🔑 Pendaftaran Alamat Wallet\n", 'cyan');
$addressInput = readline("Masukkan alamat wallet Anda: ");
if (empty(trim($addressInput))) {
echo colorLog("Alamat wallet tidak boleh kosong.\n", 'red');
return;
}
$walletAddress = trim($addressInput);
$command = $nexusCliPath . " register-user --wallet-address " . escapeshellarg($walletAddress);
runCommand($command);
saveConfiguration();
echo colorLog("Alamat wallet '$walletAddress' telah disimpan.\n", 'yellow');
}
function createNodeId(): void {
global $nodeId, $nexusCliPath;
if (!$nexusCliPath) {
echo colorLog("Perintah 'nexus-network' tidak ditemukan. Jalankan 'Cek Status' (#1) dan 'Update CLI' (#2).\n", 'red');
return;
}
echo colorLog("🆔 Membuat Node ID Baru...\n", 'cyan');
$command = $nexusCliPath . " register-node";
echo colorLog("\n▶️ Menjalankan: ", 'yellow') . $command . "\n";
// Menggunakan exec untuk menangkap output
exec($command, $output, $return_var);
$fullOutput = implode("\n", $output);
echo $fullOutput . "\n"; // Tampilkan seluruh output untuk debugging
if ($return_var === 0) {
$foundId = false;
// Regex yang lebih fleksibel untuk menangkap Node ID
// Mencari "Node registered successfully with ID: <ID>" atau "Successfully registered node with ID: <ID>"
if (preg_match('/(?:Node registered successfully with ID|Successfully registered node with ID):\s*([a-zA-Z0-9\-]+)/i', $fullOutput, $matches)) {
$nodeId = trim($matches[1]);
saveConfiguration();
echo colorLog("\n✅ Node ID berhasil dibuat dan disimpan: " . $nodeId . "\n", 'green');
$foundId = true;
}
if (!$foundId) {
echo colorLog("Tidak dapat menemukan Node ID pada output, mohon periksa kembali. Output lengkap di atas.\n", 'red');
}
} else {
echo colorLog("Gagal membuat Node ID. Pastikan wallet Anda sudah terdaftar. Kode error: $return_var\n", 'red');
}
}
/**
* Fungsi untuk menjalankan node dengan Node ID yang sudah ada (foreground).
*/
function startExistingNode(): void {
global $nexusCliPath;
if (!$nexusCliPath) {
echo colorLog("Perintah 'nexus-network' tidak ditemukan. Jalankan 'Cek Status' (#1) dan 'Update CLI' (#2).\n", 'red');
return;
}
echo colorLog("⚡ Menjalankan Node dengan Node ID yang sudah ada...\n", 'cyan');
$nodeIdInput = readline("Masukkan Node ID yang sudah ada: ");
if (empty(trim($nodeIdInput))) {
echo colorLog("Node ID tidak boleh kosong.\n", 'red');
return;
}
echo colorLog("Untuk menghentikan node, tekan CTRL+C.\n", 'yellow');
$command = $nexusCliPath . " start --node-id " . escapeshellarg(trim($nodeIdInput));
runCommand($command);
}
function startNode(): void {
global $nodeId, $nexusCliPath;
if (!$nexusCliPath) {
echo colorLog("Perintah 'nexus-network' tidak ditemukan. Jalankan 'Cek Status' (#1) dan 'Update CLI' (#2).\n", 'red');
return;
}
echo colorLog("⚡ Menjalankan Node...\n", 'cyan');
$idToUse = $nodeId;
if (empty($idToUse)) {
echo colorLog("Node ID belum disimpan. Masukkan secara manual.\n", 'yellow');
$idToUse = readline("Masukkan Node ID: ");
} else {
echo "Gunakan Node ID yang tersimpan: " . colorLog($idToUse, 'green') . "? (Y/n): ";
if (strtolower(trim(readline())) === 'n') {
$idToUse = readline("Masukkan Node ID baru: ");
}
}
if (empty(trim($idToUse))) {
echo colorLog("Node ID tidak boleh kosong.\n", 'red');
return;
}
echo colorLog("Untuk menghentikan node, tekan CTRL+C.\n", 'yellow');
$command = $nexusCliPath . " start --node-id " . escapeshellarg(trim($idToUse));
runCommand($command);
}
function startNodeInBackground(): void {
global $nodeId, $screenPath, $nexusCliPath;
if (!$screenPath) {
echo colorLog("Perintah 'screen' tidak ditemukan. Jalankan 'Cek Status' (#1) untuk info.\n", 'red');
return;
}
if (!$nexusCliPath) {
echo colorLog("Perintah 'nexus-network' tidak ditemukan. Jalankan 'Cek Status' (#1) dan 'Update CLI' (#2).\n", 'red');
return;
}
if (empty($nodeId)) {
echo colorLog("Node ID belum disimpan. Silakan buat Node ID terlebih dahulu (Pilihan #4).\n", 'red');
return;
}
echo colorLog("🖥️ Menjalankan Node di mode screen (background)...\n", 'cyan');
$baseNames = ['nexus', 'nexusnode'];
$screenName = $baseNames[array_rand($baseNames)] . '-' . rand(100, 999);
echo colorLog("Node ID yang akan digunakan: ", 'cyan') . colorLog($nodeId, 'yellow') . "\n";
echo colorLog("Nama screen yang dibuat secara acak: ", 'cyan') . colorLog($screenName, 'yellow') . "\n";
$screen_command = $nexusCliPath . " start --node-id " . escapeshellarg(trim($nodeId));
$command = $screenPath . " -S " . escapeshellarg(trim($screenName)) . " -dm bash -c " . escapeshellarg($screen_command);
runCommand($command);
echo colorLog("✅ Node telah dimulai di dalam screen bernama '{$screenName}'.\n", 'green');
}
/**
* Fungsi untuk menjalankan node di latar belakang dengan jumlah thread yang dapat dipilih.
*/
function startNodeWithThreads(): void {
global $nodeId, $screenPath, $nexusCliPath;
if (!$screenPath) {
echo colorLog("Perintah 'screen' tidak ditemukan. Jalankan 'Cek Status' (#1) untuk info.\n", 'red');
return;
}
if (!$nexusCliPath) {
echo colorLog("Perintah 'nexus-network' tidak ditemukan. Jalankan 'Cek Status' (#1) dan 'Update CLI' (#2).\n", 'red');
return;
}
echo colorLog("🖥️ Menjalankan Node di mode screen dengan custom thread...\n", 'cyan');
$idToUse = $nodeId;
if (empty($idToUse)) {
echo colorLog("Node ID belum disimpan. Masukkan secara manual.\n", 'yellow');
$idToUse = readline("Masukkan Node ID: ");
} else {
echo "Gunakan Node ID yang tersimpan: " . colorLog($idToUse, 'green') . "? (Y/n): ";
if (strtolower(trim(readline())) === 'n') {
$idToUse = readline("Masukkan Node ID baru: ");
}
}
if (empty(trim($idToUse))) {
echo colorLog("Node ID tidak boleh kosong.\n", 'red');
return;
}
$threads = readline("Masukkan jumlah thread yang diinginkan (misal: 4, 8, 16): ");
$threads = intval($threads);
if ($threads <= 0) {
echo colorLog("Jumlah thread tidak valid. Gunakan angka positif.\n", 'red');
return;
}
$baseNames = ['nexus', 'nexusnode', 'nexus-prover'];
$screenName = $baseNames[array_rand($baseNames)] . '-' . rand(100, 999);
echo colorLog("Node ID yang akan digunakan: ", 'cyan') . colorLog($idToUse, 'yellow') . "\n";
echo colorLog("Nama screen yang dibuat secara acak: ", 'cyan') . colorLog($screenName, 'yellow') . "\n";
echo colorLog("Jumlah thread yang akan digunakan: ", 'cyan') . colorLog((string)$threads, 'yellow') . "\n";
$screen_command = $nexusCliPath . " start --node-id " . escapeshellarg(trim($idToUse)) . " --max-threads " . escapeshellarg((string)$threads);
$command = $screenPath . " -S " . escapeshellarg(trim($screenName)) . " -dm bash -c " . escapeshellarg($screen_command);
runCommand($command);
echo colorLog("✅ Node telah dimulai di dalam screen bernama '{$screenName}'.\n", 'green');
echo colorLog("Untuk melihat log, pilih opsi 'Lihat Sesi Screen (Logs)' (#9).\n", 'yellow');
}
function listScreenSessions(): array {
global $screenPath;
if (!$screenPath) return [];
exec($screenPath . ' -ls', $output);
$sessions = [];
foreach ($output as $line) {
if (preg_match('/^\s+([0-9]+\..*?)\s+\(/', $line, $matches)) {
$sessions[] = trim($matches[1]);
}
}
return $sessions;
}
function viewScreenLogs(): void {
global $screenPath;
if (!$screenPath) {
echo colorLog("Perintah 'screen' tidak ditemukan. Jalankan 'Cek Status' (#1) untuk info.\n", 'red');
return;
}
echo colorLog("📊 Mengecek sesi screen yang berjalan...\n", 'cyan');
$sessions = listScreenSessions();
if (empty($sessions)) {
echo colorLog("Tidak ada sesi screen yang sedang berjalan.\n", 'yellow');
return;
}
echo colorLog("Sesi screen yang ditemukan:\n", 'green');
foreach ($sessions as $index => $session) echo ($index + 1) . ". " . colorLog($session, 'yellow') . "\n";
echo "\n";
echo colorLog("Pilih sesi untuk disambungkan (ketik nomornya), atau 'x' untuk kembali: ", 'cyan');
$choice = trim(readline());
if (strtolower($choice) === 'x' || $choice === '') return;
$choiceIndex = intval($choice) - 1;
if (isset($sessions[$choiceIndex])) {
$selectedSession = $sessions[$choiceIndex];
echo colorLog("Menyambungkan ke sesi '{$selectedSession}'...\n", 'green');
passthru('clear');
passthru($screenPath . ' -r ' . escapeshellarg($selectedSession));
echo colorLog("\nKembali dari sesi screen. Tekan [Enter] untuk melanjutkan.", 'cyan');
readline();
} else {
echo colorLog("Pilihan tidak valid.\n", 'red');
}
}
function stopScreen(): void {
global $screenPath;
if (!$screenPath) {
echo colorLog("Perintah 'screen' tidak ditemukan. Jalankan 'Cek Status' (#1) untuk info.\n", 'red');
return;
}
echo colorLog("🛑 Menghentikan sesi screen...\n", 'cyan');
$sessions = listScreenSessions();
if (empty($sessions)) {
echo colorLog("Tidak ada sesi screen yang sedang berjalan.\n", 'yellow');
return;
}
echo colorLog("Sesi screen yang ditemukan:\n", 'green');
foreach ($sessions as $index => $session) echo ($index + 1) . ". " . colorLog($session, 'yellow') . "\n";
echo "\n";
echo colorLog("Pilih sesi untuk dihentikan (ketik nomornya), atau 'x' untuk kembali: ", 'cyan');
$choice = trim(readline());
if (strtolower($choice) === 'x' || $choice === '') return;
$choiceIndex = intval($choice) - 1;
if (isset($sessions[$choiceIndex])) {
$selectedSession = $sessions[$choiceIndex];
$command = $screenPath . ' -X -S ' . escapeshellarg($selectedSession) . ' quit';
runCommand($command);
echo colorLog("Sesi '{$selectedSession}' telah dihentikan.\n", "green");
} else {
echo colorLog("Pilihan tidak valid.\n", 'red');
}
}
function manageGlibc(): void {
global $userHome;
echo colorLog("🔎 Mengecek versi GLIBC...\n", 'cyan');
exec('ldd --version', $output, $return_var);
if ($return_var !== 0) {
echo colorLog("Tidak dapat mengecek versi GLIBC.\n", 'red');
return;
}
$versionLine = $output[0] ?? '';
if (!preg_match('/([0-9]+\.[0-9]+)$/', $versionLine, $matches)) {
echo colorLog("Tidak dapat mendeteksi versi GLIBC dari output.\n", 'red');
return;
}
$glibcVersion = $matches[1];
echo colorLog("Versi GLIBC terdeteksi: ", 'green') . colorLog($glibcVersion, 'yellow') . "\n";
if ($glibcVersion === '2.35') {
echo "\n" . colorLog(str_repeat("=", 56)."\n", 'red');
echo colorLog(" PERINGATAN KERAS\n", 'yellow');
echo colorLog(str_repeat("=", 56)."\n", 'red');
echo colorLog("Mengubah GLIBC adalah operasi SANGAT BERISIKO dan dapat merusak\n", 'yellow');
echo colorLog("sistem Anda. Lanjutkan hanya jika Anda tahu apa yang Anda lakukan.\n", 'yellow');
echo colorLog("\nSetuju untuk update ke GLIBC 2.39? (Ketik 'SETUJU'): ", 'cyan');
if (trim(readline()) === 'SETUJU') {
echo colorLog("Konfirmasi diterima. Memulai proses update GLIBC...\n", 'green');
$originalDir = getcwd();
chdir($userHome); // Pindah ke home directory untuk proses
runCommand("sudo apt update");
runCommand("sudo apt install -y gawk bison gcc make wget tar");
runCommand("wget -c https://ftp.gnu.org/gnu/glibc/glibc-2.39.tar.gz");
$updateCommands = [
'tar -zxvf glibc-2.39.tar.gz',
'cd glibc-2.39',
'mkdir -p glibc-build',
'cd glibc-build',
'../configure --prefix=/opt/glibc-2.39',
'make -j$(nproc)',
'sudo make install'
];
runCommand(implode(' && ', $updateCommands));
chdir($originalDir); // Kembali ke direktori awal
echo colorLog("Proses update GLIBC selesai. Disarankan untuk me-reboot sistem Anda.", "green");
} else {
echo colorLog("Update dibatalkan.\n", 'red');
}
} else {
echo colorLog("Versi GLIBC Anda bukan 2.35. Tidak ada tindakan yang diperlukan.\n", 'green');
}
}
function manageSwap(): void {
echo colorLog("💾 Mengelola Swap File untuk Mengatasi VPS 'Killed'...\n", 'cyan');
echo "Fungsi ini akan membuat swap file untuk membantu VPS dengan RAM terbatas.\n";
echo "Pilih ukuran swap yang diinginkan:\n";
echo "1. 4G (Untuk VPS dengan RAM 4GB atau kurang)\n";
echo "2. 8G (Untuk VPS dengan RAM 8GB)\n";
echo "3. 16G (Untuk VPS dengan RAM 16GB atau lebih)\n";
echo colorLog("Masukkan pilihan Anda [1-3]: ", "yellow");
$choice = trim(readline());
$size = '';
switch ($choice) {
case '1': $size = '4G'; break;
case '2': $size = '8G'; break;
case '3': $size = '16G'; break;
default:
echo colorLog("Pilihan tidak valid.\n", 'red');
return;
}
echo colorLog("Anda memilih untuk membuat swap file sebesar $size. Lanjutkan? (y/n): ", 'cyan');
if (strtolower(trim(readline())) !== 'y') {
echo colorLog("Pembuatan swap dibatalkan.\n", 'red');
return;
}
runCommand("sudo fallocate -l $size /swapfile");
runCommand("sudo chmod 600 /swapfile");
runCommand("sudo mkswap /swapfile");
runCommand("sudo swapon /swapfile");
runCommand("echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab");
echo colorLog("Swap file sebesar $size berhasil dibuat dan diaktifkan.\n", 'green');
}
function rebootVps(): void {
echo colorLog("🔄 Reboot VPS\n", 'red');
echo colorLog("PERINGATAN: Ini akan me-reboot VPS Anda. Semua sesi yang tidak disimpan akan hilang.\n", 'yellow');
echo colorLog("Apakah Anda yakin ingin melanjutkan? (y/n): ", 'cyan');
if (strtolower(trim(readline())) === 'y') {
echo colorLog("Perintah reboot dikirim...\n", 'red');
runCommand("sudo reboot");
} else {
echo colorLog("Reboot dibatalkan.\n", 'green');
}
}
// --- Main Program Logic ---
if (posix_getuid() !== 0) {
echo colorLog("Error: Skrip ini harus dijalankan dengan sudo.", 'red') . "\n";
echo "Silakan coba lagi dengan: " . colorLog("sudo php " . basename(__FILE__), 'yellow') . "\n";
exit(1);
}
// Inisialisasi variabel global
$userHome = getUserHome();
$configFile = $userHome . '/.nexus_tool_config.json';
$screenPath = findExecutable('screen');
$nexusCliPath = findExecutable('nexus-network', $userHome);
echo colorLog("============================================\n", 'blue');
echo colorLog(" Selamat Datang di Nexus Node Tool v2.4 \n", 'blue');
echo colorLog("============================================\n", 'blue');
echo "Pilih Opsi:\n";
echo "1. " . colorLog("[INSTALASI AWAL]", 'cyan') . " (Jalankan jika ini pertama kali)\n";
echo "2. " . colorLog("[MENU UTAMA]", 'green') . " (Langsung ke manajemen node)\n";
echo colorLog("Masukkan pilihan Anda (1/2): ", "yellow");
if (trim(readline()) === '1') {
initialSetup();
exit;
}
loadConfiguration();
while (true) {
// Perbarui path nexusCliPath setiap kali masuk loop utama
// Ini penting jika CLI baru diinstal atau diperbarui
$nexusCliPath = findExecutable('nexus-network', $userHome);
echo colorLog("\nTekan [Enter] untuk menampilkan menu...", 'cyan');
readline();
passthru('clear');
echo colorLog("================= MENU MANAJEMEN NEXUS =================\n", 'blue');
echo colorLog("Konfigurasi Tersimpan:\n", 'cyan');
$displayWallet = $walletAddress ?? colorLog('[Belum diatur]', 'red');
echo "- Wallet Address : " . colorLog($displayWallet, 'yellow') . "\n";
$displayNodeId = $nodeId ?? colorLog('[Belum diatur]', 'red');
echo "- Node ID : " . colorLog($displayNodeId, 'yellow') . "\n";
echo colorLog("========================================================\n", 'blue');
echo "\nPilih tindakan:\n";
echo "1. " . colorLog("Cek Status Dependensi", 'green') . "\n";
echo "2. Update versi Nexus CLI\n";
echo "3. Register/Update alamat wallet\n";
echo "4. Create/Update Node ID\n";
echo "5. " . colorLog("Tambahkan NodeID yang sudah ada (foreground)", 'yellow') . "\n";
echo "6. Jalankan Node dengan Node ID tersimpan (foreground)\n";
echo "7. " . colorLog("Jalankan Node dengan Node ID tersimpan (background)", 'cyan') . "\n";
echo "8. " . colorLog("Jalankan Node di background (Custom Thread)", 'yellow') . "\n";
echo "9. Lihat Sesi Screen (Logs)\n";
echo "10. " . colorLog("Hentikan Sesi Screen", 'red') . "\n";
echo "11. " . colorLog("Utilitas Sistem", 'yellow') . "\n";
echo "12. Keluar dari skrip\n";
echo colorLog("Masukkan pilihan Anda [1-12]: ", "yellow");
$choice = readline();
switch (trim($choice)) {
case '1': checkStatus(); break;
case '2': updateNexusCLI(); break;
case '3': registerWallet(); break;
case '4': createNodeId(); break;
case '5': startExistingNode(); break;
case '6': startNode(); break;
case '7': startNodeInBackground(); break;
case '8': startNodeWithThreads(); break;
case '9': viewScreenLogs(); break;
case '10': stopScreen(); break;
case '11': showSystemUtilitiesMenu(); break;
case '12': echo colorLog("👋 Sampai jumpa!\n", 'green'); exit(0);
default: echo colorLog("Pilihan tidak valid. Silakan coba lagi.\n", 'red'); break;
}
}
function showSystemUtilitiesMenu(): void {
while (true) {
passthru('clear');
echo colorLog("========== MENU UTILITAS SISTEM ==========\n", 'yellow');
echo "1. Cek & Update Versi GLIBC\n";
echo "2. Mengatasi VPS Killed (Buat Swap)\n";
echo "3. Reboot VPS\n";
echo "4. Kembali ke Menu Utama\n";
echo colorLog("Masukkan pilihan Anda [1-4]: ", "yellow");
$choice = readline();
switch (trim($choice)) {
case '1': manageGlibc(); break;
case '2': manageSwap(); break;
case '3': rebootVps(); break;
case '4': return; // Kembali ke loop menu utama
default: echo colorLog("Pilihan tidak valid.\n", 'red'); break;
}
echo colorLog("\nTekan [Enter] untuk kembali ke menu utilitas...", 'cyan');
readline();
}
}