comparison sbin/ftjail @ 819:8f144f4e8441 v0.29.1

FIX: farray_tryget_XXX_at_index() does not exist any more: use the new "cookie" functions instead
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 19 Jan 2025 15:30:47 +0100
parents e2f262ec2bf4
children
comparison
equal deleted inserted replaced
818:31d5d152126c 819:8f144f4e8441
909 local _directory _new_origin _etcupdate_tarball 909 local _directory _new_origin _etcupdate_tarball
910 local _dir_basename _dir_mounts _jailname _running_jailname 910 local _dir_basename _dir_mounts _jailname _running_jailname
911 local _tmp _line _log_sock 911 local _tmp _line _log_sock
912 local _root_dataset _root_mountpoint _root_type _root_options 912 local _root_dataset _root_mountpoint _root_type _root_options
913 local _mnt_device _mnt_mountpoint _mnt_type _mnt_options 913 local _mnt_device _mnt_mountpoint _mnt_type _mnt_options
914 local _idx _sn_ds _sn_name _sn_ds_related 914 local _acookie _sn_ds _sn_name _sn_ds_related
915 local _etcupdate_status 915 local _etcupdate_status
916 916
917 _rc=0 917 _rc=0
918 918
919 _warnings='' 919 _warnings=''
972 if [ -n "${_etcupdate_tarball}" ]; then 972 if [ -n "${_etcupdate_tarball}" ]; then
973 [ -r "${_etcupdate_tarball}" ] || farray_append _errors "given etcupdate tarball does not exist and/or is not readable" 973 [ -r "${_etcupdate_tarball}" ] || farray_append _errors "given etcupdate tarball does not exist and/or is not readable"
974 fi 974 fi
975 975
976 # Check snapshotting 976 # Check snapshotting
977 _idx=1 977 _acookie="$(falist_cookie_first _opt_snapshots)"
978 while falist_tryget_item_at_index _sn_ds _sn_name _opt_snapshots ${_idx}; do 978 while falist_tryget_item_at _sn_ds _sn_name "${_acookie}"; do
979 if zfs get -H -o value name "${_sn_ds}" >/dev/null 2>/dev/null; then 979 if zfs get -H -o value name "${_sn_ds}" >/dev/null 2>/dev/null; then
980 # yes dataset exists: check that snapshots do not exist 980 # yes dataset exists: check that snapshots do not exist
981 while IFS=$'\t' read -r _line; do 981 while IFS=$'\t' read -r _line; do
982 if zfs get -H -o value name "${_line}@${_sn_name}" >/dev/null 2>/dev/null; then 982 if zfs get -H -o value name "${_line}@${_sn_name}" >/dev/null 2>/dev/null; then
983 farray_append _errors "snapshot \`${_line}@${_sn_name}' already exists" 983 farray_append _errors "snapshot \`${_line}@${_sn_name}' already exists"
986 $(zfs list -H -r -o name "${_sn_ds}") 986 $(zfs list -H -r -o name "${_sn_ds}")
987 EOF2988ee715b2d93fd93bdce23 987 EOF2988ee715b2d93fd93bdce23
988 else 988 else
989 farray_append _errors "dataset for snapshots \`${_sn_ds}' does not exist" 989 farray_append _errors "dataset for snapshots \`${_sn_ds}' does not exist"
990 fi 990 fi
991 _idx=$((_idx + 1)) 991 _acookie="$(falist_cookie_next "${_acookie}")"
992 done 992 done
993 993
994 _jailname='' 994 _jailname=''
995 _running_jailname='' 995 _running_jailname=''
996 if [ -n "${_directory}" ]; then 996 if [ -n "${_directory}" ]; then
1077 ;; 1077 ;;
1078 *) 1078 *)
1079 true 1079 true
1080 ;; 1080 ;;
1081 esac 1081 esac
1082 _idx=1 1082 _acookie="$(falist_cookie_first _opt_snapshots)"
1083 while falist_tryget_key_at_index _sn_ds _opt_snapshots ${_idx}; do 1083 while falist_tryget_key_at _sn_ds "${_acookie}"; do
1084 case "${_mnt_device}" in 1084 case "${_mnt_device}" in
1085 "${_sn_ds}") 1085 "${_sn_ds}")
1086 _sn_ds_related="yes" 1086 _sn_ds_related="yes"
1087 ;; 1087 ;;
1088 "${_sn_ds}"/*) 1088 "${_sn_ds}"/*)
1089 _sn_ds_related="yes" 1089 _sn_ds_related="yes"
1090 ;; 1090 ;;
1091 *) 1091 *)
1092 ;; 1092 ;;
1093 esac 1093 esac
1094 _idx=$((_idx + 1)) 1094 _acookie="$(falist_cookie_next "${_acookie}")"
1095 done 1095 done
1096 done <<EOF4tHGCAASL775f9f320205 1096 done <<EOF4tHGCAASL775f9f320205
1097 ${_dir_mounts} 1097 ${_dir_mounts}
1098 EOF4tHGCAASL775f9f320205 1098 EOF4tHGCAASL775f9f320205
1099 fi 1099 fi
1143 1143
1144 local _res _jailname _dir_mounts _dir_fn_fstab _dir_fn_fstab2 1144 local _res _jailname _dir_mounts _dir_fn_fstab _dir_fn_fstab2
1145 local _dir_basename _dir_fn_tldir 1145 local _dir_basename _dir_fn_tldir
1146 local _root_dataset _root_mountpoint _root_type _root_options 1146 local _root_dataset _root_mountpoint _root_type _root_options
1147 local _mnt_device _mnt_mountpoint _mnt_type _mnt_options 1147 local _mnt_device _mnt_mountpoint _mnt_type _mnt_options
1148 local _idx _sn_ds _sn_name 1148 local _acookie _sn_ds _sn_name
1149 local _clone_extra_props _canmount_prop 1149 local _clone_extra_props _canmount_prop
1150 local _line _opt 1150 local _line _opt
1151 local _root_readonly _root_origin 1151 local _root_readonly _root_origin
1152 local _u_tmpdir 1152 local _u_tmpdir
1153 local _add_log_sock 1153 local _add_log_sock
1199 if [ -n "${_etcupdate_tarball}" ]; then 1199 if [ -n "${_etcupdate_tarball}" ]; then
1200 [ -r "${_etcupdate_tarball}" ] || { echo "ERROR: given etcupdate tarball does not exist and/or is not readable" 1>&2; return 1; } 1200 [ -r "${_etcupdate_tarball}" ] || { echo "ERROR: given etcupdate tarball does not exist and/or is not readable" 1>&2; return 1; }
1201 fi 1201 fi
1202 1202
1203 # Check snapshotting 1203 # Check snapshotting
1204 _idx=1 1204 _acookie="$(falist_cookie_first _opt_snapshots)"
1205 while falist_tryget_item_at_index _sn_ds _sn_name _opt_snapshots ${_idx}; do 1205 while falist_tryget_item_at _sn_ds _sn_name "${_acookie}"; do
1206 if zfs get -H -o value name "${_sn_ds}" >/dev/null 2>/dev/null; then 1206 if zfs get -H -o value name "${_sn_ds}" >/dev/null 2>/dev/null; then
1207 # yes dataset exists: check that snapshots do not exist 1207 # yes dataset exists: check that snapshots do not exist
1208 while IFS=$'\t' read -r _line; do 1208 while IFS=$'\t' read -r _line; do
1209 if zfs get -H -o value name "${_line}@${_sn_name}" >/dev/null 2>/dev/null; then 1209 if zfs get -H -o value name "${_line}@${_sn_name}" >/dev/null 2>/dev/null; then
1210 err "snapshot \`${_line}@${_sn_name}' already exists" 1210 err "snapshot \`${_line}@${_sn_name}' already exists"
1215 EOF2988ee715b2d93fd93bdce23 1215 EOF2988ee715b2d93fd93bdce23
1216 else 1216 else
1217 err "dataset for snapshots \`${_sn_ds}' does not exist" 1217 err "dataset for snapshots \`${_sn_ds}' does not exist"
1218 return 1 1218 return 1
1219 fi 1219 fi
1220 _idx=$((_idx + 1)) 1220 _acookie="$(falist_cookie_next "${_acookie}")"
1221 done 1221 done
1222 1222
1223 _dir_basename="$(basename "${_directory}")" 1223 _dir_basename="$(basename "${_directory}")"
1224 1224
1225 set +e 1225 set +e
1329 # Replace all spaces with a sequence that is understood by mount 1329 # Replace all spaces with a sequence that is understood by mount
1330 LC_ALL=C /usr/bin/sed -e 's/ /\\040/g' <"${_dir_fn_fstab}" >"${_dir_fn_fstab2}" 1330 LC_ALL=C /usr/bin/sed -e 's/ /\\040/g' <"${_dir_fn_fstab}" >"${_dir_fn_fstab2}"
1331 _dir_fn_tldir="${_u_tmpdir}/tldirs" 1331 _dir_fn_tldir="${_u_tmpdir}/tldirs"
1332 LC_ALL=C /usr/bin/find "${_directory}" -depth 1 -type d 2>/dev/null | LC_ALL=C /usr/bin/sort >>"${_dir_fn_tldir}" 1332 LC_ALL=C /usr/bin/find "${_directory}" -depth 1 -type d 2>/dev/null | LC_ALL=C /usr/bin/sort >>"${_dir_fn_tldir}"
1333 1333
1334 _idx=1 1334 _acookie="$(falist_cookie_first _opt_snapshots)"
1335 while falist_tryget_item_at_index _sn_ds _sn_name _opt_snapshots ${_idx}; do 1335 while falist_tryget_item_at _sn_ds _sn_name "${_acookie}"; do
1336 echo "Creating snapshot \`${_sn_ds}@${_sn_name}'" 1336 echo "Creating snapshot \`${_sn_ds}@${_sn_name}'"
1337 zfs snapshot -r "${_sn_ds}@${_sn_name}" || { err "cannot snapshot \`${_sn_ds}@${_sn_name}'"; return 1; } 1337 zfs snapshot -r "${_sn_ds}@${_sn_name}" || { err "cannot snapshot \`${_sn_ds}@${_sn_name}'"; return 1; }
1338 _idx=$((_idx + 1)) 1338 _acookie="$(falist_cookie_next "${_acookie}")"
1339 done 1339 done
1340 1340
1341 # Unmount in reverse order: unmount can do it for us 1341 # Unmount in reverse order: unmount can do it for us
1342 echo "Unmounting all datasets mounted at \`${_directory}'" 1342 echo "Unmounting all datasets mounted at \`${_directory}'"
1343 /sbin/umount -a -F "${_dir_fn_fstab2}" -v 1343 /sbin/umount -a -F "${_dir_fn_fstab2}" -v