Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
comparison sbin/ftjail @ 242:59e933b81dcf
First attemt to populate base and skeleton using the "skeleton" subdir and symliks from base to RW skeleton subdirs
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 10 Sep 2022 14:26:04 +0200 |
| parents | acf16a85900f |
| children | d3fa59e2c5fe |
comparison
equal
deleted
inserted
replaced
| 241:acf16a85900f | 242:59e933b81dcf |
|---|---|
| 47 -u Alias of -n | 47 -u Alias of -n |
| 48 | 48 |
| 49 umount-tmpl BASE-RO SKELETON_RW | 49 umount-tmpl BASE-RO SKELETON_RW |
| 50 | 50 |
| 51 Unmount mounted datasets BASE-RO and SKELETON-RW | 51 Unmount mounted datasets BASE-RO and SKELETON-RW |
| 52 | |
| 53 interlink-tmpl MOUNTPOINT | |
| 54 | |
| 55 Create symbolic links between the RO base and the RW skeleton. | |
| 56 Base and skeleton must be canonically mounted already. | |
| 57 | |
| 58 populate MOUNTPOINT BASETXZ | |
| 59 | |
| 60 Populate the directory in MOUNTPOINT with the base system in BASETXZ | |
| 52 | 61 |
| 53 ENVIRONMENT: | 62 ENVIRONMENT: |
| 54 | 63 |
| 55 All environment variables that affect "zfs" are effective also. | 64 All environment variables that affect "zfs" are effective also. |
| 56 | 65 |
| 226 return 0 | 235 return 0 |
| 227 } | 236 } |
| 228 | 237 |
| 229 | 238 |
| 230 # | 239 # |
| 231 # "populate" -- populate the datasets with content from a FreeBSD base.txz | 240 # "populate-tmpl" -- populate the datasets with content from a FreeBSD base.txz |
| 232 # | 241 # |
| 233 # command_populate mountpoint basetxz | 242 # command_populate_tmpl mountpoint basetxz |
| 234 # | 243 # |
| 235 command_populate() { | 244 command_populate_tmpl() { |
| 236 # MOUNTPOINT -- base.txz | 245 # MOUNTPOINT -- base.txz |
| 237 local _mp _basetxz | 246 local _mp _basetxz |
| 238 | 247 |
| 239 _mp="$1" | 248 local _dir |
| 240 _basetxz="$2" | 249 |
| 250 _mp="${1-}" | |
| 251 _basetxz="${2-}" | |
| 241 | 252 |
| 242 if [ -z "${_mp}" ]; then | 253 if [ -z "${_mp}" ]; then |
| 243 echo "ERROR: no mountpoint given" >&2 | 254 echo "ERROR: no mountpoint given" >&2 |
| 244 return 2 | 255 return 2 |
| 245 fi | 256 fi |
| 258 | 269 |
| 259 # | 270 # |
| 260 # Handle /var/empty separately later: could be already there and | 271 # Handle /var/empty separately later: could be already there and |
| 261 # mounted read-only. | 272 # mounted read-only. |
| 262 # | 273 # |
| 263 tar -C "${_mp}" --exclude=./var/empty -xJp -f "${_basetxz}" || { echo "ERROR: tar encountered errors" >&2; return 1; } | 274 echo "Extracting RO base ..." |
| 264 if [ -d "${_mp}/var/empty" ]; then | 275 tar -C "${_mp}" --exclude=./etc --exclude=./root --exclude=./tmp --exclude=./usr/local --exclude=./var --no-safe-writes -xJp -f "${_basetxz}" || return |
| 265 # | 276 # "home" is not part of base |
| 266 # If /var/empty exists already try to extract with changing the | 277 for _dir in etc root tmp usr/local var ; do |
| 267 # flags (e.g. `schg'). But be ignore errors here. | 278 echo "Extracting RW skeleton: ${_dir} ..." |
| 268 # | 279 tar -C "${_mp}/skeleton" --include="./${_dir}" --exclude=./root/.cshrc --exclude=./root/.profile -xJp -f "${_basetxz}" || return |
| 269 tar -C "${_mp}" -xJp -f "${_basetxz}" ./var/empty || { echo "tar warnings for handling ./var/empty ignored because ./var/empty exists already" >&2; } | 280 done |
| 270 else | 281 # In the original archive they are archived as hardlinks: make symlinks here |
| 271 # Just extract /var/empty normally | 282 (cd "${_mp}/skeleton/root" && ln -s ../../.profile .profile) || return |
| 272 tar -C "${_mp}" -xJp -f "${_basetxz}" ./var/empty || { echo "ERROR: tar encountered errors" >&2; return 1; } | 283 (cd "${_mp}/skeleton/root" && ln -s ../../.cshrc .cshrc) || return |
| 273 fi | 284 |
| 274 | 285 find "${_mp}/boot" -type f -delete || true |
| 275 find "${_mp}/boot" -type f -delete | |
| 276 } | 286 } |
| 277 | 287 |
| 278 | 288 |
| 279 # | 289 # |
| 280 # _do_mount dataset mountpoint dry-run mount-natural | 290 # _do_mount dataset mountpoint dry-run mount-natural |
| 458 [ -z "${_ds_skel}" ] && { echo "ERROR: no RW skeleton dataset given" >&2; return 2; } | 468 [ -z "${_ds_skel}" ] && { echo "ERROR: no RW skeleton dataset given" >&2; return 2; } |
| 459 | 469 |
| 460 _do_umount "${_ds_skel}" || return | 470 _do_umount "${_ds_skel}" || return |
| 461 _do_umount "${_ds_base}" || return | 471 _do_umount "${_ds_base}" || return |
| 462 | 472 |
| 473 return 0 | |
| 474 } | |
| 475 | |
| 476 | |
| 477 # | |
| 478 # "interlink-tmpl" -- create links from base to skeleton | |
| 479 # | |
| 480 # command_interlink_tmpl mountpint | |
| 481 # | |
| 482 command_interlink_tmpl() { | |
| 483 local _mountpoint | |
| 484 | |
| 485 local _dir _dirpart _basepart | |
| 486 | |
| 487 _mountpoint="${1-}" | |
| 488 | |
| 489 [ -z "${_mountpoint}" ] && { echo "ERROR: no mountpoint given" 2>&1; return 2; } | |
| 490 [ -d "${_mountpoint}" ] || { echo "ERROR: mountpoint \`${_mountpoint}' does not exist" 2>&1; return 1; } | |
| 491 [ -d "${_mountpoint}/skeleton" ] || { echo "WARNING: skeleton is not mounted at \`${_mountpoint}/skeleton'" 2>&1; } | |
| 492 | |
| 493 for _dir in etc home root tmp usr/local var ; do | |
| 494 case "${_dir}" in | |
| 495 "usr/local") | |
| 496 _dirpart="$(dirname "${_dir}")" | |
| 497 _basepart="$(basename "${_dir}")" | |
| 498 [ -d "${_mountpoint}/${_dirpart}" ] || mkdir "${_mountpoint}/${_dirpart}" || return | |
| 499 ( cd "${_mountpoint}/${_dirpart}" && ln -s "../skeleton/${_dir}" "${_basepart}" ) || return | |
| 500 ;; | |
| 501 *) | |
| 502 ( cd "${_mountpoint}" && ln -s "skeleton/${_dir}" "${_dir}" ) || return | |
| 503 ;; | |
| 504 esac | |
| 505 done | |
| 463 return 0 | 506 return 0 |
| 464 } | 507 } |
| 465 | 508 |
| 466 | 509 |
| 467 # | 510 # |
| 507 command_mount_tmpl "$@" | 550 command_mount_tmpl "$@" |
| 508 ;; | 551 ;; |
| 509 umount-tmpl|unmount-tmpl) | 552 umount-tmpl|unmount-tmpl) |
| 510 command_umount_tmpl "$@" | 553 command_umount_tmpl "$@" |
| 511 ;; | 554 ;; |
| 512 populate) | 555 interlink-tmpl) |
| 513 command_populate "$@" | 556 command_interlink_tmpl "$@" |
| 557 ;; | |
| 558 populate-tmpl) | |
| 559 command_populate_tmpl "$@" | |
| 514 ;; | 560 ;; |
| 515 *) | 561 *) |
| 516 echo "ERROR: unknown command \`${command}'" >&2 | 562 echo "ERROR: unknown command \`${command}'" >&2 |
| 517 exit 2 | 563 exit 2 |
| 518 ;; | 564 ;; |
