[8bf033d] | 1 | #!/bin/bash |
---|
[0d2f40e] | 2 | # Eliminar las imagenees del repositiro seg�raca de la consola web .img |
---|
[2cb912bd] | 3 | #Version 0.3 Ejecuci�n desde cron cada minuto. |
---|
[8bf033d] | 4 | #echo "* * * * * root /opt/opengnsys/bin/image-delete" > /etc/cron.d/imagedelete |
---|
| 5 | |
---|
| 6 | # Comprobar si el proceso ya est� en ejecuci�n.on. |
---|
| 7 | PROG=$(basename $0) |
---|
| 8 | [ "$(pgrep "$PROG")" != "$$" ] && exit |
---|
| 9 | |
---|
| 10 | # Variables. |
---|
| 11 | OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} |
---|
| 12 | PATH=$PATH:$OPENGNSYS/bin |
---|
| 13 | OGIMG="$OPENGNSYS/images" |
---|
| 14 | REPOCFG="$OPENGNSYS/etc/ogAdmRepo.cfg" |
---|
| 15 | LOGFILE="$OPENGNSYS/log/$PROG.log" |
---|
| 16 | |
---|
| 17 | # Error si no est� bien configurado el repositorio de im�genes.nes. |
---|
| 18 | [ -d $OGIMG -a -f $REPOCFG ] || exit 1 |
---|
| 19 | |
---|
| 20 | # Procesar ficheros de im�genes.s. |
---|
| 21 | trap 'echo "`date` : Proceso interrumpido" >> $LOGFILE; exit ' 1 2 3 6 9 15 |
---|
| 22 | |
---|
| 23 | #TODO en LOCAL: si existe algun fichero *.delete lo movemos al repositorio |
---|
| 24 | ls /opt/opengnsys/www/tmp/*.delete &>/dev/null || exit |
---|
| 25 | #[ -f /opt/opengnsys/www/tmp/*.delete ] && |
---|
| 26 | mv /opt/opengnsys/www/tmp/*.* /opt/opengnsys/images/ |
---|
| 27 | |
---|
| 28 | #TODO: iniciar blucle siempre y cuando haya algun delete |
---|
| 29 | ls /opt/opengnsys/images/*.delete &>/dev/null || exit |
---|
| 30 | |
---|
| 31 | for IMG in `ls /opt/opengnsys/images/*.delete`; do |
---|
[4a51c8ba] | 32 | ## Obtenemos el nombre de la imagen |
---|
[25a56b8] | 33 | # DELETEIMAGE=$(echo $IMG | awk -F"." '{print $1}' | awk -F"/opt/opengnsys/images/" '{print $2}') |
---|
| 34 | DELETEIMAGE=$(echo ${IMG%%.*} | awk -F"/opt/opengnsys/images/" '{print $2}') |
---|
[4a51c8ba] | 35 | |
---|
[8bf033d] | 36 | # Borramos marca .delete para que el proximo cron no trabaje sobre este conjunto. |
---|
| 37 | [ -f $IMG ] && rm $IMG |
---|
[4a51c8ba] | 38 | |
---|
[25a56b8] | 39 | ## Comprobamos si es una imagen de backup |
---|
[4a51c8ba] | 40 | DELETEant=$(echo $IMG | awk -F"." '{print $3}') ## .ant |
---|
| 41 | |
---|
[25a56b8] | 42 | ## Si la imagen es un backup se añade la extensión ant |
---|
| 43 | if [[ $DELETEant == "ant" ]]; then |
---|
| 44 | DELETEIMAGE=$DELETEIMAGE".ant" |
---|
[4a51c8ba] | 45 | fi |
---|
[25a56b8] | 46 | ## si directorio:imagen cambiamos : por / |
---|
| 47 | DELETEIMAGE=$(echo $DELETEIMAGE|tr : /) |
---|
| 48 | |
---|
| 49 | ## se llama al escript de borrado de imagen. |
---|
| 50 | /opt/opengnsys/bin/deleteimage $DELETEIMAGE |
---|
| 51 | |
---|
| 52 | done |
---|