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
Line 
1#!/bin/bash
2#         deleteimage [ -b | -r ] [ dir_ogunit ] 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_dir_ogunit  Nombre del subdirectorio de la unidad organizativa (opcional).
8#@param   str_image    Nombre canónico de la imagen, sin extensión.
9#@exception 1 Error de formato
10#@exception 2 Solo ejecutable por root
11#@exception 3 No existe subdirectorio de la unidad organizativa
12#@version 1.0 - Versión inicial.
13#@date    2012-10-14
14#@author  Ramón Gómez, ETSII Univ. Sevilla
15#@version 1.0.5 - Eliminar imagen incremental.
16#@date    2013-07-17
17#@author  Alberto García, Univ. Málaga
18#@version 1.0.6 - Detección automática del tipo de imagen.
19#@date    2014-10-29
20#@author  Ramón Gómez, ETSII Univ. Sevilla
21#@version 1.1 - Separación subdirectorios unidades organizativas.
22#@date    2016-01-03
23#@author  Irina Gómez, ETSII Univ. Sevilla
24
25
26PROG=$(basename $0)
27OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"}
28OGIMG=$OPENGNSYS/images
29IMGEXT="img"
30BAKEXT="ant"
31DIFFEXT="diff"
32
33# Si se solicita, mostrar ayuda.
34if [ "$*" == "help" ]; then
35    cat << EOT
36$PROG: Borra los ficheros de una imagen del repositorio.
37Formato: $PROG [ -b | -r ] [ str_dir_ogunit ] str_image
38         -b  Elimina también la copia de seguridad de la imagen.
39         -r  Recupera la copia de seguridad de la imagen.
40         dir_ogunit subdirectorio unidad organizativa
41
42Ejemplo: $PROG imagen1
43         $PROG -r dir_ogunit2 imagen2
44EOT
45    exit 0
46fi
47# Procesar parámetros
48while getopts br OPTION; do
49    case $OPTION in
50        b) DELETEBACKUP=1 ;;
51        r) RECOVERBACKUP=1 ;;
52        *) ERR=1 ;;
53    esac
54    shift $((OPTIND-1))
55done
56[ -n "$DELETEBACKUP" ] && [ -n "$RECOVERBACKUP" ] && ERR=1
57if [ $# -lt 1 -o -n "$ERR" ]; then
58    echo "$PROG Error: Formato: $PROG [ -b | -r ] [ str_dir_ogunit ] str_image"
59    exit 1
60fi
61
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
77# Eliminar ficheros de imagen monolítica o sincronizada básica.
78IMGPATH="$OGIMG/$1.$IMGEXT"
79if [ -f $IMGPATH ]; then
80    echo "Borrando fichero $IMGPATH"
81    rm -f $IMGPATH && rm -f $IMGPATH.{sum,full.sum,torrent}
82else
83    # Eliminar ficheros de imagen sincronizada diferencial.
84    IMGPATH="$OGIMG/$1.$IMGEXT.$DIFFEXT"
85    if [ -f $IMGPATH ]; then
86        echo "Borrando fichero $IMGPATH"
87        rm -f $IMGPATH && rm -f $IMGPATH.{sum,full.sum,torrent}
88    else
89        # Eliminar directorio de imagen sincronizada.
90        IMGPATH="$OGIMG/$1"
91        if [ -d $IMGPATH ]; then
92            echo "Borrando directorio $IMGPATH"
93            rm -fr $IMGPATH
94        fi
95    fi
96fi
97
98# Recuperar copia de seguridad de la imagen.
99if [ -n "$RECOVERBACKUP" ]; then
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
103             mv -f $IMGPATH.full.sum.$BAKEXT $IMGPATH.full.sum 2>/dev/null
104             mv -f $IMGPATH.torrent.$BAKEXT $IMGPATH.torrent 2>/dev/null)
105fi
106
107# Borrar copia de seguridad de la imagen.
108if [ -n "$DELETEBACKUP" ]; then
109    [ -e $IMGPATH.$BAKEXT ] && echo "Eliminando copia $IMGPATH.$BAKEXT"
110    rm -f $IMGPATH.$BAKEXT && rm -f $IMGPATH.{sum,full.sum,torrent}.$BAKEXT
111fi
112
Note: See TracBrowser for help on using the repository browser.