refs #437 Adds better control in rsync process

pull/3/head
Luis Gerardo Romero Garcia 2024-06-24 13:47:18 +02:00
parent cc0a0bffbc
commit 636c6fb2c5
1 changed files with 47 additions and 14 deletions

View File

@ -377,30 +377,54 @@ function install() {
echo "Mounting SquashFS and checking Rsync version..."
OGSQFS=$OGLIVEDIR/ogclient.sqfs
# Intentar montar SquashFS
echo "Attempting to mount SquashFS..."
if mount -o loop,ro $OGSQFS $TMPDIR; then
# Obtener versiones de rsync
echo "Mounted SquashFS successfully."
RSYNCSERV=$(rsync --version 2>/dev/null | awk '/protocol/ {print $6}')
RSYNCCLNT=$(chroot $TMPDIR /usr/bin/rsync --version 2>/dev/null | awk '/protocol/ {print $6}')
echo "RSYNCSERV: $RSYNCSERV"
echo "RSYNCCLNT: $RSYNCCLNT"
# Lógica para manejar rsync
if [ -z "$RSYNCSERV" ] || [ "$RSYNCSERV" -gt "${RSYNCCLNT:-1}" ]; then
[ -e "$OPENGNSYS/client/bin/rsync-$RSYNCSERV" ] && \
mv -f "$OPENGNSYS/client/bin/rsync-$RSYNCSERV" "$OPENGNSYS/client/bin/rsync" || \
{ echo "{\"error\": \"mv rsync failed.\"}"; umount $TMPDIR; exit 1; }
echo "Comparing server and client versions for rsync..."
if [ -e "$OPENGNSYS/client/bin/rsync-$RSYNCSERV" ]; then
echo "File exists: $OPENGNSYS/client/bin/rsync-$RSYNCSERV"
if mv -f "$OPENGNSYS/client/bin/rsync-$RSYNCSERV" "$OPENGNSYS/client/bin/rsync"; then
echo "Moved rsync successfully"
else
echo "{\"error\": \"mv rsync failed.\"}"
# Optional exit if moving rsync fails
exit 1
fi
else
echo "File not found: $OPENGNSYS/client/bin/rsync-$RSYNCSERV"
echo "Rsync version $RSYNCSERV not found in $OPENGNSYS/client/bin. No action needed."
# No exit here, as this is not a critical error
fi
else
[ -e "$OPENGNSYS/client/bin/rsync" ] && \
mv -f "$OPENGNSYS/client/bin/rsync" "$OPENGNSYS/client/bin/rsync-$($OPENGNSYS/client/bin/rsync --version 2>/dev/null | awk '/protocol/ {print $6}')" || \
{ echo "{\"error\": \"mv rsync client failed.\"}"; umount $TMPDIR; exit 1; }
echo "Server rsync version is not greater, checking default rsync..."
if [ -e "$OPENGNSYS/client/bin/rsync" ]; then
echo "File exists: $OPENGNSYS/client/bin/rsync"
if mv -f "$OPENGNSYS/client/bin/rsync" "$OPENGNSYS/client/bin/rsync-$($OPENGNSYS/client/bin/rsync --version 2>/dev/null | awk '/protocol/ {print $6}')"; then
echo "Moved rsync client successfully"
else
echo "{\"error\": \"mv rsync client failed.\"}"
# Optional exit if moving rsync fails
exit 1
fi
else
echo "File not found: $OPENGNSYS/client/bin/rsync"
echo "Default rsync not found in $OPENGNSYS/client/bin. No action needed."
# No exit here, as this is not a critical error
fi
fi
echo "Unmounting SquashFS..."
if umount $TMPDIR; then
echo "Unmounted successfully"
# Espera antes de intentar eliminar el directorio
sleep 1
# Intentar eliminar el directorio TMPDIR
if rmdir $TMPDIR; then
echo "Cleaned up successfully"
else
@ -414,8 +438,17 @@ function install() {
echo "{\"error\": \"mount SquashFS failed.\"}"
fi
local json_output
json_output=$(jq -n --arg dist "$OGLIVEDIST" --arg krnl "$OGLIVEKRNL" --arg arch "$OGLIVEARCH" --arg rev "$OGLIVEREV" --arg dir "$OGLIVEDIR" --arg iso "$(basename "$OGLIVEFILE")" \
echo "Updating JSON file..."
# Crear JSON output
json_output=$(jq -n \
--arg dist "$OGLIVEDIST" \
--arg krnl "$OGLIVEKRNL" \
--arg arch "$OGLIVEARCH" \
--arg rev "$OGLIVEREV" \
--arg dir "$OGLIVEDIR" \
--arg iso "$(basename "$OGLIVEFILE")" \
'{distribution: $dist, kernel: $krnl, architecture: $arch, revision: $rev, directory: $dir, iso: $iso}')
echo "$json_output"