refs #1148 #1155 Adds no compresion cpio option to setsmbpass, fix case if ogliveinfo not exists in oglive list, changes filename of oglives when is installed

ogboot-log opengnsys_devel-0.0.10
Luis Gerardo Romero Garcia 2024-11-18 16:04:11 +01:00
parent 6cdde68206
commit 5ea829c99b
3 changed files with 59 additions and 41 deletions

View File

@ -296,8 +296,9 @@ function install() {
*)
OGLIVEARCH="i386" ;;
esac
OGLIVEDIR="$TFTPDIR/$DEFOGLIVE-${OGLIVEKRNL%%-*}-$OGLIVEARCH-$OGLIVEREV"
OGLIVEDIR="${OGLIVEDIR/amd64-/}"
#OGLIVEDIR="$TFTPDIR/$DEFOGLIVE-${OGLIVEKRNL%%-*}-$OGLIVEARCH-$OGLIVEREV"
#OGLIVEDIR="${OGLIVEDIR/amd64-/}"
OGLIVEDIR=$TFTPDIR$(basename "$OGLIVEFILE" .iso)
OGINITRD="$OGLIVEDIR/oginitrd.img"
[ ! -r "$OGINITRD" ] && OGINITRD="$TFTPDIR/$DEFOGLIVE/oginitrd.img"
@ -556,14 +557,14 @@ function list_installed_oglives() {
# Verificar si el directorio TFTPDIR es accesible
if [ ! -d "$TFTPDIR" ]; then
echo "{\"error\": \"SERVER_ERROR\", \"message\": \"TFTP directory not found or not accessible.\"}"
echo '{"error": "SERVER_ERROR", "message": "TFTP directory not found or not accessible."}'
exit 500
fi
# Buscar directorios de ogLive instalados
INST=$(find "$TFTPDIR/" -type d -name "$DEFOGLIVE-*" -a ! -name "*.old" -printf "%f\n" 2>/dev/null | sort)
if [ -z "$INST" ]; then
echo "{\"error\": \"NOT_FOUND\", \"message\": \"No installed ogLive clients found.\"}"
echo '{"error": "NOT_FOUND", "message": "No installed ogLive clients found."}'
exit 404
fi
@ -580,36 +581,47 @@ function list_installed_oglives() {
local OGLIVEJSON="$OGLIVEDIR/oglive_info.json"
local CHECKSUM_FILE="$OGLIVEDIR/ogclient.sqfs.sum"
# Verificar que el archivo oglive_info.json existe en el directorio.
# Intentar obtener el ID desde el archivo ogclient.sqfs.sum
if [ -f "$CHECKSUM_FILE" ]; then
CHECKSUM=$(cut -d ' ' -f 1 "$CHECKSUM_FILE")
else
local DATA=$(jq -n \
--arg id "unknown" \
--arg error "CHECKSUM_NOT_FOUND" \
--arg message "Checksum file not found or invalid in $OGLIVEDIR. Manual deletion is recommended." \
'{id: $id, error: $error, message: $message}')
installed_ogLives+=("$DATA")
continue
fi
# Verificar que el archivo oglive_info.json existe en el directorio
if [ -f "$OGLIVEJSON" ]; then
OGLIVEDIST=$(jq -r '.OGLIVEDIST' "$OGLIVEJSON")
OGLIVEKRNL=$(jq -r '.OGLIVEKRNL' "$OGLIVEJSON")
OGLIVEARCH=$(jq -r '.OGLIVEARCH' "$OGLIVEJSON")
OGLIVEREV=$(jq -r '.OGLIVEREV' "$OGLIVEJSON")
else
echo "{\"error\": \"NOT_FOUND\", \"message\": \"oglive_info.json not found in $OGLIVEDIR.\"}"
continue # Continuar con el siguiente ogLive en lugar de detener el proceso
fi
# Obtener el checksum del archivo ogclient.sqfs.sum
if [ -f "$CHECKSUM_FILE" ]; then
CHECKSUM=$(cat "$CHECKSUM_FILE" | cut -d ' ' -f 1)
# Crear el JSON con los datos del ogLive
local DATA=$(jq -n \
--arg id "$CHECKSUM" \
--arg dist "$OGLIVEDIST" \
--arg krnl "$OGLIVEKRNL" \
--arg arch "$OGLIVEARCH" \
--arg rev "$OGLIVEREV" \
--arg dir "$OGLIVEDIR" \
'{id: $id, distribution: $dist, kernel: $krnl, architecture: $arch, revision: $rev, directory: $dir}')
installed_ogLives+=("$DATA")
else
echo "{\"error\": \"NOT_FOUND\", \"message\": \"Checksum file not found in $OGLIVEDIR.\"}"
# Informar que el archivo oglive_info.json no existe y que el ogLive puede estar corrupto
local DATA=$(jq -n \
--arg id "$CHECKSUM" \
--arg error "CORRUPT_OG_LIVE" \
--arg message "oglive_info.json not found in $OGLIVEDIR. ogLive may be corrupted." \
'{id: $id, error: $error, message: $message}')
installed_ogLives+=("$DATA")
continue
fi
# Crear el JSON con los datos del ogLive
local DATA=$(jq -n \
--arg id "$CHECKSUM" \
--arg dist "$OGLIVEDIST" \
--arg krnl "$OGLIVEKRNL" \
--arg arch "$OGLIVEARCH" \
--arg rev "$OGLIVEREV" \
--arg dir "$OGLIVEDIR" \
'{id: $id, distribution: $dist, kernel: $krnl, architecture: $arch, revision: $rev, directory: $dir}')
installed_ogLives+=("$DATA")
oglive_count=$((oglive_count + 1))
# Verificar si es el ogLive por defecto
@ -618,7 +630,7 @@ function list_installed_oglives() {
# Verificar si se encontraron ogLives
if [ "$oglive_count" -eq 0 ]; then
echo "{\"error\": \"NOT_FOUND\", \"message\": \"No valid ogLive clients found.\"}"
echo '{"error": "NOT_FOUND", "message": "No valid ogLive clients found."}'
exit 404
fi

View File

@ -67,23 +67,29 @@ for OGLIVE in $LIST; do
echo "TMPDIR $TMPDIR"
cd $TMPDIR || { echo "Error: no se pudo cambiar al directorio temporal."; exit 3; }
echo "Verificar si el archivo es gzip o lz4 antes de descomprimir"
if file "$CLIENTINITRD" | grep -q "gzip compressed data"; then
if ! gzip -dc "$CLIENTINITRD" | cpio -im; then
echo "Error: No se pudo descomprimir y extraer $CLIENTINITRD con gzip."
exit 4
fi
COMPRESS_CMD="gzip -9c"
elif file "$CLIENTINITRD" | grep -q "LZ4 compressed data"; then
if ! lz4 -d "$CLIENTINITRD" | cpio -im; then
echo "Error: No se pudo descomprimir y extraer $CLIENTINITRD con lz4."
exit 4
fi
COMPRESS_CMD="lz4 -c"
else
echo "Error: $CLIENTINITRD no está en formato gzip o lz4."
echo "Verificar si el archivo es gzip, lz4 o ASCII cpio antes de descomprimir"
if file "$CLIENTINITRD" | grep -q "gzip compressed data"; then
if ! gzip -dc "$CLIENTINITRD" | cpio -im; then
echo "Error: No se pudo descomprimir y extraer $CLIENTINITRD con gzip."
exit 4
fi
COMPRESS_CMD="gzip -9c"
elif file "$CLIENTINITRD" | grep -q "LZ4 compressed data"; then
if ! lz4 -d "$CLIENTINITRD" | cpio -im; then
echo "Error: No se pudo descomprimir y extraer $CLIENTINITRD con lz4."
exit 4
fi
COMPRESS_CMD="lz4 -c"
elif file "$CLIENTINITRD" | grep -q "ASCII cpio archive"; then
if ! cpio -im < "$CLIENTINITRD"; then
echo "Error: No se pudo extraer $CLIENTINITRD como archivo cpio."
exit 4
fi
COMPRESS_CMD="cat" # No compresión, simplemente se pasa el archivo tal cual
else
echo "Error: $CLIENTINITRD no está en formato gzip, lz4 o ASCII cpio."
exit 4
fi
if [ -f scripts/ogfunctions ]; then
sudo sed -i "s/OPTIONS=\(.*\)user=\w*\(.*\)pass=\w*\(.*\)/OPTIONS=\1user=$SAMBAUSER\2pass=$SAMBAPASS\3/" scripts/ogfunctions

View File

@ -21,7 +21,7 @@ echo "${MSG_LAUNCHCLIENT:-.}"
if [ -f "/usr/share/OGAgent/opengnsys/linux/OGAgentService.py" -a "$ogstatus" != "offline" ]; then
# Ejecutar servicio cliente.
cd /usr/share/OGAgent
sed -i -e "/remote=/ s/https:/http:/; /remote=/ s%192.168.[^/]*/%${ogcore}:8000/%" cfg/ogagent.cfg
export OGAGENTCFG_OGCORE_IP=$ogcore
python3 -m opengnsys.linux.OGAgentService fg
else
for FILE in index $OGGROUP $(ogGetIpAddress)