Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
comparison sbin/ftjail @ 532:c615279bb797
Call mount and umount with absolute paths
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 05 Sep 2024 04:05:33 +0200 |
| parents | aae67d3011b4 |
| children | 62cd970aea9c |
comparison
equal
deleted
inserted
replaced
| 531:07a916bd830c | 532:c615279bb797 |
|---|---|
| 449 echo "Would mount ${_name} on ${_real_mp}" | 449 echo "Would mount ${_name} on ${_real_mp}" |
| 450 else | 450 else |
| 451 mkdir -p "${_real_mp}" 1> /dev/null 2> /dev/null || \ | 451 mkdir -p "${_real_mp}" 1> /dev/null 2> /dev/null || \ |
| 452 { echo "ERROR: cannot create mountpoint ${_real_mp}" 1>&2; return 1; } | 452 { echo "ERROR: cannot create mountpoint ${_real_mp}" 1>&2; return 1; } |
| 453 echo "Mounting ${_name} on ${_real_mp}" | 453 echo "Mounting ${_name} on ${_real_mp}" |
| 454 mount -t zfs "${_name}" "${_real_mp}" || return 1 | 454 /sbin/mount -t zfs "${_name}" "${_real_mp}" || return 1 |
| 455 fi | 455 fi |
| 456 fi | 456 fi |
| 457 ;; | 457 ;; |
| 458 *) | 458 *) |
| 459 echo "Skipping ${_name} because its configured ZFS mountpoint is not relative to given root dataset" 1>&2 | 459 echo "Skipping ${_name} because its configured ZFS mountpoint is not relative to given root dataset" 1>&2 |
| 535 | 535 |
| 536 # Just determine whether the given dataset name exists | 536 # Just determine whether the given dataset name exists |
| 537 _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}")" || \ | 537 _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}")" || \ |
| 538 { echo "ERROR: dataset not found" >&2; return 1; } | 538 { echo "ERROR: dataset not found" >&2; return 1; } |
| 539 | 539 |
| 540 mount -t zfs -p \ | 540 /sbin/mount -t zfs -p \ |
| 541 | grep -E "^${_dsname}(/|\s)" \ | 541 | grep -E "^${_dsname}(/|\s)" \ |
| 542 | sort -n -r \ | 542 | sort -n -r \ |
| 543 | { | 543 | { |
| 544 while IFS=' '$'\t' read -r _name _mp _rest ; do | 544 while IFS=' '$'\t' read -r _name _mp _rest ; do |
| 545 echo "Umounting ${_name} on ${_mp}" | 545 echo "Umounting ${_name} on ${_mp}" |
| 546 umount "${_mp}" || return 1 | 546 /sbin/umount "${_mp}" || return 1 |
| 547 done | 547 done |
| 548 return 0 | 548 return 0 |
| 549 } | 549 } |
| 550 } | 550 } |
| 551 | 551 |
| 991 _dir_fn_tldir="${_u_tmpdir}/tldirs" | 991 _dir_fn_tldir="${_u_tmpdir}/tldirs" |
| 992 find "${_directory}" -depth 1 -type d 2>/dev/null | sort >>"${_dir_fn_tldir}" | 992 find "${_directory}" -depth 1 -type d 2>/dev/null | sort >>"${_dir_fn_tldir}" |
| 993 | 993 |
| 994 # Unmount in reverse order: unmount can do it for us | 994 # Unmount in reverse order: unmount can do it for us |
| 995 echo "Unmounting all datasets mounted at \`${_directory}'" | 995 echo "Unmounting all datasets mounted at \`${_directory}'" |
| 996 umount -a -F "${_dir_fn_fstab}" -v | 996 /sbin/umount -a -F "${_dir_fn_fstab}" -v |
| 997 | 997 |
| 998 # | 998 # |
| 999 # XXX TBD: Hooks to create some new top-level dirs (/srv /proc et | 999 # XXX TBD: Hooks to create some new top-level dirs (/srv /proc et |
| 1000 # al.) if needed: clone RW, mount, make the dirs, | 1000 # al.) if needed: clone RW, mount, make the dirs, |
| 1001 # umount, make the clone RO and continue "normally" by | 1001 # umount, make the clone RO and continue "normally" by |
| 1019 # property. So in scripts to be sure to unmount and re-mount | 1019 # property. So in scripts to be sure to unmount and re-mount |
| 1020 # at the same location always use "mount -t zfs". | 1020 # at the same location always use "mount -t zfs". |
| 1021 # | 1021 # |
| 1022 echo "Remounting only the root dataset at \`${_directory}'" | 1022 echo "Remounting only the root dataset at \`${_directory}'" |
| 1023 [ ! -d "${_directory}" ] && mkdir "${_directory}" | 1023 [ ! -d "${_directory}" ] && mkdir "${_directory}" |
| 1024 mount -t zfs "${_root_dataset}" "${_directory}" | 1024 /sbin/mount -t zfs "${_root_dataset}" "${_directory}" |
| 1025 # | 1025 # |
| 1026 # Re-create all currently missing top-level dirs (aka mountpoint) | 1026 # Re-create all currently missing top-level dirs (aka mountpoint) |
| 1027 # in the new clone. Most probably they serve as mountpoints for other | 1027 # in the new clone. Most probably they serve as mountpoints for other |
| 1028 # datasets. | 1028 # datasets. |
| 1029 # | 1029 # |
| 1040 mkdir "${_line}" | 1040 mkdir "${_line}" |
| 1041 fi | 1041 fi |
| 1042 done | 1042 done |
| 1043 } | 1043 } |
| 1044 echo "Unmounting the new root dataset" | 1044 echo "Unmounting the new root dataset" |
| 1045 umount "${_directory}" | 1045 /sbin/umount "${_directory}" |
| 1046 echo "Re-setting some ZFS properties on the new cloned dataset" | 1046 echo "Re-setting some ZFS properties on the new cloned dataset" |
| 1047 zfs set readonly=on "${_root_dataset}" | 1047 zfs set readonly=on "${_root_dataset}" |
| 1048 # | 1048 # |
| 1049 # Copy "canmount" properly last because it has been set to "noauto" | 1049 # Copy "canmount" properly last because it has been set to "noauto" |
| 1050 # temporarily. | 1050 # temporarily. |
| 1064 fi | 1064 fi |
| 1065 | 1065 |
| 1066 # Mount again | 1066 # Mount again |
| 1067 echo "Mounting all datasets rooted at \`${_directory}'" | 1067 echo "Mounting all datasets rooted at \`${_directory}'" |
| 1068 [ ! -d "${_directory}" ] && mkdir "${_directory}" | 1068 [ ! -d "${_directory}" ] && mkdir "${_directory}" |
| 1069 mount -a -F "${_dir_fn_fstab}" -v | 1069 /sbin/mount -a -F "${_dir_fn_fstab}" -v |
| 1070 | 1070 |
| 1071 # Update and/or merge configs | 1071 # Update and/or merge configs |
| 1072 if [ -n "${_etcupdate_tarball}" ]; then | 1072 if [ -n "${_etcupdate_tarball}" ]; then |
| 1073 echo "Calling etcupdate for DESTDIR=${_directory}" | 1073 echo "Calling etcupdate for DESTDIR=${_directory}" |
| 1074 etcupdate -D "${_directory}" -t "${_etcupdate_tarball}" | 1074 etcupdate -D "${_directory}" -t "${_etcupdate_tarball}" |
