Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
comparison sbin/ftjail @ 253:590007b0e902
Implement "-L" and "-P" for "datasets-tmpl" to allow for different ZFS props
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 11 Sep 2022 18:37:51 +0200 |
| parents | 62b38b2312b4 |
| children | 39268cba8c46 |
comparison
equal
deleted
inserted
replaced
| 252:62b38b2312b4 | 253:590007b0e902 |
|---|---|
| 36 PARENT-BASE and PARENT-SKELETON must exist already and NAME must | 36 PARENT-BASE and PARENT-SKELETON must exist already and NAME must |
| 37 not exist. | 37 not exist. |
| 38 | 38 |
| 39 The datasets will not be mounted. | 39 The datasets will not be mounted. |
| 40 | 40 |
| 41 -L Create dataset properties optimized for employing a | |
| 42 "skeleton" subdirectory | |
| 43 -P Create dataset properties optimized for direct mounts | |
| 44 of skeleton children over an already mounted base | |
| 45 | |
| 41 mount-tmpl [ OPTIONS ] BASE-RO SKELETON-RW MOUNTPOINT | 46 mount-tmpl [ OPTIONS ] BASE-RO SKELETON-RW MOUNTPOINT |
| 42 | 47 |
| 43 Canonically mount the RO base and the RW skeleton into MOUNTPOINT and | 48 Canonically mount the RO base and the RW skeleton into MOUNTPOINT and |
| 44 MOUNTPOINT/skeleton | 49 MOUNTPOINT/skeleton |
| 45 | 50 |
| 176 # SKELETON NAME DRY-RUN | 181 # SKELETON NAME DRY-RUN |
| 177 # | 182 # |
| 178 command_datasets_tmpl_skel() { | 183 command_datasets_tmpl_skel() { |
| 179 local _p_base _name | 184 local _p_base _name |
| 180 | 185 |
| 181 local _opt_dry_run | 186 local _opt_dry_run _opt_symlink |
| 182 | 187 |
| 183 local _ds_skel _child _child_zfsopts _opt | 188 local _ds_skel _child _child_zfsopts _opt |
| 184 | 189 |
| 185 _opt_dry_run="" | 190 _opt_dry_run="" |
| 186 while getopts "nu" _opt ; do | 191 _opt_symlink="" |
| 192 | |
| 193 while getopts "LPnu" _opt ; do | |
| 187 case ${_opt} in | 194 case ${_opt} in |
| 195 L) | |
| 196 _opt_symlink="yes" | |
| 197 ;; | |
| 198 P) | |
| 199 _opt_symlink="no" | |
| 200 ;; | |
| 188 n|u) | 201 n|u) |
| 189 _opt_dry_run="yes" | 202 _opt_dry_run="yes" |
| 190 ;; | 203 ;; |
| 191 \?|:) | 204 \?|:) |
| 192 return 2; | 205 return 2; |
| 194 esac | 207 esac |
| 195 done | 208 done |
| 196 shift $((OPTIND-1)) | 209 shift $((OPTIND-1)) |
| 197 OPTIND=1 | 210 OPTIND=1 |
| 198 | 211 |
| 212 [ -z "${_opt_symlink}" ] && { echo "ERROR: -L or -P must be given" 1>&2; return 2; } | |
| 213 | |
| 199 _p_skel="${1-}" | 214 _p_skel="${1-}" |
| 200 _name="${2-}" | 215 _name="${2-}" |
| 201 | 216 |
| 202 if [ -z "${_p_skel}" ]; then | 217 if [ -z "${_p_skel}" ]; then |
| 203 echo "ERROR: no parent dataset for skeleton given" >&2 | 218 echo "ERROR: no parent dataset for skeleton given" >&2 |
| 216 if zfs list -H -o mountpoint -t filesystem "${_ds_skel}" >/dev/null 2>/dev/null; then | 231 if zfs list -H -o mountpoint -t filesystem "${_ds_skel}" >/dev/null 2>/dev/null; then |
| 217 echo "ERROR: dataset \`${_ds_skel}' does already exist" >&2 | 232 echo "ERROR: dataset \`${_ds_skel}' does already exist" >&2 |
| 218 return 1 | 233 return 1 |
| 219 fi | 234 fi |
| 220 | 235 |
| 221 | |
| 222 [ "${_opt_dry_run}" = "yes" ] && return 0 | 236 [ "${_opt_dry_run}" = "yes" ] && return 0 |
| 223 | 237 |
| 224 echo "Creating RW skeleton datasets in:" | 238 echo "Creating RW skeleton datasets in:" |
| 225 printf "\\t%s\\n" "${_ds_skel}" | 239 printf "\\t%s\\n" "${_ds_skel}" |
| 226 | 240 |
| 227 zfs create -u -o canmount=noauto "${_ds_skel}" | 241 if [ "${_opt_symlink}" = "yes" ]; then |
| 242 # In this case the skeleton root needs to be mounted into a "skeleton" subdir | |
| 243 zfs create -u -o canmount=noauto "${_ds_skel}" | |
| 244 else | |
| 245 # Only childres are to be mounted | |
| 246 zfs create -u -o canmount=off "${_ds_skel}" | |
| 247 fi | |
| 228 zfs create -u -o canmount=off "${_ds_skel}/usr" | 248 zfs create -u -o canmount=off "${_ds_skel}/usr" |
| 229 # | 249 # |
| 230 # XXX FIXME: What about usr/ports/distfiles | 250 # XXX FIXME: What about usr/ports/distfiles |
| 231 # We typically want to use binary packages. | 251 # We typically want to use binary packages. |
| 232 # And if we use ports they are not in usr/ports typically. | 252 # And if we use ports they are not in usr/ports typically. |
| 264 # PARENT-BASE PARENT-SKELETON NAME | 284 # PARENT-BASE PARENT-SKELETON NAME |
| 265 # | 285 # |
| 266 command_datasets_tmpl() { | 286 command_datasets_tmpl() { |
| 267 # parent ZFS dataset -- child ZFS dataset name | 287 # parent ZFS dataset -- child ZFS dataset name |
| 268 local _p_base _p_skel _name | 288 local _p_base _p_skel _name |
| 269 local _ds_base _ds_skel | 289 local _opt_symlink |
| 270 | 290 |
| 271 _ensure_no_options "$@" | 291 local _ds_base _ds_skel _opt |
| 292 | |
| 293 _opt_symlink="" | |
| 294 | |
| 295 while getopts "LP" _opt ; do | |
| 296 case ${_opt} in | |
| 297 L) | |
| 298 _opt_symlink="-L" | |
| 299 ;; | |
| 300 P) | |
| 301 _opt_symlink="-P" | |
| 302 ;; | |
| 303 \?) | |
| 304 return 2; | |
| 305 ;; | |
| 306 esac | |
| 307 done | |
| 308 shift $((OPTIND-1)) | |
| 309 OPTIND=1 | |
| 310 | |
| 311 [ -z "${_opt_symlink}" ] && { echo "ERROR: -L or -P must be given" 1>&2; return 2; } | |
| 272 | 312 |
| 273 _p_base="${1-}" | 313 _p_base="${1-}" |
| 274 _p_skel="${2-}" | 314 _p_skel="${2-}" |
| 275 _name="${3-}" | 315 _name="${3-}" |
| 276 | 316 |
| 277 # Check preconditions | 317 # Check preconditions |
| 278 command_datasets_tmpl_base -n "${_p_base}" "${_name}" || return | 318 command_datasets_tmpl_base -n "${_p_base}" "${_name}" || return |
| 279 command_datasets_tmpl_skel -n "${_p_skel}" "${_name}" || return | 319 command_datasets_tmpl_skel -n ${_opt_symlink} "${_p_skel}" "${_name}" || return |
| 280 | 320 |
| 281 # Really do it | 321 # Really do it |
| 282 command_datasets_tmpl_base "${_p_base}" "${_name}" || return | 322 command_datasets_tmpl_base "${_p_base}" "${_name}" || return |
| 283 command_datasets_tmpl_skel "${_p_skel}" "${_name}" || return | 323 command_datasets_tmpl_skel ${_opt_symlink} "${_p_skel}" "${_name}" || return |
| 284 return 0 | 324 return 0 |
| 285 } | 325 } |
| 286 | 326 |
| 287 | 327 |
| 288 # | 328 # |
