invokable provision script controllers

This commit is contained in:
2025-04-07 13:31:10 +01:00
parent a708c69698
commit 1ffabe8093
3 changed files with 87 additions and 62 deletions

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProvisionScript extends Controller
{
public function __invoke(Request $request)
{
$validated = $request->validate([
'sudo_password' => ['required', 'string'],
'hostname' => ['required', 'string'],
'server_id' => ['required', 'integer', 'exists:servers,id'],
]);
$script = file_get_contents(base_path('provision.sh'));
$keystonePublicKey = file_get_contents(storage_path('app/private/ssh/id_ed25519.pub'));
$script = str_replace('[!hostname!]', $validated['hostname'], $script);
$script = str_replace('[!sudo_password!]', $validated['sudo_password'], $script);
$script = str_replace('[!server_id!]', $validated['server_id'], $script);
$script = str_replace('[!keystonepublickey!]', $keystonePublicKey, $script);
$script = str_replace('[!callback!]', route('provision.callback'), $script);
return response($script)
->header('Content-Type', 'text/plain');
}
}