From 65b8eea86f5f33499a4fe3368127b754a178e55f Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sun, 23 Feb 2025 12:03:43 -0700 Subject: [PATCH] zfs: Implement new functions --- usr/local/share/bastille/zfs.sh | 92 +++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 32 deletions(-) diff --git a/usr/local/share/bastille/zfs.sh b/usr/local/share/bastille/zfs.sh index 3ba50792..8ffef062 100644 --- a/usr/local/share/bastille/zfs.sh +++ b/usr/local/share/bastille/zfs.sh @@ -34,7 +34,14 @@ . /usr/local/etc/bastille/bastille.conf usage() { - error_exit "Usage: bastille zfs TARGET [set|get|snap] [key=value|date]'" + error_notify "Usage: bastille zfs TARGET [set|get|snap|destroy_snap|df|usage] [key=value|date]" + cat << EOF + Options: + + -x | --debug Enable debug mode. + +EOF + exit 1 } zfs_snapshot() { @@ -79,47 +86,68 @@ for _jail in ${JAILS}; do done } -# Handle special-case commands first. -case "$1" in -help|-h|--help) + +# Handle options. +while [ "$#" -gt 0 ]; do + case "${1}" in + -h|--help|help) + usage + ;; + -x|--debug) + enable_debug + shift + ;; + -*) + error_notify "Unknown Option: \"${1}\"" + usage + ;; + *) + break + ;; + esac +done + +if [ "$#" -lt 2 ]; then usage - ;; -esac +fi + +TARGET="${1}" +ACTION="${2}" bastille_root_check +set_target "${TARGET}" -## check ZFS enabled +# Check if ZFS is enabled if ! checkyesno bastille_zfs_enable; then error_exit "ZFS not enabled." fi -## check zpool defined +# Check if zpool is defined if [ -z "${bastille_zfs_zpool}" ]; then error_exit "ZFS zpool not defined." fi -if [ $# -lt 1 ]; then - usage -fi - -case "$1" in -set) - ATTRIBUTE=$2 - zfs_set_value - ;; -get) - ATTRIBUTE=$2 - zfs_get_value - ;; -snap|snapshot) - TAG=$2 - zfs_snapshot - ;; -destroy_snap|destroy_snapshot) - TAG=$2 - zfs_destroy_snapshot - ;; -df|usage) - zfs_disk_usage - ;; +case "${ACTION}" in + set) + ATTRIBUTE="${3}" + zfs_set_value + ;; + get) + ATTRIBUTE="${3}" + zfs_get_value + ;; + snap|snapshot) + TAG="${3}" + zfs_snapshot + ;; + destroy_snap|destroy_snapshot) + TAG="${3}" + zfs_destroy_snapshot + ;; + df|usage) + zfs_disk_usage + ;; + *) + usage + ;; esac