Statistiques
| Révision :

root / bin / create-filesystem @ 39

Historique | Voir | Annoter | Télécharger (2,77 ko)

1
#!/bin/bash
2
# $Id: create-filesystem 39 2013-10-08 12:46:21Z ltaulell $
3

    
4
function usage {
5
echo "Syntax :" 1>&2 
6
echo "$0 [options]" 1>&2
7
echo " -n : filesystem name" 1>&2
8
echo " -p : pool name" 1>&2
9
echo " -o : options zfs filesystem. Read the man zfs for more details" 1>&2
10

    
11
}
12

    
13
function nointeractive {
14

    
15
/sbin/zfs create -o $FS_OPTION $NAME_POOL/$NAME
16

    
17
}
18

    
19

    
20
function interactive {
21
zfs list
22
echo "*** Choose a pool for the filesystem to create : ***"
23

    
24
while read inputline
25
do
26
   if [ "$inputline" != "" ]
27
   then
28
      zfs list |grep -i $inputline
29
      if [ $? -eq 1 ]
30
      then
31
         echo "*** Choose a pool for the filesystem to create : ***"
32
      else
33

    
34
         echo "*** Are you sur : $inputline ? (y/n) ***"
35
         while read inputConfirm
36
         do
37
            if [ "$inputConfirm" = "y" ]||[ "$inputConfirm" = "n" ]
38
            then
39
              break
40
            fi
41
            echo "*** Are you sur : $inputline ? (y/n) ***"
42
         done
43

    
44
          if [ "$inputConfirm" = "y" ]
45
          then
46
             NAME_POOL=$inputline
47
             echo "filesystem name : "
48
             while read inputFS
49
             do
50
                if [ "$inputFS" != "" ]
51
                then
52
                   zfs list |grep -i "$inputFS "
53
                   if [ $? -eq 0 ]
54
                   then
55
                         echo "Filesystem name already exists"
56
                         FS_OK=1   
57
                   else
58
                      FS_OK=0 
59
                   fi
60
                   if [ $FS_OK -eq 1 ]
61
                   then
62
                      echo "filesystem name : "
63
                   else
64
                      NAME_FS=$inputFS
65
                           zfs create $NAME_POOL/$inputFS
66
                           if [ $? -eq 0 ]
67
                           then
68
                              echo "*** ZFS filesystem Creation [OK] ***" 
69
                              zfs list
70
                              break
71
                           else
72
                              echo "/!\\ ZFS filesystem Creation [ERROR] /!\\"
73
                           fi
74
                    fi
75
                else
76
                  echo "filesystem name : "
77
                fi
78
             done
79
             break
80
          fi
81
          break
82
      fi
83
   else
84
      echo "*** Choose a pool for the filesystem to create : ***"
85
   fi
86
done
87
}
88

    
89
while getopts "in:p:b:s:o:h" OPTION
90
do
91
     case $OPTION in
92
         h)
93
             usage
94
             exit 1
95
             ;;
96
         i)
97
            interactive
98
            exit 0
99
            ;;
100
         n)
101
           NAME=$OPTARG
102
           ;;
103
         p)
104
           NAME_POOL=$OPTARG
105
           ;;
106
         o)
107
           FS_OPTION=$OPTARG
108
           FS_OPTION=$(echo $FS_OPTION|sed -e 's/,/ -o /g')
109
           echo "$FS_OPTION"
110
           ;;
111
    esac
112
done
113
if [[ -z $NAME_POOL ]] || [[ -z $NAME ]] 
114
then
115
     usage
116
     exit 1
117
fi
118

    
119
nointeractive