Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
comparison sbin/ftjail @ 256:68f091c9524a
Command "copy-skel" implemented
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 12 Sep 2022 09:40:20 +0200 |
| parents | 39268cba8c46 |
| children | dde5967d1e43 |
comparison
equal
deleted
inserted
replaced
| 255:7f21d242f79f | 256:68f091c9524a |
|---|---|
| 68 | 68 |
| 69 -L Populate having a "skeleton" subdirectory within the mountpoint | 69 -L Populate having a "skeleton" subdirectory within the mountpoint |
| 70 -P Populate directly into the mountpoint | 70 -P Populate directly into the mountpoint |
| 71 | 71 |
| 72 snapshot-tmpl BASE-RO SKELETON-RW SNAPSHOT-NAME | 72 snapshot-tmpl BASE-RO SKELETON-RW SNAPSHOT-NAME |
| 73 | |
| 74 copy-skel [ OPTIONS ] SOURCE-DS SNAPSHOT-NAME TARGET-DS | |
| 75 | |
| 76 -A Set "canmount=noauto" for all datasets in the target dataset | |
| 77 -L Copy dataset properties optimized for employing a | |
| 78 "skeleton" subdirectory | |
| 79 -P Copy dataset properties optimized for direct mounts | |
| 80 of skeleton children over an already mounted base | |
| 81 -u Do not mount the target dataset automatically | |
| 73 | 82 |
| 74 ENVIRONMENT: | 83 ENVIRONMENT: |
| 75 | 84 |
| 76 All environment variables that affect "zfs" are effective also. | 85 All environment variables that affect "zfs" are effective also. |
| 77 | 86 |
| 240 | 249 |
| 241 if [ "${_opt_symlink}" = "yes" ]; then | 250 if [ "${_opt_symlink}" = "yes" ]; then |
| 242 # In this case the skeleton root needs to be mounted into a "skeleton" subdir | 251 # In this case the skeleton root needs to be mounted into a "skeleton" subdir |
| 243 zfs create -u -o canmount=noauto "${_ds_skel}" | 252 zfs create -u -o canmount=noauto "${_ds_skel}" |
| 244 else | 253 else |
| 245 # Only childres are to be mounted | 254 # Only children are to be mounted |
| 246 zfs create -u -o canmount=off "${_ds_skel}" | 255 zfs create -u -o canmount=off "${_ds_skel}" |
| 247 fi | 256 fi |
| 257 # "usr" is only a container holding "usr/local" | |
| 248 zfs create -u -o canmount=off "${_ds_skel}/usr" | 258 zfs create -u -o canmount=off "${_ds_skel}/usr" |
| 249 # | 259 # |
| 250 # XXX FIXME: What about usr/ports/distfiles | 260 # XXX FIXME: What about usr/ports/distfiles |
| 251 # We typically want to use binary packages. | 261 # We typically want to use binary packages. |
| 252 # And if we use ports they are not in usr/ports typically. | 262 # And if we use ports they are not in usr/ports typically. |
| 687 [ -z "${_ds_skel}" ] && { echo "ERROR: no RW skeleton dataset name given" 1>&2; return 2; } | 697 [ -z "${_ds_skel}" ] && { echo "ERROR: no RW skeleton dataset name given" 1>&2; return 2; } |
| 688 | 698 |
| 689 _do_snapshot "${_ds_base}" "${_snap_name}" || return | 699 _do_snapshot "${_ds_base}" "${_snap_name}" || return |
| 690 _do_snapshot "${_ds_skel}" "${_snap_name}" || return | 700 _do_snapshot "${_ds_skel}" "${_snap_name}" || return |
| 691 return 0 | 701 return 0 |
| 702 } | |
| 703 | |
| 704 | |
| 705 #: | |
| 706 #: Implementation of "copy-skel" | |
| 707 #: | |
| 708 command_copy_skel() { | |
| 709 local _ds_source _snapshot_name _ds_target | |
| 710 local _opt_symlink _opt_nomount | |
| 711 | |
| 712 local _opt _name _relative_name _opt_canmount | |
| 713 | |
| 714 _opt_symlink="" | |
| 715 _opt_nomount="" | |
| 716 _opt_canmount="-o canmount=on" | |
| 717 | |
| 718 | |
| 719 while getopts "ALPu" _opt ; do | |
| 720 case ${_opt} in | |
| 721 A) | |
| 722 _opt_canmount="-o canmount=noauto" | |
| 723 ;; | |
| 724 L) | |
| 725 _opt_symlink="yes" | |
| 726 ;; | |
| 727 P) | |
| 728 _opt_symlink="no" | |
| 729 ;; | |
| 730 u) | |
| 731 _opt_nomount="-u" | |
| 732 ;; | |
| 733 \?) | |
| 734 return 2; | |
| 735 ;; | |
| 736 esac | |
| 737 done | |
| 738 shift $((OPTIND-1)) | |
| 739 OPTIND=1 | |
| 740 | |
| 741 [ -z "${_opt_symlink}" ] && { echo "ERROR: -L or -P must be given" 1>&2; return 2; } | |
| 742 | |
| 743 _ds_source="${1-}" | |
| 744 _snapshot_name="${2-}" | |
| 745 _ds_target="${3-}" | |
| 746 | |
| 747 [ -z "${_ds_source}" ] && { echo "ERROR: no source given" 1>&2; return 2; } | |
| 748 [ -z "${_snapshot_name}" ] && { echo "ERROR: no snapshot name given" 1>&2; return 2; } | |
| 749 [ -z "${_ds_target}" ] && { echo "ERROR: no target given" 1>&2; return 2; } | |
| 750 | |
| 751 zfs list -r -t all -o name "${_ds_source}" \ | |
| 752 | { | |
| 753 while IFS=$'\t' read -r _name ; do | |
| 754 if [ "${_name}" = "${_name%@*}@${_snapshot_name}" ]; then | |
| 755 echo "FOUND: $_name" | |
| 756 # Determine the relative name of the dataset | |
| 757 _relative_name="${_name#${_ds_source}}" | |
| 758 _relative_name="${_relative_name%@*}" | |
| 759 echo " -> $_relative_name" | |
| 760 if [ -z "${_relative_name}" ]; then | |
| 761 # root | |
| 762 if [ "${_opt_symlink}" = "yes" ]; then | |
| 763 zfs send -Lec -p -v "${_name}" | zfs receive ${_opt_nomount} -v ${_opt_canmount} -x mountpoint "${_ds_target}${_relative_name}" | |
| 764 else | |
| 765 zfs send -Lec -p -v "${_name}" | zfs receive ${_opt_nomount} -v -o canmount=off -x mountpoint "${_ds_target}${_relative_name}" | |
| 766 fi | |
| 767 else | |
| 768 # child | |
| 769 if [ "${_relative_name}" = "/usr" ]; then | |
| 770 zfs send -Lec -p -v "${_name}" | zfs receive ${_opt_nomount} -v -o canmount=off -x mountpoint "${_ds_target}${_relative_name}" | |
| 771 else | |
| 772 zfs send -Lec -p -v "${_name}" | zfs receive ${_opt_nomount} -v ${_opt_canmount} -x mountpoint "${_ds_target}${_relative_name}" | |
| 773 fi | |
| 774 fi | |
| 775 fi | |
| 776 done | |
| 777 } | |
| 778 # Need only the filesystem data (no associated snapshots) | |
| 779 echo "Destroying unneeded snapshots ..." | |
| 780 zfs destroy -rv "${_ds_target}@${_snapshot_name}" | |
| 692 } | 781 } |
| 693 | 782 |
| 694 | 783 |
| 695 # | 784 # |
| 696 # Global option handling | 785 # Global option handling |
| 744 command_populate_tmpl "$@" | 833 command_populate_tmpl "$@" |
| 745 ;; | 834 ;; |
| 746 snapshot-tmpl) | 835 snapshot-tmpl) |
| 747 command_snapshot_tmpl "$@" | 836 command_snapshot_tmpl "$@" |
| 748 ;; | 837 ;; |
| 838 copy-skel) | |
| 839 command_copy_skel "$@" | |
| 840 ;; | |
| 749 configure) | 841 configure) |
| 750 echo "ERROR: use \`fjail configure' instead" 1>&2; | 842 echo "ERROR: use \`fjail configure' instead" 1>&2; |
| 751 exit 2 | 843 exit 2 |
| 752 ;; | 844 ;; |
| 753 *) | 845 *) |
