summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xadmin/Interface/EjecutarScript8
-rw-r--r--admin/WebConsole/asistentes/jscripts/asistentes.js4
-rwxr-xr-xclient/shared/lib/httpd/LogCommand.sh12
-rwxr-xr-xclient/shared/lib/httpd/LogSession.sh10
-rwxr-xr-xclient/shared/scripts/deployImage35
-rwxr-xr-xclient/shared/scripts/restoreImage17
-rwxr-xr-xclient/shared/scripts/updateCache44
7 files changed, 80 insertions, 50 deletions
diff --git a/admin/Interface/EjecutarScript b/admin/Interface/EjecutarScript
index adac9af7..9793290c 100755
--- a/admin/Interface/EjecutarScript
+++ b/admin/Interface/EjecutarScript
@@ -8,10 +8,9 @@ TIME1=$SECONDS
# Clear temporary file used as log track by httpdlog
# Limpia los ficheros temporales usados como log de seguimiento para httpdlog
-echo " " > $OGLOGSESSION; echo " " > $OGLOGCOMMAND; echo " " > ${OGLOGCOMMAND}.tmp
+echo -n "" > $OGLOGSESSION; echo -n "" > $OGLOGCOMMAND
# Registro de inicio de ejecución
-#echo "[START Interface ] Run this command: $0 $*" | tee -a $OGLOGSESSION $OGLOGFILE
echo "$MSG_INTERFACE_START $0 $*" | tee -a $OGLOGSESSION $OGLOGFILE
echo -e "\n Instrucciones a ejecutar: *****************************" >> $OGLOGFILE
@@ -20,7 +19,9 @@ cat $1 >> $OGLOGFILE
echo -e "\n Salida de las instrucciones: *****************************" >> $OGLOGFILE
chmod +x $1
-$1 &>> $OGLOGCOMMAND
+# Si mandamos la salida a OGLOGCOMMAND reescribimos lo que manda el comando.
+#$1 &>> $OGLOGCOMMAND
+$1
RETVAL=$?
@@ -35,7 +36,6 @@ fi
# Registro de fin de ejecución
-#echo "[END Interface] Command finished with this code: $RETVAL" | tee -a $OGLOGSESSION $OGLOGFILE
echo "$MSG_INTERFACE_END $RETVAL" | tee -a $OGLOGSESSION $OGLOGFILE
diff --git a/admin/WebConsole/asistentes/jscripts/asistentes.js b/admin/WebConsole/asistentes/jscripts/asistentes.js
index 7a5b472e..00009538 100644
--- a/admin/WebConsole/asistentes/jscripts/asistentes.js
+++ b/admin/WebConsole/asistentes/jscripts/asistentes.js
@@ -48,7 +48,7 @@ if (form.modo[0].checked)
command="deployImage REPO /" + form.idimagen.value + " "+diskPart[0]+" " + diskPart[1] + " " + protocol ;
form.codigo.value="\
echo [0] $MSG_SCRIPTS_TASK_START " + command +" | tee -a $OGLOGSESSION \n \ " +
-command + " | tee -a $OGLOGCOMMAND";
+command + " \n";
//form.codigo.value="deployImage REPO /" + form.idimagen.value + " 1 " + form.idparticion.value + " " + protocol ;
}
else
@@ -56,7 +56,7 @@ else
command="updateCache REPO /" + form.idimagen.value + ".img" + " " + protocol ;
form.codigo.value="\
echo [0] $MSG_SCRIPTS_TASK_START " + command +" | tee -a $OGLOGSESSION \n \ " +
-command + " | tee -a $OGLOGCOMMAND";
+command + " \n";
//form.codigo.value="updateCache REPO /" + form.idimagen.value + ".img" + " " + protocol ;
}
diff --git a/client/shared/lib/httpd/LogCommand.sh b/client/shared/lib/httpd/LogCommand.sh
index 22a73251..54c4881e 100755
--- a/client/shared/lib/httpd/LogCommand.sh
+++ b/client/shared/lib/httpd/LogCommand.sh
@@ -1,8 +1,10 @@
#!/bin/bash
echo "Content-type: text/html"
echo ""
-echo "<html><head><meta http-equiv='Refresh' content='5,URL=./LogCommand.sh'> <link rel='stylesheet' type='text/css' href='oglive.css' /> <title>Bash as CGI"
-echo "</title></head><body>"
+echo "<html><head>"
+echo "<meta charset='utf-8'>"
+echo "<meta http-equiv='Refresh' content='5,URL=./LogCommand.sh'> <link rel='stylesheet' type='text/css' href='oglive.css' />"
+echo "<title>Bash as CGI</title></head><body>"
$(strings /tmp/command.log > /tmp/command.log.tmp)
@@ -14,7 +16,7 @@ echo "<tr>"
echo "<TEXTAREA NAME='trackloghead' ROWS='13' COLS='175'>"
#echo "$(head -n 10 /tmp/command.log.tmp | uniq)"
# UHU - 2013/07/05 - Se incluye el simbolo % y la palabra sent para que se muestre la salida de rsync
-echo "$(egrep -v '%|sent|^Elapsed:\|^Total [Tt]ime:\|^-\|^|\|^bytes\|^\[' /tmp/command.log.tmp | uniq | head -n 15)"
+echo "$(egrep -v '^bytes|%|sent|^Elapsed:|^Total [Tt]ime:|^-|^\\|^\/' /tmp/command.log.tmp | uniq | head -n 15)"
echo "</TEXTAREA>"
echo "</tr>"
@@ -25,7 +27,7 @@ echo "<tr>"
echo "<TEXTAREA NAME='tracklogtail' ROWS='2' COLS='175'>"
#echo "$(tail -n 5 /tmp/command.log.tmp | uniq)"
# UHU - 2013/07/05 - Se incluye el simbolo % y la palabra sent para que se muestre la salida de rsync
-echo "$(egrep '%|sent|^Elapsed:\|^Total [Tt]ime:\|^-\|^|\|^bytes' /tmp/command.log.tmp | uniq | tail -n 2)"
+echo "$(egrep '^bytes|%|sent|^Elapsed:|^Total [Tt]ime:|^-|^\\|^\/' /tmp/command.log.tmp | uniq | tail -n 2)"
echo "</TEXTAREA>"
@@ -34,4 +36,4 @@ echo "</tr>"
echo "</table>"
-echo "</body></html>" \ No newline at end of file
+echo "</body></html>"
diff --git a/client/shared/lib/httpd/LogSession.sh b/client/shared/lib/httpd/LogSession.sh
index a5d18e68..250f382e 100755
--- a/client/shared/lib/httpd/LogSession.sh
+++ b/client/shared/lib/httpd/LogSession.sh
@@ -1,8 +1,10 @@
#!/bin/bash
echo "Content-type: text/html"
echo ""
-echo "<html><head> <meta http-equiv='Refresh' content='5,URL=./LogSession.sh'> <title>Bash as CGI"
-echo "</title>"
+echo "<html><head>"
+echo " <meta charset='utf-8'"
+echo " <meta http-equiv='Refresh' content='5,URL=./LogSession.sh'>"
+echo " <title>Bash as CGI</title>"
echo "<style type='text/css'>"
echo "<!--"
@@ -17,15 +19,11 @@ echo "} "
echo "-->"
echo "</style>"
-
-
echo "</head><body>"
echo "<TEXTAREA NAME='contenido' ROWS='115' COLS='175' >"
echo "$(cat /tmp/session.log | uniq )"
echo "</TEXTAREA>"
-
-
echo "</body></html>"
diff --git a/client/shared/scripts/deployImage b/client/shared/scripts/deployImage
index 5473c674..e11e571d 100755
--- a/client/shared/scripts/deployImage
+++ b/client/shared/scripts/deployImage
@@ -61,7 +61,8 @@ PROTOOPT="$6"
# Clear temporary file used as log track by httpdlog
# Limpia los ficheros temporales usados como log de seguimiento para httpdlog
-echo -n "" > $OGLOGSESSION; echo " " > $OGLOGCOMMAND
+echo " " > $OGLOGCOMMAND
+[ "$(ogGetCaller)" == "EjecutarScript" ] || echo -n "" > $OGLOGSESSION
# Registro de inicio de ejecución
echo "[1] $MSG_SCRIPTS_START $0 $*" | tee -a $OGLOGSESSION $OGLOGFILE
@@ -134,11 +135,13 @@ case "$REPO" in
esac
;;
*) # Error: repositorio desconocido.
- ogRaiseError $OG_ERR_FORMAT "$MSG_ERR_FORMAT, $REPO" | tee -a $OGLOGSESSION $OGLOGFILE
- exit $?
+ ogRaiseError $OG_ERR_FORMAT "$MSG_ERR_FORMAT, $REPO" 2>&1 | tee -a $OGLOGSESSION $OGLOGFILE
+ exit ${PIPESTATUS[0]}
;;
esac
+echo Borrar
+cp $OGLOGCOMMAND.tmp $OGLOGCOMMAND.update
TIME3=$SECONDS
case "$NEXTOPERATION" in
@@ -146,23 +149,27 @@ case "$NEXTOPERATION" in
echo "[55] $MSG_HELP_ogRestoreImage : restoreImage CACHE $IMGNAME $DISK $PART UNICAST" | tee -a $OGLOGSESSION $OGLOGFILE
restoreImage CACHE "$IMGNAME" "$DISK" "$PART"
RETVAL=${PIPESTATUS[0]}
- RESUMERESTOREIMAGE=$(grep "Total Time:" $OGLOGCOMMAND)
;;
UNICAST)
echo "[55] $MSG_HELP_ogRestoreImage : restoreImage REPO $IMGNAME $DISK $PART UNICAST" | tee -a $OGLOGSESSION $OGLOGFILE
restoreImage REPO "$IMGNAME" "$DISK" "$PART"
- RETVAL=$?
- RESUMERESTOREIMAGE=$(grep "Total Time:" $OGLOGCOMMAND)
+ RETVAL=${PIPESTATUS[0]}
;;
MULTICAST)
echo "[55] $MSG_HELP_ogRestoreImage : restoreImage REPO $IMGNAME $DISK $PART $PROTO $PROTOOPT" | tee -a $OGLOGSESSION $OGLOGFILE
- restoreImage REPO "$IMGNAME" "$DISK" "$PART" $PROTO $PROTOOPT
- RETVAL=$?
- RESUMERESTOREIMAGE=$(grep "Total Time:" $OGLOGCOMMAND)
+ restoreImage REPO "$IMGNAME" "$DISK" "$PART" $PROTO $PROTOOPT
+ RETVAL=${PIPESTATUS[0]}
;;
esac
-
+RESUMERESTOREIMAGE=$(grep -m 1 "Total Time:" $OGLOGCOMMAND)
echo " [ ] $RESUMERESTOREIMAGE " | tee -a $OGLOGSESSION $OGLOGFILE
+# Si la transferencia ha dado error me salgo.
+if [ $RETVAL -ne 0 ] ; then
+ ogRaiseError $OG_ERR_IMAGE "$REPO $IMGNAME" 2>&1 | tee -a $OGLOGSESSION $OGLOGFILE
+ # Muestro registro de fin de ejecución si no viene de Ejecutar Script
+ [ "$(ogGetCaller)" == "EjecutarScript" ] || echo "$MSG_INTERFACE_END $OG_ERR_IMAGE" | tee -a $OGLOGSESSION $OGLOGFILE
+ exit $OG_ERR_IMAGE
+fi
TIME3=$[SECONDS-TIME3]
echo " [ ] $MSG_SCRIPTS_TIME_PARTIAL : $[TIME3/60]m $[TIME3%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
@@ -178,7 +185,9 @@ TIME=$[SECONDS-TIME1]
echo "[100] $MSG_SCRIPTS_TIME_TOTAL $[TIME/60]m $[TIME%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
# Registro de fin de ejecución
-echo "$MSG_INTERFACE_END $RETVAL" | tee -a $OGLOGSESSION $OGLOGFILE
-
-exit $RETVAL
+# Si se ha llamado desde ejecutar script no lo muestro para no repetir.
+if [ "$(ogGetCaller)" != "EjecutarScript" ]
+ echo "$MSG_INTERFACE_END $RETVAL" | tee -a $OGLOGSESSION $OGLOGFILE
+ exit $RETVAL
+fi
diff --git a/client/shared/scripts/restoreImage b/client/shared/scripts/restoreImage
index d89db318..0de16a5c 100755
--- a/client/shared/scripts/restoreImage
+++ b/client/shared/scripts/restoreImage
@@ -1,12 +1,12 @@
#!/bin/bash
-# Scirpt de ejemplo para restaurar una imagen.
+# Script de ejemplo para restaurar una imagen.
# (puede usarse como base para el programa de restauración de imágenes usado por OpenGNSys Admin).
TIME1=$SECONDS
PROG="$(basename $0)"
if [ $# -lt 4 ]; then
- ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST opciones protocolo]"
- exit $?
+ ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST opciones protocolo]" 2>&1 | tee -a $OGLOGSESSION $OGLOGFILE
+ exit ${PIPESTATUS[0]}
fi
#Load engine configurator from engine.cfg file.
@@ -31,8 +31,12 @@ PROTO=${PROTO:-"UNICAST"}
PROTOOPT="$6"
IMGTYPE="${IMGTYPE:-"img"}"
# Comprobar que existe la imagen del origen.
-IMGFILE=$(ogGetPath "$REPO" "$IMGNAME.$IMGTYPE") || ogRaiseError $OG_ERR_NOTFOUND "$REPO, ${IMGNAME%/*}" || exit $?
-IMGDIR=$(ogGetParentPath "$REPO" "$IMGNAME") || ogRaiseError $OG_ERR_NOTFOUND "$REPO, ${IMGNAME%/*}" || exit $?
+IMGFILE=$(ogGetPath "$REPO" "$IMGNAME.$IMGTYPE")
+IMGDIR=$(ogGetParentPath "$REPO" "$IMGNAME")
+if [ "$IMGFILE" == "" -o "$IMGDIR" == "" ]; then
+ ogRaiseError $OG_ERR_NOTFOUND "$REPO, ${IMGNAME%/*}" 2>&1 | tee -a $OGLOGSESSION $OGLOGFILE
+ exit ${PIPESTATUS[0]}
+fi
# Procesar protocolos de transferencia.
case "$PROTO" in
@@ -53,7 +57,8 @@ case "$PROTO" in
RETVAL=${PIPESTATUS[0]}
;;
*) # Protocolo desconocido.
- ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST opciones ]"
+ ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST opciones ]" 2>&1 | tee -a $OGLOGSESSION $OGLOGFILE
+
exit $?
esac
diff --git a/client/shared/scripts/updateCache b/client/shared/scripts/updateCache
index 39d2c6b8..028fbe46 100755
--- a/client/shared/scripts/updateCache
+++ b/client/shared/scripts/updateCache
@@ -31,13 +31,18 @@
PROG="$(basename $0)"
if [ $# -lt 3 ]; then
- ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG str_REPO _str_Relative_Path_OGIMG_with_/ PROTOCOLO OPCIONES_PROTOCOLO OPCIONES_UPDATECACHE"
- exit $?
+ ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG str_REPO _str_Relative_Path_OGIMG_with_/ PROTOCOLO OPCIONES_PROTOCOLO OPCIONES_UPDATECACHE" 2>&1 | tee -a $OGLOGSESSION $OGLOGFILE
+ exit ${PIPESTATUS[0]}
fi
#Carga del configurador del engine
[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
+# Clear temporary file used as log track by httpdlog
+# Limpia los ficheros temporales usados como log de seguimiento para httpdlog
+echo " " > $OGLOGCOMMAND
+[ "$(ogGetCaller)" == "deployImage" ] || echo -n "" > $OGLOGSESSION;
+
REPOSITORIO="${1^^}"
PROTOCOLO="${3^^}"
OPTPROTOCOLO="$4"
@@ -46,12 +51,16 @@ echo $REPOSITORIO $REPOIP $PROTOCOLO $OPTPROTOCOLO
# Si el repositorio local CACHE no existe error 15.
if ! $(ogFindCache >/dev/null); then
- ogRaiseError $OG_ERR_NOTCACHE "CACHE" | tee -a $OGLOGSESSION $OGLOGFILE
+ ogRaiseError $OG_ERR_NOTCACHE "CACHE" 2>&1 | tee -a $OGLOGSESSION $OGLOGFILE
exit ${PIPESTATUS[0]}
fi
# comprobar si la imagen existe (.img, .img.diff o directorio)
-REPOFILE=$(ogGetPath "REPO" "/$2") || exit $(ogRaiseError $OG_ERR_NOTFOUND "REPO /$2")
+REPOFILE=$(ogGetPath "REPO" "/$2")
+if [ "$REPOFILE" == "" ]; then
+ ogRaiseError $OG_ERR_NOTFOUND "REPO /$2" 2>&1 | tee -a $OGLOGSESSION $OGLOGFILE
+ exit ${PIPESTATUS[0]}
+fi
echo "$MSG_SCRIPTS_UPDATECACHE_DOUPDATE " | tee -a $OGLOGSESSION $OGLOGFILE
# Distingo si es monolitica o sincronizable
@@ -67,7 +76,10 @@ if [ $? == 0 ]; then
RETVAL=0
else
# Si la imagen es monolitica y ha elegido protocolo = RSYNC salimos con error.
- [ $PROTOCOLO == "RSYNC" ] && exit $(ogRaiseError $OG_ERR_DONTSYNC_IMAGE "REPO $2")
+ if [ $PROTOCOLO == "RSYNC" ]; then
+ ogRaiseError $OG_ERR_DONTSYNC_IMAGE "REPO $2" 2>&1| tee -a $OGLOGSESSION $OGLOGFILE
+ exit ${PIPESTATUS[0]}
+ fi
IMGSYNC=FALSE
#TODO: ogUpdateCacheIsNecesary debe borrar la imagen que tenga igual nombre pero distinto sum-
ogUpdateCacheIsNecesary $1 $2
@@ -113,8 +125,8 @@ fi
if [ "$SIZEREQUIRED" -ge "$CACHESIZE" ]
then
echo "$MSG_WARNING: $MSG_ERR_CACHESIZE: $2 = $SIZEREQUIRED > CACHE = $CACHESIZE" | tee -a $OGLOGSESSION $OGLOGFILE
- ogRaiseError $OG_ERR_CACHESIZE "CACHE" | tee -a $OGLOGSESSION $OGLOGFILE
- exit ${PIPESTATUS[0]}
+ ogRaiseError $OG_ERR_CACHESIZE "CACHE" 2>&1 | tee -a $OGLOGSESSION $OGLOGFILE
+ exit ${PIPESTATUS[0]}
fi
echo "$MSG_SCRIPTS_UPDATECACHE_IFNOTCACHEDO" | tee -a $OGLOGSESSION $OGLOGFILE
@@ -140,8 +152,8 @@ then
;;
*)
echo "$MSG_WARNING: $MSG_ERR_CACHESIZE: $2 = $FILESIZE > CACHE = $CACHESIZEFREE" | tee -a $OGLOGSESSION $OGLOGFILE
- ogRaiseError $OG_ERR_CACHESIZE "CACHE"
- exit $?
+ ogRaiseError $OG_ERR_CACHESIZE "CACHE" 2>&1 | tee -a $OGLOGSESSION $OGLOGFILE
+ exit ${PIPESTATUS[0]}
;;
esac
fi
@@ -179,7 +191,7 @@ case "$PROTOCOLO" in
sleep $P2PWAIT
echo " [ ] $MSG_SCRIPTS_TASK_START: ogTorrentStart CACHE $2.torrent $4" | tee -a $OGLOGSESSION $OGLOGFILE
ogTorrentStart CACHE "$2.torrent" $4 2>&1 | tee -a $OGLOGCOMMAND
- RESUMEUPDATECACHE=$(cat $OGLOGCOMMAND | grep -B1 "Download")
+ RESUMEUPDATECACHE=$(grep -m 1 -B1 "Download" $OGLOGCOMMAND)
;;
MULTICAST)
PORT=$(echo $OPTPROTOCOLO | cut -f1 -d":")
@@ -211,11 +223,13 @@ case "$PROTOCOLO" in
#cat $OGLOGCOMMAND.tmp | grep -B1 "Transfer complete"
sleep 5
#cat $OGLOGCOMMAND.tmp | grep -B1 "Transfer complete"
- RESUMEUPDATECACHE=$(cat $OGLOGCOMMAND.tmp | grep -B1 "Transfer complete")
+ RESUMEUPDATECACHE=$(grep -m 1 -B1 "Transfer complete" $OGLOGCOMMAND.tmp)
;;
UNICAST)
echo "unicast" | tee -a $OGLOGSESSION $OGLOGFILE
ogCopyFile $REPOSITORIO "$2" "$IMGDIR" 2>&1 | tee -a $OGLOGCOMMAND
+ sleep 5
+ RESUMEUPDATECACHE=$(grep -m 1 "100%" $OGLOGCOMMAND.tmp)
;;
RSYNC)
# Opciones de rsync
@@ -264,6 +278,7 @@ case "$PROTOCOLO" in
esac
TIME1=$[SECONDS-TIME1]
+
echo " [ ] $RESUMEUPDATECACHE " | tee -a $OGLOGSESSION $OGLOGFILE
echo " [ ] $MSG_SCRIPTS_TIME_PARTIAL updateCache $[TIME1/60]m $[TIME1%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
echo " [ ] $MSG_SCRIPTS_TASK_START $MSG_HELP_ogCalculateChecksum " | tee -a $OGLOGSESSION $OGLOGFILE
@@ -277,9 +292,10 @@ else
RETVAL=$?
fi
-TIME2=$[SECONDS-TIME2]
-echo " [ ] $MSG_SCRIPTS_TIME_PARTIAL $MSG_HELP_ogCalculateChecksum $[TIME2/60]m $[TIME2%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
-
+if [ "$(ogGetCaller)" != "deployImage" ]; then
+ TIME2=$[SECONDS-TIME2]
+ echo " [ ] $MSG_SCRIPTS_TIME_PARTIAL $MSG_HELP_ogCalculateChecksum $[TIME2/60]m $[TIME2%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
+fi
# si RETVAL=0 => actualizamos si RETVAL=1 no actaulizamos-exit 0 || si RETVAL>2 exit 1
[ "$RETVAL" == "0" ] && exit 1
[ "$RETVAL" == "1" ] && exit 0