source: repoman/bin/deleteimage

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

Log to syslog in a number of shell scripts

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