Statistiques
| Révision :

root / bin / create-filesystem @ 46

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

1
#!/bin/bash
2
# $Id: create-filesystem 46 2013-10-10 05:22:26Z 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
/sbin/zfs list
25
echo "*** Select the parent zpool : ***"
26

    
27
while read inputline
28
do
29
   if [ "$inputline" != "" ]
30
   then
31
      /sbin/zfs list |grep -i $inputline
32
      if [ $? -eq 1 ]
33
      then
34
         echo "*** Select the parent zpool : ***"
35
      else
36

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

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