Statistiques
| Révision :

root / bin / del-volume @ 49

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

1
#!/bin/bash
2
# $Id: del-volume 49 2013-10-10 08:59:11Z kreverch $
3

    
4
# TODO: fix typos
5
GETINFO_ISCSI="/sbin/get-conf-iscsi-volume"
6
DEL_ISCSI="/sbin/del-iscsi-volume"
7
BINZFS="/sbin/zfs"
8
BINZPOOL="/sbin/zpool"
9

    
10
function usage {
11
  echo "Usage :" 1>&2
12
  echo "$0 [OPTIONS]" 1>&2
13
  echo " -h display this message" 1>&2
14
  echo " -i interactive mode" 1>&2
15
  echo " -n ZFS Volume Name" 1>&2
16

    
17
}
18

    
19
function nointeractive {
20

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

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

    
38

    
39
function interactive {
40

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

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

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

    
89
if [[ -z $NAME_VOL ]]
90
then
91
     usage
92
     exit 1
93
fi
94
nointeractive
95

    
96

    
97

    
98