Statistiques
| Révision :

root / bin / create-filesystem @ 41

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

1
#!/bin/bash
2
# $Id: create-filesystem 41 2013-10-09 08:44:10Z kreverch $
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 : set property list for a  zfs volume. Separate such property by a ','." 1>&2
10
echo "      Example : -o compression=off,snapdev=visble." 1>&2
11
echo "      Read the man zfs to get the list of the valid properties" 1>&2
12
echo " -i : interactive mode" 1>&2
13

    
14
}
15

    
16
function nointeractive {
17

    
18
/sbin/zfs create -o $FS_OPTION $NAME_POOL/$NAME
19

    
20
}
21

    
22

    
23
function interactive {
24
zfs list
25
# FIXME: c'est pas clair ta formulation
26
echo "*** Choose a pool for the filesystem to create: ***"
27

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

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

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

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

    
125
nointeractive