feat: show install command on machine creation

This commit is contained in:
xboard
2026-04-17 06:47:05 +08:00
parent e297b5fe9f
commit a74cc2f19d
4 changed files with 7 additions and 6 deletions
@@ -72,6 +72,7 @@ class MachineController extends Controller
return $this->success([ return $this->success([
'id' => $machine->id, 'id' => $machine->id,
'token' => $machine->token, 'token' => $machine->token,
'install_command' => $this->buildInstallCommand($request, $machine),
]); ]);
} }
@@ -191,12 +192,12 @@ class MachineController extends Controller
private function buildInstallCommand(Request $request, ServerMachine $machine): string private function buildInstallCommand(Request $request, ServerMachine $machine): string
{ {
$panelUrl = rtrim((string) (config('app.url') ?: $request->getSchemeAndHttpHost()), '/'); $panelUrl = rtrim((string) (admin_setting('app_url') ?: $request->getSchemeAndHttpHost()), '/');
$installerUrl = 'https://raw.githubusercontent.com/cedar2025/xboard-node/main/install.sh'; $installerUrl = 'https://raw.githubusercontent.com/cedar2025/xboard-node/main/install.sh';
return sprintf( return sprintf(
'bash <(curl -fsSL %s) --panel %s --token %s --machine-id %d --yes', 'curl -fsSL %s | sudo bash -s -- --mode machine --panel %s --token %s --machine-id %d',
escapeshellarg($installerUrl), $installerUrl,
escapeshellarg($panelUrl), escapeshellarg($panelUrl),
escapeshellarg($machine->token), escapeshellarg($machine->token),
$machine->id $machine->id
@@ -17,7 +17,7 @@ class ManageController extends Controller
public function getNodes(Request $request) public function getNodes(Request $request)
{ {
$servers = ServerService::getAllServers()->map(function ($item) { $servers = ServerService::getAllServers()->map(function ($item) {
$item['groups'] = ServerGroup::whereIn('id', $item['group_ids'])->get(['name', 'id']); $item['groups'] = ServerGroup::whereIn('id', $item['group_ids'] ?? [])->get(['name', 'id']);
$item['parent'] = $item->parent; $item['parent'] = $item->parent;
return $item; return $item;
}); });
+1 -1
View File
@@ -429,7 +429,7 @@ class Server extends Model
public function groups() public function groups()
{ {
return ServerGroup::whereIn('id', $this->group_ids)->get(); return ServerGroup::whereIn('id', $this->group_ids ?? [])->get();
} }
public function routes() public function routes()