refs #503 #504 #639 updates config for nelmio swagger and adapts getoglives to oglivecli and adds filename to the json output

ogboot_debian_installer
Luis Gerardo Romero Garcia 2024-08-20 10:46:53 +00:00
parent 23e660610f
commit fcbc625545
5 changed files with 31 additions and 149 deletions

View File

@ -509,13 +509,14 @@ function list_installed_oglives() {
local DATA=$(jq -n \
--arg id "$CHECKSUM" \
--arg filename "$OGLIVEDIR" \
--arg dist "$OGLIVEDIST" \
--arg krnl "$OGLIVEKRNL" \
--arg arch "$OGLIVEARCH" \
--arg rev "$OGLIVEREV" \
--arg dir "$TFTPDIR/$OGLIVEDIR" \
--arg iso "" \
'{id: $id, distribution: $dist, kernel: $krnl, architecture: $arch, revision: $rev, directory: $dir, iso: $iso}')
'{id: $id, filename: $filename, distribution: $dist, kernel: $krnl, architecture: $arch, revision: $rev, directory: $dir, iso: $iso}')
installed_ogLives+=("$DATA")

View File

@ -12,4 +12,5 @@ return [
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true],
App\OgBootBundle\OgBootBundle::class => ['all' => true],
Nelmio\ApiDocBundle\NelmioApiDocBundle::class => ['all' => true],
];

View File

@ -1,3 +1,7 @@
#index:
# path: /
# controller: App\Controller\DefaultController::index
app.swagger_ui:
path: /api/doc
methods: GET
defaults: { _controller: nelmio_api_doc.controller.swagger_ui }

View File

