source: repoman/bin/deleteimage @ a0dd47a

Last change on this file since a0dd47a was 01f4ee0, checked in by Ramón M. Gómez <ramongomez@…>, 6 years ago

#882: Remove directory-based image.

  • Property mode set to 100755
File size: 2.8 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
[b518302]30# Si se solicita, mostrar ayuda.
31if [ "$*" == "help" ]; then
32    cat << EOT
33$PROG: Borra los ficheros de una imagen del repositorio.
[25a56b8]34Formato: $PROG [ -b | -r ] [ str_image | str_dir/str_image ]
[b518302]35         -b  Elimina también la copia de seguridad de la imagen.
36         -r  Recupera la copia de seguridad de la imagen.
37Ejemplo: $PROG imagen1
[25a56b8]38         $PROG -r dir2/imagen2
[b518302]39EOT
40    exit 0
41fi
42# Procesar parámetros
[99e251e]43while getopts br OPTION; do
[b518302]44    case $OPTION in
45        b) DELETEBACKUP=1 ;;
46        r) RECOVERBACKUP=1 ;;
47        *) ERR=1 ;;
48    esac
49    shift $((OPTIND-1))
50done
[99e251e]51[ -n "$DELETEBACKUP" ] && [ -n "$RECOVERBACKUP" ] && ERR=1
[25a56b8]52if [ $# != 1 -o -n "$ERR" ]; then
53    echo "$PROG Error: Formato: $PROG [ -b | -r ] [ str_image | str_dir/str_image ]"
[b518302]54    exit 1
55fi
56
[d0c9a98]57# Eliminar ficheros de imagen monolítica o sincronizada.
58for IMG in "$OGIMG/$1.$IMGEXT" "$OGIMG/$1.$IMGEXT.$DIFFEXT" "$OGIMG/$1"; do
59    # Borro la imagen si existe
60    if [ -r $IMG ] ; then
61        IMGPATH=$IMG
62        echo "Borrando imagen $IMGPATH"
[01f4ee0]63        rm -fr $IMGPATH{,.sum,.full.sum,.torrent}
[d0c9a98]64        break
[99e251e]65    fi
[d0c9a98]66    # Compruebo si existe copia de seguridad
67    [ -r $IMG.$BAKEXT ] && OLDPATH=$IMG
68done
[99e251e]69
[d0c9a98]70[ "_${IMGPATH}_" == "__" ] && IMGPATH=$OLDPATH
[b518302]71# Recuperar copia de seguridad de la imagen.
72if [ -n "$RECOVERBACKUP" ]; then
[99e251e]73    [ -e $IMGPATH.$BAKEXT ] && echo "Recuperando copia $IMGPATH.$BAKEXT"
74    mv -f $IMGPATH.$BAKEXT $IMGPATH && \
75            (mv -f $IMGPATH.sum.$BAKEXT $IMGPATH.sum 2>/dev/null
[1a2fa9d8]76             mv -f $IMGPATH.full.sum.$BAKEXT $IMGPATH.full.sum 2>/dev/null
[99e251e]77             mv -f $IMGPATH.torrent.$BAKEXT $IMGPATH.torrent 2>/dev/null)
[b518302]78fi
79
80# Borrar copia de seguridad de la imagen.
81if [ -n "$DELETEBACKUP" ]; then
[d6bffcc]82    [ -e $IMGPATH.$BAKEXT ] && echo "Eliminando copia $IMGPATH.$BAKEXT"
[1a2fa9d8]83    rm -f $IMGPATH.$BAKEXT && rm -f $IMGPATH.{sum,full.sum,torrent}.$BAKEXT
[b518302]84fi
Note: See TracBrowser for help on using the repository browser.