GCC 7.1 fixes
[zfs.git] / scripts / zpool-create.sh
blob16ee6714680615981440ce79bbbc753760c1186f
1 #!/bin/bash
3 basedir="$(dirname $0)"
5 SCRIPT_COMMON=common.sh
6 if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
7 . "${basedir}/${SCRIPT_COMMON}"
8 else
9 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
12 PROG=zpool-create.sh
14 usage() {
15 cat << EOF
16 USAGE:
17 $0 [hvfxcp]
19 DESCRIPTION:
20 Create one of several predefined zpool configurations.
22 OPTIONS:
23 -h Show this message
24 -v Verbose
25 -f Force everything
26 -x Disable all zpool features
27 -c Configuration for zpool
28 -p Name for zpool
29 -d Destroy zpool (default create)
30 -l Additional zpool options
31 -s Additional zfs options
33 EOF
36 check_config() {
38 if [ ! -f ${ZPOOL_CONFIG} ]; then
39 local NAME=`basename ${ZPOOL_CONFIG} .sh`
40 ERROR="Unknown config '${NAME}', available configs are:\n"
42 for CFG in `ls ${ZPOOLDIR}/ | grep ".sh"`; do
43 local NAME=`basename ${CFG} .sh`
44 ERROR="${ERROR}${NAME}\n"
45 done
47 return 1
50 return 0
53 ZPOOL_CONFIG=unknown
54 ZPOOL_NAME=tank
55 ZPOOL_DESTROY=
56 ZPOOL_FLAGS=${ZPOOL_FLAGS:-""}
57 ZPOOL_OPTIONS=""
58 ZFS_OPTIONS=""
60 while getopts 'hvfxc:p:dl:s:' OPTION; do
61 case $OPTION in
63 usage
64 exit 1
67 VERBOSE=1
68 VERBOSE_FLAG="-v"
71 FORCE=1
72 ZPOOL_FLAGS="$ZPOOL_FLAGS -f"
75 NO_FEATURES=1
76 ZPOOL_FLAGS="$ZPOOL_FLAGS -d"
79 ZPOOL_CONFIG=${ZPOOLDIR}/${OPTARG}.sh
82 ZPOOL_NAME=${OPTARG}
85 ZPOOL_DESTROY=1
88 ZPOOL_OPTIONS=${OPTARG}
91 ZFS_OPTIONS=${OPTARG}
94 usage
95 exit 1
97 esac
98 done
100 if [ $(id -u) != 0 ]; then
101 die "Must run as root"
104 check_config || die "${ERROR}"
105 . ${ZPOOL_CONFIG}
107 if [ ${ZPOOL_DESTROY} ]; then
108 zpool_destroy
109 else
110 zpool_create
112 if [ "${ZPOOL_OPTIONS}" ]; then
113 if [ ${VERBOSE} ]; then
114 echo
115 echo "${ZPOOL} ${ZPOOL_OPTIONS} ${ZPOOL_NAME}"
117 ${ZPOOL} ${ZPOOL_OPTIONS} ${ZPOOL_NAME} || exit 1
120 if [ "${ZFS_OPTIONS}" ]; then
121 if [ ${VERBOSE} ]; then
122 echo
123 echo "${ZFS} ${ZFS_OPTIONS} ${ZPOOL_NAME}"
125 ${ZFS} ${ZFS_OPTIONS} ${ZPOOL_NAME} || exit 1
128 if [ ${VERBOSE} ]; then
129 echo
130 echo "zpool list"
131 ${ZPOOL} list || exit 1
133 echo
134 echo "zpool status ${ZPOOL_NAME}"
135 ${ZPOOL} status ${ZPOOL_NAME} || exit 1
139 exit 0