source: repoman/bin/deleteimage @ 044d306

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 044d306 was 25a56b8, checked in by irina <irinagomez@…>, 9 years ago

#678 Permite borrar imágenes en directorios de unidades organizativas desde la consola o línea de comando

git-svn-id: https://opengnsys.es/svn/branches/version1.1@4811 a21b9725-9963-47de-94b9-378ad31fedc9

  • 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
19
20PROG=$(basename $0)
21OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"}
22OGIMG=$OPENGNSYS/images
23IMGEXT="img"
24BAKEXT="ant"
25DIFFEXT="diff"
26
27# Si se solicita, mostrar ayuda.
28if [ "$*" == "help" ]; then
29    cat << EOT
30$PROG: Borra los ficheros de una imagen del repositorio.
31Formato: $PROG [ -b | -r ] [ str_image | str_dir/str_image ]
32         -b  Elimina también la copia de seguridad de la imagen.
33         -r  Recupera la copia de seguridad de la imagen.
34Ejemplo: $PROG imagen1
35         $PROG -r dir2/imagen2
36EOT
37    exit 0
38fi
39# Procesar parámetros
40while getopts br OPTION; do
41    case $OPTION in
42        b) DELETEBACKUP=1 ;;
43        r) RECOVERBACKUP=1 ;;
44        *) ERR=1 ;;
45    esac
46    shift $((OPTIND-1))
47done
48[ -n "$DELETEBACKUP" ] && [ -n "$RECOVERBACKUP" ] && ERR=1
49if [ $# != 1 -o -n "$ERR" ]; then
50    echo "$PROG Error: Formato: $PROG [ -b | -r ] [ str_image | str_dir/str_image ]"
51    exit 1
52fi
53
54# Eliminar ficheros de imagen monolítica o sincronizada básica.
55IMGPATH="$OGIMG/$1.$IMGEXT"
56if [ -f $IMGPATH ]; then
57    echo "Borrando fichero $IMGPATH"
58    rm -f $IMGPATH && rm -f $IMGPATH.{sum,full.sum,torrent}
59else
60    # Eliminar ficheros de imagen sincronizada diferencial.
61    IMGPATH="$OGIMG/$1.$IMGEXT.$DIFFEXT"
62    if [ -f $IMGPATH ]; then
63        echo "Borrando fichero $IMGPATH"
64        rm -f $IMGPATH && rm -f $IMGPATH.{sum,full.sum,torrent}
65    else
66        # Eliminar directorio de imagen sincronizada.
67        IMGPATH="$OGIMG/$1"
68        if [ -d $IMGPATH ]; then
69            echo "Borrando directorio $IMGPATH"
70            rm -fr $IMGPATH
71        fi
72    fi
73fi
74
75# Recuperar copia de seguridad de la imagen.
76if [ -n "$RECOVERBACKUP" ]; then
77    [ -e $IMGPATH.$BAKEXT ] && echo "Recuperando copia $IMGPATH.$BAKEXT"
78    mv -f $IMGPATH.$BAKEXT $IMGPATH && \
79            (mv -f $IMGPATH.sum.$BAKEXT $IMGPATH.sum 2>/dev/null
80             mv -f $IMGPATH.full.sum.$BAKEXT $IMGPATH.full.sum 2>/dev/null
81             mv -f $IMGPATH.torrent.$BAKEXT $IMGPATH.torrent 2>/dev/null)
82fi
83
84# Borrar copia de seguridad de la imagen.
85if [ -n "$DELETEBACKUP" ]; then
86    [ -e $IMGPATH.$BAKEXT ] && echo "Eliminando copia $IMGPATH.$BAKEXT"
87    rm -f $IMGPATH.$BAKEXT && rm -f $IMGPATH.{sum,full.sum,torrent}.$BAKEXT
88fi
89
Note: See TracBrowser for help on using the repository browser.