# HG changeset patch # User Franz Glasner # Date 1662914271 -7200 # Node ID 590007b0e902b3af99886b72a1481e509079fd39 # Parent 62b38b2312b4855521e70840d4b45f90141dcea8 Implement "-L" and "-P" for "datasets-tmpl" to allow for different ZFS props diff -r 62b38b2312b4 -r 590007b0e902 sbin/ftjail --- a/sbin/ftjail Sun Sep 11 17:57:09 2022 +0200 +++ b/sbin/ftjail Sun Sep 11 18:37:51 2022 +0200 @@ -38,6 +38,11 @@ The datasets will not be mounted. + -L Create dataset properties optimized for employing a + "skeleton" subdirectory + -P Create dataset properties optimized for direct mounts + of skeleton children over an already mounted base + mount-tmpl [ OPTIONS ] BASE-RO SKELETON-RW MOUNTPOINT Canonically mount the RO base and the RW skeleton into MOUNTPOINT and @@ -178,13 +183,21 @@ command_datasets_tmpl_skel() { local _p_base _name - local _opt_dry_run + local _opt_dry_run _opt_symlink local _ds_skel _child _child_zfsopts _opt _opt_dry_run="" - while getopts "nu" _opt ; do + _opt_symlink="" + + while getopts "LPnu" _opt ; do case ${_opt} in + L) + _opt_symlink="yes" + ;; + P) + _opt_symlink="no" + ;; n|u) _opt_dry_run="yes" ;; @@ -196,6 +209,8 @@ shift $((OPTIND-1)) OPTIND=1 + [ -z "${_opt_symlink}" ] && { echo "ERROR: -L or -P must be given" 1>&2; return 2; } + _p_skel="${1-}" _name="${2-}" @@ -218,13 +233,18 @@ return 1 fi - [ "${_opt_dry_run}" = "yes" ] && return 0 echo "Creating RW skeleton datasets in:" printf "\\t%s\\n" "${_ds_skel}" - zfs create -u -o canmount=noauto "${_ds_skel}" + if [ "${_opt_symlink}" = "yes" ]; then + # In this case the skeleton root needs to be mounted into a "skeleton" subdir + zfs create -u -o canmount=noauto "${_ds_skel}" + else + # Only childres are to be mounted + zfs create -u -o canmount=off "${_ds_skel}" + fi zfs create -u -o canmount=off "${_ds_skel}/usr" # # XXX FIXME: What about usr/ports/distfiles @@ -266,9 +286,29 @@ command_datasets_tmpl() { # parent ZFS dataset -- child ZFS dataset name local _p_base _p_skel _name - local _ds_base _ds_skel + local _opt_symlink + + local _ds_base _ds_skel _opt + + _opt_symlink="" - _ensure_no_options "$@" + while getopts "LP" _opt ; do + case ${_opt} in + L) + _opt_symlink="-L" + ;; + P) + _opt_symlink="-P" + ;; + \?) + return 2; + ;; + esac + done + shift $((OPTIND-1)) + OPTIND=1 + + [ -z "${_opt_symlink}" ] && { echo "ERROR: -L or -P must be given" 1>&2; return 2; } _p_base="${1-}" _p_skel="${2-}" @@ -276,11 +316,11 @@ # Check preconditions command_datasets_tmpl_base -n "${_p_base}" "${_name}" || return - command_datasets_tmpl_skel -n "${_p_skel}" "${_name}" || return + command_datasets_tmpl_skel -n ${_opt_symlink} "${_p_skel}" "${_name}" || return # Really do it command_datasets_tmpl_base "${_p_base}" "${_name}" || return - command_datasets_tmpl_skel "${_p_skel}" "${_name}" || return + command_datasets_tmpl_skel ${_opt_symlink} "${_p_skel}" "${_name}" || return return 0 }