2008-12-05 17:46:11 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2009-01-16 20:06:25 +00:00
|
|
|
. ./common.sh
|
2009-01-16 21:57:12 +00:00
|
|
|
PROG=zpool-create.sh
|
2008-12-05 17:46:11 +00:00
|
|
|
|
2009-01-16 20:53:12 +00:00
|
|
|
usage() {
|
|
|
|
cat << EOF
|
|
|
|
USAGE:
|
|
|
|
$0 [hvcp]
|
|
|
|
|
|
|
|
DESCRIPTION:
|
|
|
|
Create one of several predefined zpool configurations.
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-h Show this message
|
|
|
|
-v Verbose
|
2009-01-20 22:10:30 +00:00
|
|
|
-c Configuration for zpool
|
|
|
|
-p Name for zpool
|
|
|
|
-d Destroy zpool (default create)
|
2009-01-16 20:53:12 +00:00
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
check_config() {
|
|
|
|
|
|
|
|
if [ ! -f ${ZPOOL_CONFIG} ]; then
|
2009-01-20 22:15:05 +00:00
|
|
|
local NAME=`basename ${ZPOOL_CONFIG} .sh`
|
2009-01-16 20:53:12 +00:00
|
|
|
ERROR="Unknown config '${NAME}', available configs are:\n"
|
|
|
|
|
|
|
|
for CFG in `ls ${TOPDIR}/scripts/zpool-config/`; do
|
2009-01-20 22:15:05 +00:00
|
|
|
local NAME=`basename ${CFG} .sh`
|
2009-01-16 20:53:12 +00:00
|
|
|
ERROR="${ERROR}${NAME}\n"
|
|
|
|
done
|
|
|
|
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2009-01-20 22:15:05 +00:00
|
|
|
ZPOOL_CONFIG=zpool_config.sh
|
2009-01-16 20:53:12 +00:00
|
|
|
ZPOOL_NAME=tank
|
2009-01-20 22:10:30 +00:00
|
|
|
ZPOOL_DESTROY=
|
2009-01-16 20:53:12 +00:00
|
|
|
|
2009-01-20 22:10:30 +00:00
|
|
|
while getopts 'hvc:p:d' OPTION; do
|
2009-01-16 20:53:12 +00:00
|
|
|
case $OPTION in
|
|
|
|
h)
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
v)
|
|
|
|
VERBOSE=1
|
|
|
|
;;
|
|
|
|
c)
|
2009-01-20 22:15:05 +00:00
|
|
|
ZPOOL_CONFIG=${TOPDIR}/scripts/zpool-config/${OPTARG}.sh
|
2009-01-16 20:53:12 +00:00
|
|
|
;;
|
|
|
|
p)
|
|
|
|
ZPOOL_NAME=${OPTARG}
|
|
|
|
;;
|
2009-01-20 22:10:30 +00:00
|
|
|
d)
|
|
|
|
ZPOOL_DESTROY=1
|
|
|
|
;;
|
2009-01-16 20:53:12 +00:00
|
|
|
?)
|
|
|
|
usage
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2009-01-16 22:51:52 +00:00
|
|
|
if [ $(id -u) != 0 ]; then
|
|
|
|
die "Must run as root"
|
|
|
|
fi
|
|
|
|
|
2009-01-16 20:53:12 +00:00
|
|
|
check_config || die "${ERROR}"
|
|
|
|
. ${ZPOOL_CONFIG}
|
|
|
|
|
2009-01-20 22:10:30 +00:00
|
|
|
if [ ${ZPOOL_DESTROY} ]; then
|
|
|
|
zpool_destroy
|
|
|
|
else
|
|
|
|
zpool_create
|
|
|
|
|
2009-01-20 23:34:38 +00:00
|
|
|
if [ ${VERBOSE} ]; then
|
|
|
|
echo
|
|
|
|
echo "zpool list"
|
|
|
|
${CMDDIR}/zpool/zpool list || exit 1
|
2009-01-16 20:53:12 +00:00
|
|
|
|
2009-01-20 23:34:38 +00:00
|
|
|
echo
|
|
|
|
echo "zpool status ${ZPOOL_NAME}"
|
|
|
|
${CMDDIR}/zpool/zpool status ${ZPOOL_NAME} || exit 1
|
|
|
|
fi
|
2009-01-16 21:57:12 +00:00
|
|
|
fi
|
2009-01-16 20:53:12 +00:00
|
|
|
|
|
|
|
exit 0
|