source: repoman/bin/deleteimage @ 78a0db7

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 78a0db7 was d6bffcc, checked in by irina <irinagomez@…>, 9 years ago

#678 unidades organizativas separadas: los script deleteimagen y torrent-creator permiten imágenes dentro de subdirectorios de /opt/opengnsys/images

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

  • Property mode set to 100755
File size: 3.6 KB
RevLine 
[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
26PROG=$(basename $0)
27OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"}
28OGIMG=$OPENGNSYS/images
29IMGEXT="img"
30BAKEXT="ant"
[5b521cb]31DIFFEXT="diff"
32
[b518302]33# Si se solicita, mostrar ayuda.
34if [ "$*" == "help" ]; then
35    cat << EOT
36$PROG: Borra los ficheros de una imagen del repositorio.
[d6bffcc]37Formato: $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]42Ejemplo: $PROG imagen1
[d6bffcc]43         $PROG -r dir_ogunit2 imagen2
[b518302]44EOT
45    exit 0
46fi
47# Procesar parámetros
[99e251e]48while 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))
55done
[99e251e]56[ -n "$DELETEBACKUP" ] && [ -n "$RECOVERBACKUP" ] && ERR=1
[d6bffcc]57if [ $# -lt 1 -o -n "$ERR" ]; then
58    echo "$PROG Error: Formato: $PROG [ -b | -r ] [ str_dir_ogunit ] str_image"
[b518302]59    exit 1
60fi
61
[d6bffcc]62if [ "$USER" != "root" ]; then
63    echo "$PROG: Error: solo ejecutable por root" >&2
64    exit 2
65fi
66
67if [ "$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
75fi   
76
[99e251e]77# Eliminar ficheros de imagen monolítica o sincronizada básica.
78IMGPATH="$OGIMG/$1.$IMGEXT"
79if [ -f $IMGPATH ]; then
[d6bffcc]80    echo "Borrando fichero $IMGPATH"
[1a2fa9d8]81    rm -f $IMGPATH && rm -f $IMGPATH.{sum,full.sum,torrent}
[99e251e]82else
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
96fi
97
[b518302]98# Recuperar copia de seguridad de la imagen.
99if [ -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]105fi
106
107# Borrar copia de seguridad de la imagen.
108if [ -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]111fi
112
Note: See TracBrowser for help on using the repository browser.