- # Look for $snap_label.* in block devices and copy the contents to $snap_mount
- # and remember the device and filename for resync on exit in live-initramfs.init
-
- snap_label="${1}"
- snap_mount="${2}"
- snap_type="${3}"
-
- snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
- if [ ! -z "${snapdata}" ]; then
- snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
- snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
- snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
- if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'; then
- # squashfs or ext2/ext3 snapshot
- dev=$(get_backing_device "${snapback}/${snapfile}")
- if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
- log_warning_msg "Impossible to include the ${snapfile} Snapshot"
- return 1
- fi
- else
- # cpio.gz snapshot
- if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
- log_warning_msg "Impossible to include the ${snapfile} Snapshot"
- return 1
- fi
- fi
- umount "${snapback}"
- else
- dev=$(find_cow_device "${snap_label}")
- if [ -b ${dev} ]; then
- if echo "${dev}" | grep -qs loop; then
- # strange things happens, user confused?
- snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
- snapfile=$(basename ${snaploop})
- snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
- else
- snapdev="${dev}"
- fi
- if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
- log_warning_msg "Impossible to include the ${snap_label} Snapshot"
- return 1
- else
- if [ -n "${snapfile}" ]; then
- # it was a loop device, user confused
- umount ${snapdev}
- fi
- fi
- else
- log_warning_msg "Impossible to include the ${snap_label} Snapshot"
- return 1
- fi
- fi
- echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
- return 0
+ # Look for ${snap_label}.* in block devices and copy the contents to ${snap_mount}
+ # and remember the device and filename for resync on exit in live-initramfs.init
+
+ snap_label="${1}"
+ snap_mount="${2}"
+ snap_type="${3}"
+ snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
+
+ if [ ! -z "${snapdata}" ]
+ then
+ snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
+ snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
+ snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
+
+ if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'
+ then
+ # squashfs or ext2/ext3 snapshot
+ dev=$(get_backing_device "${snapback}/${snapfile}")
+
+ if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
+ then
+ log_warning_msg "Impossible to include the ${snapfile} Snapshot"
+ return 1
+ fi
+ else
+ # cpio.gz snapshot
+ if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null)
+ then
+ log_warning_msg "Impossible to include the ${snapfile} Snapshot"
+ return 1
+ fi
+ fi
+
+ umount "${snapback}"
+ else
+ dev=$(find_cow_device "${snap_label}")
+
+ if [ -b ${dev} ]
+ then
+ if echo "${dev}" | grep -qs loop
+ then
+ # strange things happens, user confused?
+ snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
+ snapfile=$(basename ${snaploop})
+ snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
+ else
+ snapdev="${dev}"
+ fi
+
+ if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
+ then
+ log_warning_msg "Impossible to include the ${snap_label} Snapshot"
+ return 1
+ else
+ if [ -n "${snapfile}" ]
+ then
+ # it was a loop device, user confused
+ umount ${snapdev}
+ fi
+ fi
+ else
+ log_warning_msg "Impossible to include the ${snap_label} Snapshot"
+ return 1
+ fi
+ fi
+
+ echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
+ return 0