Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
comparison sbin/ftjail @ 557:3afebbaf613b
ftjail: mounting and unmounting in freebsd-update now handles spaces in devices/datasets and mountpoints properly.
Fully supported only if textproc/jq is installed.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 11 Sep 2024 13:43:09 +0200 |
| parents | a593dce19f54 |
| children | d173161a3a0f |
comparison
equal
deleted
inserted
replaced
| 556:a593dce19f54 | 557:3afebbaf613b |
|---|---|
| 871 #: | 871 #: |
| 872 command_freebsd_update() { | 872 command_freebsd_update() { |
| 873 local _directory _new_origin _etcupdate_tarball | 873 local _directory _new_origin _etcupdate_tarball |
| 874 local _opt_keep _opt_old_origin | 874 local _opt_keep _opt_old_origin |
| 875 | 875 |
| 876 local _res _jailname _dir_mounts _dir_fn_fstab _dir_basename _dir_fn_tldir | 876 local _res _jailname _dir_mounts _dir_fn_fstab _dir_fn_fstab2 |
| 877 local _dir_basename _dir_fn_tldir | |
| 877 local _root_dataset _root_mountpoint _root_type _root_options | 878 local _root_dataset _root_mountpoint _root_type _root_options |
| 878 local _clone_extra_props _canmount_prop | 879 local _clone_extra_props _canmount_prop |
| 879 local _line _opt | 880 local _line _opt |
| 880 local _root_readonly _root_origin | 881 local _root_readonly _root_origin |
| 881 local _u_tmpdir | 882 local _u_tmpdir |
| 989 # start with "ro," | 990 # start with "ro," |
| 990 # _root_origin="$(zfs list -H -o origin "${_root_dataset}")" | 991 # _root_origin="$(zfs list -H -o origin "${_root_dataset}")" |
| 991 | 992 |
| 992 _u_tmpdir="$(env TMPDIR=/var/tmp mktemp -d -t ftjail_${_dir_basename})" | 993 _u_tmpdir="$(env TMPDIR=/var/tmp mktemp -d -t ftjail_${_dir_basename})" |
| 993 [ -z "${_u_tmpdir}" ] && { echo "ERROR: cannot create unique temp dir" 1>&2; return 1; } | 994 [ -z "${_u_tmpdir}" ] && { echo "ERROR: cannot create unique temp dir" 1>&2; return 1; } |
| 995 # The fstab that is corrently mounted at relevant locations (normalized) | |
| 994 _dir_fn_fstab="${_u_tmpdir}/fstab" | 996 _dir_fn_fstab="${_u_tmpdir}/fstab" |
| 995 # | 997 # The very same fstab -- but with spaces replaced by \040 |
| 996 # XXX FIXME: handle spaces in device and mountpoint names: replace | 998 _dir_fn_fstab2="${_u_tmpdir}/fstab2" |
| 997 # with a literal `\040'. Note that ${_dir_mounts} is | |
| 998 # normalized already: it uses TAB characters as field | |
| 999 # separator exclusively. | |
| 1000 # | |
| 1001 printf '%s' "${_dir_mounts}" >"${_dir_fn_fstab}" | 999 printf '%s' "${_dir_mounts}" >"${_dir_fn_fstab}" |
| 1000 # Replace all spaces with a sequence that is understood by mount | |
| 1001 LC_ALL=C /usr/bin/sed -e 's/ /\\040/g' <"${_dir_fn_fstab}" >"${_dir_fn_fstab2}" | |
| 1002 _dir_fn_tldir="${_u_tmpdir}/tldirs" | 1002 _dir_fn_tldir="${_u_tmpdir}/tldirs" |
| 1003 LC_ALL=C /usr/bin/find "${_directory}" -depth 1 -type d 2>/dev/null | LC_ALL=C /usr/bin/sort >>"${_dir_fn_tldir}" | 1003 LC_ALL=C /usr/bin/find "${_directory}" -depth 1 -type d 2>/dev/null | LC_ALL=C /usr/bin/sort >>"${_dir_fn_tldir}" |
| 1004 | 1004 |
| 1005 # Unmount in reverse order: unmount can do it for us | 1005 # Unmount in reverse order: unmount can do it for us |
| 1006 echo "Unmounting all datasets mounted at \`${_directory}'" | 1006 echo "Unmounting all datasets mounted at \`${_directory}'" |
| 1007 /sbin/umount -a -F "${_dir_fn_fstab}" -v | 1007 /sbin/umount -a -F "${_dir_fn_fstab2}" -v |
| 1008 | 1008 |
| 1009 # | 1009 # |
| 1010 # XXX TBD: Hooks to create some new top-level dirs (/srv /proc et | 1010 # XXX TBD: Hooks to create some new top-level dirs (/srv /proc et |
| 1011 # al.) if needed: clone RW, mount, make the dirs, | 1011 # al.) if needed: clone RW, mount, make the dirs, |
| 1012 # umount, make the clone RO and continue "normally" by | 1012 # umount, make the clone RO and continue "normally" by |
| 1075 fi | 1075 fi |
| 1076 | 1076 |
| 1077 # Mount again | 1077 # Mount again |
| 1078 echo "Mounting all datasets rooted at \`${_directory}'" | 1078 echo "Mounting all datasets rooted at \`${_directory}'" |
| 1079 [ ! -d "${_directory}" ] && mkdir "${_directory}" | 1079 [ ! -d "${_directory}" ] && mkdir "${_directory}" |
| 1080 /sbin/mount -a -F "${_dir_fn_fstab}" -v | 1080 /sbin/mount -a -F "${_dir_fn_fstab2}" -v |
| 1081 | 1081 |
| 1082 # Update and/or merge configs | 1082 # Update and/or merge configs |
| 1083 if [ -n "${_etcupdate_tarball}" ]; then | 1083 if [ -n "${_etcupdate_tarball}" ]; then |
| 1084 echo "Calling etcupdate for DESTDIR=${_directory}" | 1084 echo "Calling etcupdate for DESTDIR=${_directory}" |
| 1085 etcupdate -D "${_directory}" -t "${_etcupdate_tarball}" | 1085 etcupdate -D "${_directory}" -t "${_etcupdate_tarball}" |
