From fb906b659c046a9755baa933043e629392824374 Mon Sep 17 00:00:00 2001 From: Alex Tavarez Date: Wed, 17 Sep 2025 12:03:40 -0400 Subject: [PATCH] Added a position shift for script arguments, simplified conditional case --- zfs/zfs-media-drive.help | 9 +++++++++ zfs/zfs-media-drive.sh | 9 ++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 zfs/zfs-media-drive.help diff --git a/zfs/zfs-media-drive.help b/zfs/zfs-media-drive.help new file mode 100644 index 0000000..31185da --- /dev/null +++ b/zfs/zfs-media-drive.help @@ -0,0 +1,9 @@ +This script allows the creation of ZFS pool specifically for the purpose of media. +This pool is divided into datasets that allow useful storage management of that media. + +-k Option to provide a custom path to the key for the encrypted filesystem. Equivalent to 'keylocation' option in ZFS pool creation. +-f Opton to provide a custom format for the aforementioned key. Equivalnt to 'keyformat' option in ZFS pool creation. +-c Option to specify custom ZFS compression algorithm for ZFS pool. Equivalent to 'compression' option in ZFS pool creation. +-v Option to specify custom ZFS version for compatibility purposes. Equivalent to 'compatibility' option in ZFS pool creation. +-p Option to provide a custom name for the created ZFS pool. +-d Specify the storage device, volume or partition to be given a pool. diff --git a/zfs/zfs-media-drive.sh b/zfs/zfs-media-drive.sh index c73bfbd..2f28748 100644 --- a/zfs/zfs-media-drive.sh +++ b/zfs/zfs-media-drive.sh @@ -1,6 +1,7 @@ #!/bin/bash set -euo pipefail +SCRIPT_ROOT=$(dirname "$0") # @TODO: Implement more soft-coding and interactivity to this script ZFS_POOL_NAME="media" ZFS_COMPAT="openzfs-2.1-linux" @@ -61,14 +62,16 @@ create_datasets () { } print_menu () { - echo "Placeholder content" + echo "$(<"${SCRIPT_ROOT}"/zfs-media-drive.help)" } if [ -z "$1" ]; then exit 1 fi -if ! [ -z "$1" ] && [ "$1" == "init" ]; then +if [ -n "$1" ] && [ "$1" == "init" ]; then + shift + while getopts "d:p:k:f:c:v:" opt; do case $opt in k) ZFS_KEY_LOC="${OPTARG}";; @@ -82,7 +85,7 @@ if ! [ -z "$1" ] && [ "$1" == "init" ]; then done if [ -z "$ZFS_TARGET_DRIVE" ]; then - echo "It is necessary to argue a -d option." + echo "Error: It is necessary to argue a -d option." exit 1 fi