source: repoman/bin/deleteimage @ 642e39f

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 642e39f was 841e5ef, checked in by ramon <ramongomez@…>, 10 years ago

#674: Actualizar comentario de versión del script deleteimage.

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

  • Property mode set to 100755
File size: 2.7 KB
Line 
1#!/bin/bash
2#         deleteimage [ -b | -r ] 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.
8#@version 1.0 - Versión inicial.
9#@date    2012-10-14
10#@author  Ramón Gómez, ETSII Univ. Sevilla
11#@version 1.0.5 - Eliminar imagen incremental.
12#@date    2013-07-17
13#@author  Alberto García, Univ. Málaga
14#@version 1.0.6 - Detección automática del tipo de imagen.
15#@date    2014-10-29
16#@author  Ramón Gómez, ETSII Univ. Sevilla
17
18
19PROG=$(basename $0)
20OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"}
21OGIMG=$OPENGNSYS/images
22IMGEXT="img"
23BAKEXT="ant"
24DIFFEXT="diff"
25
26# Si se solicita, mostrar ayuda.
27if [ "$*" == "help" ]; then
28    cat << EOT
29$PROG: Borra los ficheros de una imagen del repositorio.
30Formato: $PROG [ -b | -r ] str_image
31         -b  Elimina también la copia de seguridad de la imagen.
32         -r  Recupera la copia de seguridad de la imagen.
33Ejemplo: $PROG imagen1
34EOT
35    exit 0
36fi
37# Procesar parámetros
38while getopts br OPTION; do
39    case $OPTION in
40        b) DELETEBACKUP=1 ;;
41        r) RECOVERBACKUP=1 ;;
42        *) ERR=1 ;;
43    esac
44    shift $((OPTIND-1))
45done
46[ -n "$DELETEBACKUP" ] && [ -n "$RECOVERBACKUP" ] && ERR=1
47if [ $# != 1 -o -n "$ERR" ]; then
48    echo "$PROG Error: Formato: $PROG [ -b | -r ] str_image"
49    exit 1
50fi
51
52# Eliminar ficheros de imagen monolítica o sincronizada básica.
53IMGPATH="$OGIMG/$1.$IMGEXT"
54if [ -f $IMGPATH ]; then
55    echo "Borrando fichero $PATHDIR"
56    rm -f $IMGPATH && rm -f $IMGPATH.{sum,torrent}
57else
58    # Eliminar ficheros de imagen sincronizada diferencial.
59    IMGPATH="$OGIMG/$1.$IMGEXT.$DIFFEXT"
60    if [ -f $IMGPATH ]; then
61        echo "Borrando fichero $PATHDIR"
62        rm -f $IMGPATH && rm -f $IMGPATH.{sum,torrent}
63    else
64        # Eliminar directorio de imagen sincronizada.
65        IMGPATH="$OGIMG/$1"
66        if [ -d $IMGPATH ]; then
67            echo "Borrando directorio $PATHDIR"
68            rm -fr $IMGPATH
69        fi
70    fi
71fi
72
73# Recuperar copia de seguridad de la imagen.
74if [ -n "$RECOVERBACKUP" ]; then
75    [ -e $IMGPATH.$BAKEXT ] && echo "Recuperando copia $IMGPATH.$BAKEXT"
76    mv -f $IMGPATH.$BAKEXT $IMGPATH && \
77            (mv -f $IMGPATH.sum.$BAKEXT $IMGPATH.sum 2>/dev/null
78             mv -f $IMGPATH.torrent.$BAKEXT $IMGPATH.torrent 2>/dev/null)
79fi
80
81# Borrar copia de seguridad de la imagen.
82if [ -n "$DELETEBACKUP" ]; then
83    [ -e $IMGPATH ] && echo "Eliminando copia $IMGPATH.$BAKEXT"
84    rm -f $IMGPATH.$BAKEXT && rm -f $IMGPATH.{sum,torrent}.$BAKEXT
85fi
86
Note: See TracBrowser for help on using the repository browser.