[b518302] | 1 | #!/bin/bash |
---|
[d6bffcc] | 2 | # deleteimage [ -b | -r ] [ dir_ogunit ] 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). |
---|
[d6bffcc] | 7 | #@param str_dir_ogunit Nombre del subdirectorio de la unidad organizativa (opcional). |
---|
[b518302] | 8 | #@param str_image Nombre canónico de la imagen, sin extensión. |
---|
[d6bffcc] | 9 | #@exception 1 Error de formato |
---|
| 10 | #@exception 2 Solo ejecutable por root |
---|
| 11 | #@exception 3 No existe subdirectorio de la unidad organizativa |
---|
[bbad384] | 12 | #@version 1.0 - Versión inicial. |
---|
| 13 | #@date 2012-10-14 |
---|
[b518302] | 14 | #@author Ramón Gómez, ETSII Univ. Sevilla |
---|
[99e251e] | 15 | #@version 1.0.5 - Eliminar imagen incremental. |
---|
[bbad384] | 16 | #@date 2013-07-17 |
---|
| 17 | #@author Alberto García, Univ. Málaga |
---|
[841e5ef] | 18 | #@version 1.0.6 - Detección automática del tipo de imagen. |
---|
[99e251e] | 19 | #@date 2014-10-29 |
---|
| 20 | #@author Ramón Gómez, ETSII Univ. Sevilla |
---|
[d6bffcc] | 21 | #@version 1.1 - Separación subdirectorios unidades organizativas. |
---|
| 22 | #@date 2016-01-03 |
---|
| 23 | #@author Irina Gómez, ETSII Univ. Sevilla |
---|
[b518302] | 24 | |
---|
| 25 | |
---|
| 26 | PROG=$(basename $0) |
---|
| 27 | OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} |
---|
| 28 | OGIMG=$OPENGNSYS/images |
---|
| 29 | IMGEXT="img" |
---|
| 30 | BAKEXT="ant" |
---|
[5b521cb] | 31 | DIFFEXT="diff" |
---|
| 32 | |
---|
[b518302] | 33 | # Si se solicita, mostrar ayuda. |
---|
| 34 | if [ "$*" == "help" ]; then |
---|
| 35 | cat << EOT |
---|
| 36 | $PROG: Borra los ficheros de una imagen del repositorio. |
---|
[d6bffcc] | 37 | Formato: $PROG [ -b | -r ] [ str_dir_ogunit ] str_image |
---|
[b518302] | 38 | -b Elimina también la copia de seguridad de la imagen. |
---|
| 39 | -r Recupera la copia de seguridad de la imagen. |
---|
[d6bffcc] | 40 | dir_ogunit subdirectorio unidad organizativa |
---|
| 41 | |
---|
[b518302] | 42 | Ejemplo: $PROG imagen1 |
---|
[d6bffcc] | 43 | $PROG -r dir_ogunit2 imagen2 |
---|
[b518302] | 44 | EOT |
---|
| 45 | exit 0 |
---|
| 46 | fi |
---|
| 47 | # Procesar parámetros |
---|
[99e251e] | 48 | while getopts br OPTION; do |
---|
[b518302] | 49 | case $OPTION in |
---|
| 50 | b) DELETEBACKUP=1 ;; |
---|
| 51 | r) RECOVERBACKUP=1 ;; |
---|
| 52 | *) ERR=1 ;; |
---|
| 53 | esac |
---|
| 54 | shift $((OPTIND-1)) |
---|
| 55 | done |
---|
[99e251e] | 56 | [ -n "$DELETEBACKUP" ] && [ -n "$RECOVERBACKUP" ] && ERR=1 |
---|
[d6bffcc] | 57 | if [ $# -lt 1 -o -n "$ERR" ]; then |
---|
| 58 | echo "$PROG Error: Formato: $PROG [ -b | -r ] [ str_dir_ogunit ] str_image" |
---|
[b518302] | 59 | exit 1 |
---|
| 60 | fi |
---|
| 61 | |
---|
[d6bffcc] | 62 | if [ "$USER" != "root" ]; then |
---|
| 63 | echo "$PROG: Error: solo ejecutable por root" >&2 |
---|
| 64 | exit 2 |
---|
| 65 | fi |
---|
| 66 | |
---|
| 67 | if [ "$2" ]; then |
---|
| 68 | if [ -d "$OGIMG/$1" ]; then |
---|
| 69 | OGIMG="$OGIMG/$1" |
---|
| 70 | else |
---|
| 71 | echo "$PROG Error: No existe el subdirectorio de la unidad organizativa $OGIMG/$1" |
---|
| 72 | exit 3 |
---|
| 73 | fi |
---|
| 74 | shift |
---|
| 75 | fi |
---|
| 76 | |
---|
[99e251e] | 77 | # Eliminar ficheros de imagen monolítica o sincronizada básica. |
---|
| 78 | IMGPATH="$OGIMG/$1.$IMGEXT" |
---|
| 79 | if [ -f $IMGPATH ]; then |
---|
[d6bffcc] | 80 | echo "Borrando fichero $IMGPATH" |
---|
[1a2fa9d8] | 81 | rm -f $IMGPATH && rm -f $IMGPATH.{sum,full.sum,torrent} |
---|
[99e251e] | 82 | else |
---|
| 83 | # Eliminar ficheros de imagen sincronizada diferencial. |
---|
| 84 | IMGPATH="$OGIMG/$1.$IMGEXT.$DIFFEXT" |
---|
| 85 | if [ -f $IMGPATH ]; then |
---|
[d6bffcc] | 86 | echo "Borrando fichero $IMGPATH" |
---|
[1a2fa9d8] | 87 | rm -f $IMGPATH && rm -f $IMGPATH.{sum,full.sum,torrent} |
---|
[99e251e] | 88 | else |
---|
| 89 | # Eliminar directorio de imagen sincronizada. |
---|
| 90 | IMGPATH="$OGIMG/$1" |
---|
| 91 | if [ -d $IMGPATH ]; then |
---|
[d6bffcc] | 92 | echo "Borrando directorio $IMGPATH" |
---|
[99e251e] | 93 | rm -fr $IMGPATH |
---|
| 94 | fi |
---|
| 95 | fi |
---|
| 96 | fi |
---|
| 97 | |
---|
[b518302] | 98 | # Recuperar copia de seguridad de la imagen. |
---|
| 99 | if [ -n "$RECOVERBACKUP" ]; then |
---|
[99e251e] | 100 | [ -e $IMGPATH.$BAKEXT ] && echo "Recuperando copia $IMGPATH.$BAKEXT" |
---|
| 101 | mv -f $IMGPATH.$BAKEXT $IMGPATH && \ |
---|
| 102 | (mv -f $IMGPATH.sum.$BAKEXT $IMGPATH.sum 2>/dev/null |
---|
[1a2fa9d8] | 103 | mv -f $IMGPATH.full.sum.$BAKEXT $IMGPATH.full.sum 2>/dev/null |
---|
[99e251e] | 104 | mv -f $IMGPATH.torrent.$BAKEXT $IMGPATH.torrent 2>/dev/null) |
---|
[b518302] | 105 | fi |
---|
| 106 | |
---|
| 107 | # Borrar copia de seguridad de la imagen. |
---|
| 108 | if [ -n "$DELETEBACKUP" ]; then |
---|
[d6bffcc] | 109 | [ -e $IMGPATH.$BAKEXT ] && echo "Eliminando copia $IMGPATH.$BAKEXT" |
---|
[1a2fa9d8] | 110 | rm -f $IMGPATH.$BAKEXT && rm -f $IMGPATH.{sum,full.sum,torrent}.$BAKEXT |
---|
[b518302] | 111 | fi |
---|
| 112 | |
---|