source: repoman/bin/deleteimage @ 96ee53a

lgromero-new-oglive
Last change on this file since 96ee53a was c28eefa, checked in by Natalia Serrano <natalia.serrano@…>, 20 months ago

Log to syslog in a number of shell scripts

  • Property mode set to 100755
File size: 2.9 KB
RevLine 
[b518302]1#!/bin/bash
[25a56b8]2#         deleteimage [ -b | -r ] [ str_image | str_dir/str_image ]
[b518302]3#@file    deleteimage
4#@brief   Borra del repositorio los ficheros de una imagen.
5#@param   -b           Elimina también la copia de seguridad de la imagen (opcional).
6#@param   -r           Recupera la copia de seguridad de la imagen (opcional).
[25a56b8]7#@param   str_image    Nombre canónico de la imagen, sin extensión. Permite directorio.
[d6bffcc]8#@exception 1 Error de formato
[bbad384]9#@version 1.0 - Versión inicial.
10#@date    2012-10-14
[b518302]11#@author  Ramón Gómez, ETSII Univ. Sevilla
[99e251e]12#@version 1.0.5 - Eliminar imagen incremental.
[bbad384]13#@date    2013-07-17
14#@author  Alberto García, Univ. Málaga
[841e5ef]15#@version 1.0.6 - Detección automática del tipo de imagen.
[99e251e]16#@date    2014-10-29
17#@author  Ramón Gómez, ETSII Univ. Sevilla
[01f4ee0]18#@version 1.1.0 - Aunque no exista imagen permite recuperar la copia.
[d0c9a98]19#@date    2016-10-14
20#@author  Irina Gómez, ETSII Univ. Sevilla
21#*/ ##
[b518302]22
23PROG=$(basename $0)
24OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"}
25OGIMG=$OPENGNSYS/images
26IMGEXT="img"
27BAKEXT="ant"
[5b521cb]28DIFFEXT="diff"
29
[c28eefa]30source $OPENGNSYS/lib/ogfunctions.sh
31
[b518302]32# Si se solicita, mostrar ayuda.
33if [ "$*" == "help" ]; then
34    cat << EOT
35$PROG: Borra los ficheros de una imagen del repositorio.
[25a56b8]36Formato: $PROG [ -b | -r ] [ str_image | str_dir/str_image ]
[b518302]37         -b  Elimina también la copia de seguridad de la imagen.
38         -r  Recupera la copia de seguridad de la imagen.
39Ejemplo: $PROG imagen1
[25a56b8]40         $PROG -r dir2/imagen2
[b518302]41EOT
42    exit 0
43fi
44# Procesar parámetros
[99e251e]45while getopts br OPTION; do
[b518302]46    case $OPTION in
47        b) DELETEBACKUP=1 ;;
48        r) RECOVERBACKUP=1 ;;
49        *) ERR=1 ;;
50    esac
51    shift $((OPTIND-1))
52done
[99e251e]53[ -n "$DELETEBACKUP" ] && [ -n "$RECOVERBACKUP" ] && ERR=1
[25a56b8]54if [ $# != 1 -o -n "$ERR" ]; then
55    echo "$PROG Error: Formato: $PROG [ -b | -r ] [ str_image | str_dir/str_image ]"
[b518302]56    exit 1
57fi
58
[d0c9a98]59# Eliminar ficheros de imagen monolítica o sincronizada.
60for IMG in "$OGIMG/$1.$IMGEXT" "$OGIMG/$1.$IMGEXT.$DIFFEXT" "$OGIMG/$1"; do
61    # Borro la imagen si existe
62    if [ -r $IMG ] ; then
63        IMGPATH=$IMG
[c28eefa]64        echolog "Borrando imagen $IMGPATH"
[01f4ee0]65        rm -fr $IMGPATH{,.sum,.full.sum,.torrent}
[d0c9a98]66        break
[99e251e]67    fi
[d0c9a98]68    # Compruebo si existe copia de seguridad
69    [ -r $IMG.$BAKEXT ] && OLDPATH=$IMG
70done
[99e251e]71
[d0c9a98]72[ "_${IMGPATH}_" == "__" ] && IMGPATH=$OLDPATH
[b518302]73# Recuperar copia de seguridad de la imagen.
74if [ -n "$RECOVERBACKUP" ]; then
[c28eefa]75    [ -e $IMGPATH.$BAKEXT ] && echolog "Recuperando copia $IMGPATH.$BAKEXT"
[99e251e]76    mv -f $IMGPATH.$BAKEXT $IMGPATH && \
77            (mv -f $IMGPATH.sum.$BAKEXT $IMGPATH.sum 2>/dev/null
[1a2fa9d8]78             mv -f $IMGPATH.full.sum.$BAKEXT $IMGPATH.full.sum 2>/dev/null
[99e251e]79             mv -f $IMGPATH.torrent.$BAKEXT $IMGPATH.torrent 2>/dev/null)
[b518302]80fi
81
82# Borrar copia de seguridad de la imagen.
83if [ -n "$DELETEBACKUP" ]; then
[c28eefa]84    [ -e $IMGPATH.$BAKEXT ] && echolog "Eliminando copia $IMGPATH.$BAKEXT"
[1a2fa9d8]85    rm -f $IMGPATH.$BAKEXT && rm -f $IMGPATH.{sum,full.sum,torrent}.$BAKEXT
[b518302]86fi
Note: See TracBrowser for help on using the repository browser.