Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
changeset 246:bdee72ff7dbd
Some subcommands now support options properly
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 10 Sep 2022 19:13:41 +0200 |
| parents | 61861d36758c |
| children | 5dd38cb3fecf |
| files | sbin/ftjail |
| diffstat | 1 files changed, 45 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/sbin/ftjail Sat Sep 10 18:16:37 2022 +0200 +++ b/sbin/ftjail Sat Sep 10 19:13:41 2022 +0200 @@ -90,6 +90,7 @@ ' local _mountpoint + local _ds _mount _rest _mountpoint="$1" @@ -111,15 +112,28 @@ # PARENT-BASE NAME DRY-RUN # command_datasets_tmpl_base() { - local _p_base _name _dry_run + local _p_base _name + + local _opt_dry_run + + local _ds_base _opt - local _ds_base - - _ensure_no_options "$@" + _opt_dry_run="" + while getopts "nu" _opt ; do + case ${_opt} in + n|u) + _opt_dry_run="yes" + ;; + \?|:) + return 2; + ;; + esac + done + shift $((OPTIND-1)) + OPTIND=1 _p_base="${1-}" _name="${2-}" - _dry_run="${3-}" if [ -z "${_p_base}" ]; then echo "ERROR: no parent dataset for base given" >&2 @@ -141,7 +155,7 @@ fi - [ "${_dry_run}" = "yes" ] && return 0 + [ "${_opt_dry_run}" = "yes" ] && return 0 echo "Creating RO base datasets in:" printf "\\t%s\\n" "${_ds_base}" @@ -155,15 +169,28 @@ # SKELETON NAME DRY-RUN # command_datasets_tmpl_skel() { - local _p_base _name _dry_run + local _p_base _name + + local _opt_dry_run + + local _ds_skel _child _child_zfsopts _opt - local _ds_skel _child _child_zfsopts - - _ensure_no_options "$@" + _opt_dry_run="" + while getopts "nu" _opt ; do + case ${_opt} in + n|u) + _opt_dry_run="yes" + ;; + \?|:) + return 2; + ;; + esac + done + shift $((OPTIND-1)) + OPTIND=1 _p_skel="${1-}" _name="${2-}" - _dry_run="${3-}" if [ -z "${_p_skel}" ]; then echo "ERROR: no parent dataset for skeleton given" >&2 @@ -185,7 +212,7 @@ fi - [ "${_dry_run}" = "yes" ] && return 0 + [ "${_opt_dry_run}" = "yes" ] && return 0 echo "Creating RW skeleton datasets in:" printf "\\t%s\\n" "${_ds_skel}" @@ -244,8 +271,8 @@ _name="${3-}" # Check preconditions - command_datasets_tmpl_base "${_p_base}" "${_name}" "yes" || return - command_datasets_tmpl_skel "${_p_skel}" "${_name}" "yes" || return + command_datasets_tmpl_base -n "${_p_base}" "${_name}" || return + command_datasets_tmpl_skel -n "${_p_skel}" "${_name}" || return # Really do it command_datasets_tmpl_base "${_p_base}" "${_name}" || return @@ -311,6 +338,7 @@ # _do_mount() { local _dsname _mountpoint _dry_run _mount_natural + local _name _mp _canmount _mounted local _rootds_mountpoint _relative_mp _real_mp @@ -411,8 +439,9 @@ # command_mount_tmpl() { local _ds_base _ds_skel _mountpoint + local _opt_dry_run - local _opt_dry_run _opt + local _opt _opt_dry_run="" @@ -450,6 +479,7 @@ # _do_umount() { local _dsname + local _name _mp _rest local _rootds_mountpoint