@ -225,31 +225,6 @@ def downloadComposer():
logger.info(f"composer.phar downloaded to {INSTALL_OGBOOT_TARGET}/bin")
return 0
def install_swagger_ui():
global INSTALL_TARGET
# Define la URL del archivo de Swagger UI que quieres descargar
swagger_ui_url = "https://github.com/swagger-api/swagger-ui/archive/refs/heads/master.zip"
# Define la ruta donde quieres descomprimir Swagger UI
swagger_ui_path = "/tmp/swagger-ui"
# Define la ruta de destino para los archivos de Swagger UI
destination_path = os.path.join(INSTALL_TARGET, "public")
# Crea los directorios si no existen
os.makedirs(swagger_ui_path, exist_ok=True)
os.makedirs(destination_path, exist_ok=True)
# Descarga el archivo de Swagger UI
urllib.request.urlretrieve(swagger_ui_url, "/tmp/swagger-ui.zip")
# Descomprime el archivo de Swagger UI en la ruta especificada
with zipfile.ZipFile("/tmp/swagger-ui.zip", "r") as zip_ref:
zip_ref.extractall(swagger_ui_path)
# Copia los archivos de Swagger UI al directorio de destino
for file_path in glob.glob(os.path.join(swagger_ui_path, "swagger-ui-master", "dist", "*")):
shutil.copy(file_path, destination_path)
# Elimina el archivo descargado y el directorio temporal
os.remove("/tmp/swagger-ui.zip")
shutil.rmtree(swagger_ui_path)
# Genera el archivo swagger.json
os.system(f"{os.path.join(INSTALL_TARGET, 'vendor', 'bin', 'openapi')} {INSTALL_TARGET}/src/OgBootBundle/Controller/ -o {destination_path}/swagger.json")
logger.info(f"Swagger UI installed on {destination_path}.")
def og_core_create_user(OPENGNSYS_CLIENT_USER):
try:
@ -365,7 +340,6 @@ def og_boot_composer_install():
if os.path.exists(composer_lock_path):
os.remove(composer_lock_path)
install_swagger_ui() # Instalar Swagger UI
subprocess.call(["sudo", "chown", "-R", "ogboot:ogboot", f"{INSTALL_OGBOOT_TARGET}/public"])
logger.info("Application skeleton created and composer.lock file removed.")
@ -494,10 +468,10 @@ TFTP_OPTIONS="--secure"
logger.warning(f"The symbolic link already exists: {symlink_target}")
#Descargar oglive
logger.info("Downloading oglive...")
iso_name = "ogLive-focal-5.13.0-27-beta-amd64-r20210706.5b4bf5f.iso"
iso_url = "https://ognproject.evlt.uma.es/trac/downloads/ogLive-focal-5.13.0-27-beta-amd64-r20210706.5b4bf5f.iso"
try:
result = subprocess.run(
["sudo", "/opt/ogboot/bin/oglivecli", "download", iso_name],
["sudo", "/opt/ogboot/bin/oglivecli", "download", iso_url],
check=True,
capture_output=True,
text=True
@ -893,11 +867,11 @@ def modify_php_fpm_config():
with open(php_fpm_conf_path, 'w') as file:
for line in config_lines:
if line.startswith('user ='):
file.write('user = www-data\n')
file.write('user = ogboot\n')
elif line.startswith('group ='):
file.write('group = ogboot\n')
elif line.startswith('listen.owner ='):
file.write('listen.owner = www-data\n')
file.write('listen.owner = ogboot\n')
elif line.startswith('listen.group ='):
file.write('listen.group = ogboot\n')
else:

View File

@ -173,44 +173,21 @@ public function getDownloadMenu(): Response
* response=200,
* description="Successful operation",
* @OA\JsonContent(
* type="array",
* @OA\Items(
* type="object",
* @OA\Property(
* property="id",
* type="string",
* description="Unique identifier for the ogLive client, generated from ogclient.sqfs.sum",
* example="9e49a085ba74f97a81bdf9b3d0785094"
* ),
* @OA\Property(
* property="distribution",
* type="string",
* description="Distribution name of the installed ogLive client"
* ),
* @OA\Property(
* property="kernel",
* type="string",
* description="Kernel version of the installed ogLive client"
* ),
* @OA\Property(
* property="architecture",
* type="string",
* description="Architecture of the installed ogLive client"
* ),
* @OA\Property(
* property="revision",
* type="string",
* description="Revision of the installed ogLive client"
* ),
* @OA\Property(
* property="directory",
* type="string",
* description="Directory name of the installed ogLive client"
* ),
* @OA\Property(
* property="iso",
* type="string",
* description="ISO file name of the installed ogLive client"
* type="object",
* @OA\Property(property="default_oglive", type="string", description="Default ogLive client"),
* @OA\Property(
* property="installed_ogLives",
* type="array",
* @OA\Items(
* type="object",
* @OA\Property(property="id", type="string", description="Unique identifier for the ogLive client"),
* @OA\Property(property="filename", type="string", description="Filename of the ogLive client"),
* @OA\Property(property="distribution", type="string", description="Distribution name of the installed ogLive client"),
* @OA\Property(property="kernel", type="string", description="Kernel version of the installed ogLive client"),
* @OA\Property(property="architecture", type="string", description="Architecture of the installed ogLive client"),
* @OA\Property(property="revision", type="string", description="Revision of the installed ogLive client"),
* @OA\Property(property="directory", type="string", description="Directory name of the installed ogLive client"),
* @OA\Property(property="iso", type="string", description="ISO file name of the installed ogLive client")
* )
* )
* )
@ -223,89 +200,14 @@ public function getDownloadMenu(): Response
*/
public function getOglives(): Response
{
$directoryPath = '/opt/ogboot/tftpboot/';
$pattern = '/^ogLive-([\w.-]+)-r(\d+)$/';
// Llama al servicio que ejecuta el comando oglivecli y procesa la salida
$ogLiveConfigResult = $this->curlRequestService->callOgLive("list_installed_oglives");
$ogLives = [];
if ($handle = opendir($directoryPath)) {
error_log("Opened directory: $directoryPath");
while (false !== ($entry = readdir($handle))) {
error_log("Processing entry: $entry");
if ($entry != "." && $entry != ".." && is_dir($directoryPath . $entry)) {
if (preg_match($pattern, $entry, $matches)) {
error_log("Entry matches pattern: $entry");
// Evitar directorios .old
if (substr($entry, -4) === '.old') {
error_log("Ignoring old directory: $entry");
continue;
}
// Extraer detalles
$distribution = $matches[1];
$revision = $matches[2];
$directory = $entry;
$ogLivePath = $directoryPath . $entry;
// Obtener el ID del archivo ogclient.sqfs.sum
$sumFile = $ogLivePath . '/ogclient.sqfs.sum';
$id = '';
if (file_exists($sumFile)) {
$id = trim(file_get_contents($sumFile));
}
// Obtener el nombre del archivo ISO
$iso = '';
$oldInfoFile = $ogLivePath . '/OLDINFOFILE';
if (file_exists($oldInfoFile)) {
$iso = trim(file($oldInfoFile, FILE_USE_INCLUDE_PATH | FILE_IGNORE_NEW_LINES)[0]);
}
// Obtener la versión del kernel
$kernelFile = $ogLivePath . '/ogvmlinuz';
$kernel = '';
if (file_exists($kernelFile)) {
$fileOutput = shell_exec("file -bkr $kernelFile");
if (preg_match('/Linux kernel.*version (\d+\.\d+\.\d+)/', $fileOutput, $kernelMatches)) {
$kernel = $kernelMatches[1];
}
}
// Asumir arquitectura como 'amd64'; puedes refinar esto si se necesita más lógica
$architecture = 'amd64';
// Construir el objeto
$ogLives[] = [
'id' => $id,
'distribution' => $distribution,
'kernel' => $kernel,
'architecture' => $architecture,
'revision' => $revision,
'directory' => $directory,
'iso' => $iso
];
} else {
error_log("Entry does not match pattern: $entry");
}
} else {
error_log("Entry is not a directory: $directoryPath$entry");
}
}
closedir($handle);
error_log("Closed directory: $directoryPath");
}
if (!empty($ogLives)) {
error_log("Returning ogLives data");
return new JsonResponse($ogLives, Response::HTTP_OK);
} else {
error_log("No ogLive clients found");
if (empty($ogLiveConfigResult) || !isset($ogLiveConfigResult['installed_ogLives'])) {
return new JsonResponse(['error' => 'No ogLive clients found'], Response::HTTP_NOT_FOUND);
}
return new JsonResponse($ogLiveConfigResult, Response::HTTP_OK);
}
/**