Statistiques
| Révision :

root / bin / create-filesystem @ 40

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

1
#!/bin/bash
2
# $Id: create-filesystem 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 : filesystem name" 1>&2
8
echo " -p : pool name" 1>&2
9
# FIXME: c'est pas clair ta formulation :
10
echo " -o : options zfs filesystem. Read the man zfs for more details" 1>&2
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
# FIXME: c'est pas clair ta formulation
23
echo "*** Choose a pool for the filesystem to create: ***"
24

    
25
while read inputline
26
do
27
   if [ "$inputline" != "" ]
28
   then
29
      zfs list |grep -i $inputline
30
      if [ $? -eq 1 ]
31
      then
32
# FIXME: c'est pas clair ta formulation
33
         echo "*** Choose a pool for the filesystem to create: ***"
34
      else
35

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

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

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

    
122
nointeractive