source: repoman/bin/deleteimage @ a6d6d6f

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