Statistiques
| Révision :

root / bin / del-volume

Historique | Voir | Annoter | Télécharger (1,7 ko)

1
#!/bin/bash
2
# $Id: del-volume 51 2013-10-10 11:20:37Z ltaulell $
3
# Copyright (C) 2013 Kevin Reverchon, Loïs Taulelle
4
# This file/program is part of gZFS free software
5
# See COPYING file for details
6
#
7

    
8
# TODO: fix typos
9
GETINFO_ISCSI="/sbin/get-conf-iscsi-volume"
10
DEL_ISCSI="/sbin/del-iscsi-volume"
11
BINZFS="/sbin/zfs"
12
BINZPOOL="/sbin/zpool"
13

    
14
function usage {
15
  echo "Usage :" 1>&2
16
  echo "$0 [OPTIONS]" 1>&2
17
  echo " -h display this message" 1>&2
18
  echo " -i interactive mode" 1>&2
19
  echo " -n ZFS Volume Name" 1>&2
20

    
21
}
22

    
23
function nointeractive {
24

    
25
TID=$($GETINFO_ISCSI $NAME_VOL|grep "^tid "|cut -d " " -f2)
26

    
27
if [ "$TID" == "" ]
28
then
29
   $BINZFS destroy -r $NAME_VOL
30
   
31
else
32
   $DEL_ISCSI -T $TID
33
   if [ $? -eq 0 ]
34
   then
35
     $BINZFS destroy -r $NAME_VOL
36
   else
37
      exit 1;
38
   fi
39
fi 
40
}
41

    
42

    
43
function interactive {
44

    
45
$BINZFS list
46
echo "*** Enter the ZFS Volume Name : ***" 
47
while read inputline
48
do
49
   NAME_VOL=$inputline 
50
   echo "*** Do you want really remove the ZFS Volume : $inputline ? (y/n) ***"
51
   while read inputConfirm
52
   do
53
      if [ "$inputConfirm" = "y" ]||[ "$inputConfirm" = "n" ]
54
      then
55
         break
56
      fi
57
      echo "*** Do you want really remove the ZFS Volume : $inputline ? (y/n) ***"
58
   done
59

    
60
   
61
   if [ "$inputConfirm" = "y" ]
62
   then
63
      break
64
   fi
65
   if [ "$inputConfirm" != "y" ]
66
   then
67
      echo "*** Enter the ZFS Volume Name : ***" 
68
   fi
69
done
70
nointeractive
71
}
72

    
73
while getopts "in:h" OPTION
74
do
75
     case $OPTION in
76
         h)
77
             usage
78
             exit 1
79
             ;;
80
         i)
81
             interactive
82
             ;;
83
         n)
84
             NAME_VOL=$OPTARG
85
             ;;
86
         *)
87
             usage
88
             exit 1
89
             ;;
90
     esac
91
done
92

    
93
if [[ -z $NAME_VOL ]]
94
then
95
     usage
96
     exit 1
97
fi
98
nointeractive
99

    
100

    
101

    
102