comparison sbin/ftjail @ 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
comparison
equal deleted inserted replaced
245:61861d36758c 246:bdee72ff7dbd
88 _get_dataset_for_mountpoint() { 88 _get_dataset_for_mountpoint() {
89 : 'Use `mount -t zfs -p` to determine the ZFS dataset for a given mountpoint. 89 : 'Use `mount -t zfs -p` to determine the ZFS dataset for a given mountpoint.
90 90
91 ' 91 '
92 local _mountpoint 92 local _mountpoint
93
93 local _ds _mount _rest 94 local _ds _mount _rest
94 95
95 _mountpoint="$1" 96 _mountpoint="$1"
96 97
97 mount -t zfs -p \ 98 mount -t zfs -p \
109 110
110 # 111 #
111 # PARENT-BASE NAME DRY-RUN 112 # PARENT-BASE NAME DRY-RUN
112 # 113 #
113 command_datasets_tmpl_base() { 114 command_datasets_tmpl_base() {
114 local _p_base _name _dry_run 115 local _p_base _name
115 116
116 local _ds_base 117 local _opt_dry_run
117 118
118 _ensure_no_options "$@" 119 local _ds_base _opt
120
121 _opt_dry_run=""
122 while getopts "nu" _opt ; do
123 case ${_opt} in
124 n|u)
125 _opt_dry_run="yes"
126 ;;
127 \?|:)
128 return 2;
129 ;;
130 esac
131 done
132 shift $((OPTIND-1))
133 OPTIND=1
119 134
120 _p_base="${1-}" 135 _p_base="${1-}"
121 _name="${2-}" 136 _name="${2-}"
122 _dry_run="${3-}"
123 137
124 if [ -z "${_p_base}" ]; then 138 if [ -z "${_p_base}" ]; then
125 echo "ERROR: no parent dataset for base given" >&2 139 echo "ERROR: no parent dataset for base given" >&2
126 return 2 140 return 2
127 fi 141 fi
139 echo "ERROR: dataset \`${_ds_base}' does already exist" >&2 153 echo "ERROR: dataset \`${_ds_base}' does already exist" >&2
140 return 1 154 return 1
141 fi 155 fi
142 156
143 157
144 [ "${_dry_run}" = "yes" ] && return 0 158 [ "${_opt_dry_run}" = "yes" ] && return 0
145 159
146 echo "Creating RO base datasets in:" 160 echo "Creating RO base datasets in:"
147 printf "\\t%s\\n" "${_ds_base}" 161 printf "\\t%s\\n" "${_ds_base}"
148 162
149 zfs create -u -o canmount=noauto "${_ds_base}" 163 zfs create -u -o canmount=noauto "${_ds_base}"
153 167
154 # 168 #
155 # SKELETON NAME DRY-RUN 169 # SKELETON NAME DRY-RUN
156 # 170 #
157 command_datasets_tmpl_skel() { 171 command_datasets_tmpl_skel() {
158 local _p_base _name _dry_run 172 local _p_base _name
159 173
160 local _ds_skel _child _child_zfsopts 174 local _opt_dry_run
161 175
162 _ensure_no_options "$@" 176 local _ds_skel _child _child_zfsopts _opt
177
178 _opt_dry_run=""
179 while getopts "nu" _opt ; do
180 case ${_opt} in
181 n|u)
182 _opt_dry_run="yes"
183 ;;
184 \?|:)
185 return 2;
186 ;;
187 esac
188 done
189 shift $((OPTIND-1))
190 OPTIND=1
163 191
164 _p_skel="${1-}" 192 _p_skel="${1-}"
165 _name="${2-}" 193 _name="${2-}"
166 _dry_run="${3-}"
167 194
168 if [ -z "${_p_skel}" ]; then 195 if [ -z "${_p_skel}" ]; then
169 echo "ERROR: no parent dataset for skeleton given" >&2 196 echo "ERROR: no parent dataset for skeleton given" >&2
170 return 2 197 return 2
171 fi 198 fi
183 echo "ERROR: dataset \`${_ds_skel}' does already exist" >&2 210 echo "ERROR: dataset \`${_ds_skel}' does already exist" >&2
184 return 1 211 return 1
185 fi 212 fi
186 213
187 214
188 [ "${_dry_run}" = "yes" ] && return 0 215 [ "${_opt_dry_run}" = "yes" ] && return 0
189 216
190 echo "Creating RW skeleton datasets in:" 217 echo "Creating RW skeleton datasets in:"
191 printf "\\t%s\\n" "${_ds_skel}" 218 printf "\\t%s\\n" "${_ds_skel}"
192 219
193 zfs create -u -o canmount=noauto "${_ds_skel}" 220 zfs create -u -o canmount=noauto "${_ds_skel}"
242 _p_base="${1-}" 269 _p_base="${1-}"
243 _p_skel="${2-}" 270 _p_skel="${2-}"
244 _name="${3-}" 271 _name="${3-}"
245 272
246 # Check preconditions 273 # Check preconditions
247 command_datasets_tmpl_base "${_p_base}" "${_name}" "yes" || return 274 command_datasets_tmpl_base -n "${_p_base}" "${_name}" || return
248 command_datasets_tmpl_skel "${_p_skel}" "${_name}" "yes" || return 275 command_datasets_tmpl_skel -n "${_p_skel}" "${_name}" || return
249 276
250 # Really do it 277 # Really do it
251 command_datasets_tmpl_base "${_p_base}" "${_name}" || return 278 command_datasets_tmpl_base "${_p_base}" "${_name}" || return
252 command_datasets_tmpl_skel "${_p_skel}" "${_name}" || return 279 command_datasets_tmpl_skel "${_p_skel}" "${_name}" || return
253 return 0 280 return 0
309 # 336 #
310 # _do_mount dataset mountpoint dry-run mount-natural 337 # _do_mount dataset mountpoint dry-run mount-natural
311 # 338 #
312 _do_mount() { 339 _do_mount() {
313 local _dsname _mountpoint _dry_run _mount_natural 340 local _dsname _mountpoint _dry_run _mount_natural
341
314 local _name _mp _canmount _mounted 342 local _name _mp _canmount _mounted
315 local _rootds_mountpoint _relative_mp _real_mp 343 local _rootds_mountpoint _relative_mp _real_mp
316 344
317 _dsname="${1}" 345 _dsname="${1}"
318 _mountpoint="${2}" 346 _mountpoint="${2}"
409 # 437 #
410 # command_mount_tmpl base-ro skeleton-rw mountpoint 438 # command_mount_tmpl base-ro skeleton-rw mountpoint
411 # 439 #
412 command_mount_tmpl() { 440 command_mount_tmpl() {
413 local _ds_base _ds_skel _mountpoint 441 local _ds_base _ds_skel _mountpoint
414 442 local _opt_dry_run
415 local _opt_dry_run _opt 443
444 local _opt
416 445
417 _opt_dry_run="" 446 _opt_dry_run=""
418 447
419 while getopts "nu" _opt ; do 448 while getopts "nu" _opt ; do
420 case ${_opt} in 449 case ${_opt} in
448 # 477 #
449 # _do_umount dataset 478 # _do_umount dataset
450 # 479 #
451 _do_umount() { 480 _do_umount() {
452 local _dsname 481 local _dsname
482
453 local _name _mp _rest 483 local _name _mp _rest
454 local _rootds_mountpoint 484 local _rootds_mountpoint
455 485
456 _dsname="${1}" 486 _dsname="${1}"
457 [ -z "${_dsname}" ] && { echo "ERROR: no dataset given" >&2; return 2; } 487 [ -z "${_dsname}" ] && { echo "ERROR: no dataset given" >&2; return 2; }