Statistiques
| Révision :

root / bin / create-volume @ 40

Historique | Voir | Annoter | Télécharger (3,96 ko)

1
#!/bin/bash
2
# $Id: create-volume 40 2013-10-08 14:37:55Z ltaulell $
3

    
4
function usage {
5
echo "Syntax :" 1>&2
6
echo "$0 [options]" 1>&2
7
echo " -n : volume name" 1>&2
8
echo " -p : pool name" 1>&2
9
echo " -b : block size. Permit value : 32K, 64K, 128K (recommanded)" 1>&2
10
echo " -s : volume size. Permit unit : T, G, M"  1>&2
11
# FIXME: c'est pas clair ta formulation
12
echo " -o : options zfs volume. Read the man zfs for more details" 1>&2
13
}
14

    
15

    
16
function nointeractive {
17

    
18
if [[ -z $VOL_OPTION ]]
19
then
20
/sbin/zfs create -s -b $BLOCK_SIZE -V $SIZE $NAME_POOL/$NAME
21
else
22
/sbin/zfs create -s -b $BLOCK_SIZE -o $VOL_OPTION -V $SIZE $NAME_POOL/$NAME
23
fi
24

    
25
}
26

    
27

    
28
function interactive {
29
zfs list
30
# FIXME: c'est pas clair ta formulation
31
echo "*** Choose a pool for the ZFS volume to create: ***"
32

    
33
while read inputline
34
do
35
   if [ "$inputline" != "" ]
36
   then
37
      zfs list |grep -i $inputline
38
      if [ $? -eq 1 ]
39
      then
40
# FIXME: c'est pas clair ta formulation
41
         echo "*** Choose a pool for the ZFS volume to create: ***"
42
      else
43

    
44
         echo "*** Are you sure: $inputline ? (y/n) ***"
45
         while read inputConfirm
46
         do
47
            if [ "$inputConfirm" = "y" ]||[ "$inputConfirm" = "n" ]
48
            then
49
              break
50
            fi
51
            echo "*** Are you sure: $inputline ? (y/n) ***"
52
          done
53

    
54
          if [ "$inputConfirm" = "y" ]
55
          then
56
             NAME_POOL=$inputline
57
             echo "volume name: "
58
             while read inputVolume
59
             do
60
                if [ "$inputVolume" != "" ]
61
                then
62
                   test -d /dev/zvol
63
                   if [ $? -eq 0 ]
64
                   then
65
                      ls -l /dev/zvol/$NAME_POOL/$inputVolume
66
                      if [ $? -eq 0 ]
67
                      then
68
                         echo "volume name already exists"
69
                         VOL_OK=1   
70
                      else
71
                         VOL_OK=0
72
                      fi
73
                   else
74
                      VOL_OK=0 
75
                   fi
76
                   if [ $VOL_OK -eq 1 ]
77
                   then
78
                      echo "volume name: "
79
                   else
80
                      NAME_VOL=$inputVolume
81
                      echo "volume size (Unit in T|G|M): "
82
                      while read inputSize
83
                      do
84
                         if [ "$inputSize" != "" ]
85
                         then
86
                           zfs create -s -b 128K -V $inputSize  $NAME_POOL/$inputVolume
87
                           if [ $? -eq 0 ]
88
                           then
89
                              echo "*** ZFS volume creation [OK] ***" 
90
                              zfs list
91
                              break
92
                           else
93
                              echo "/!\\ ZFS volume creation [ERROR] /!\\"
94
                           fi
95
                        else
96
                           echo "volume size (Unit in T|G|M): "   
97
                        fi
98
                      done
99
                      break
100
                    fi
101
                else
102
                  echo "volume name: "
103
                fi
104
             done
105
             break
106
          fi
107
          break
108
      fi
109
   else
110
# FIXME: c'est pas clair ta formulation
111
      echo "*** Choose a pool for the ZFS volume to create: ***"
112
   fi
113
done
114
}
115

    
116
while getopts "in:p:b:s:o:h" OPTION
117
do
118
     case $OPTION in
119
         h)
120
             usage
121
             exit 1
122
             ;;
123
         i)
124
            interactive
125
            exit 0
126
            ;;
127
         n)
128
           NAME=$OPTARG
129
           ;;
130
         p)
131
           NAME_POOL=$OPTARG
132
           ;;
133
         b)
134
           BLOCK_SIZE=$OPTARG
135
           ;;
136
         s)
137
           SIZE=$OPTARG
138
           ;;
139
         o)
140
           VOL_OPTION=$OPTARG
141
           VOL_OPTION=$(echo $VOL_OPTION|sed -e 's/,/ -o /g')
142
           echo "$VOL_OPTION"
143
           ;;
144
         *)
145
          usage
146
          exit 1
147
          ;;
148
    esac
149
done
150

    
151

    
152
if [[ -z $NAME ]] || [[ -z $NAME_POOL ]] || [[ -z $BLOCK_SIZE ]] || [[ -z $SIZE ]]
153
then
154
     usage
155
     exit 1
156
fi
157
nointeractive