Removing live-snapshot version as this component is always released within live-initr...
[live-boot-grml.git] / bin / live-snapshot
index 141d266..0038c87 100755 (executable)
@@ -2,7 +2,7 @@
 
 # live-snapshot - utility to manage Debian Live systems snapshots
 #
-#   This program mount a device (fallback to /tmpfs under /mnt/snapshot
+#   This program mount a device (fallback to /tmpfs under $MOUNTP
 #   and save the /live/cow (or a different dir) filesystem in it for reusing
 #   in another live-initramfs session. Look at manpage for more info.
 #
@@ -34,9 +34,12 @@ set -eu
 export USERNAME USERFULLNAME HOSTNAME
 
 PROGRAM="$(basename $0)"
-VERSION=0.0.2
 
-MOUNTP="/mnt/live-snapshot"
+# Needs to be available at run and reboot time
+SAFE_TMPDIR="/live"
+
+# Permits multiple runs
+MOUNTP="$(mktemp -d -p ${SAFE_TMPDIR} live-snapshot-mnt.XXXXXX)"
 SNAP_COW="/live/cow"
 SNAP_DEV=""
 DEST="${MOUNTP}/live-sn.cpio.gz"
@@ -96,7 +99,7 @@ Usage ()
 
 Version ()
 {
-       echo "${PROGRAM}, version ${VERSION}"
+       echo "${PROGRAM}"
        echo
        echo "Copyright (C) 2006 Marco Amadori <marco.amadori@gmail.com>"
        echo
@@ -289,10 +292,13 @@ Do_snapshot ()
 {
        case "${SNAP_TYPE}" in
                squashfs)
-                       echo "./tmp/exclude_list" > /tmp/exclude_list
-                       ( cd "${SNAP_COW}" && find . -name '*.wh.*' >> /tmp/exclude_list )
-                       mksquashfs "${SNAP_COW}" "${DEST}" -ef /tmp/exclude_list
-                       rm /tmp/exclude_list
+                       EXCLUDE_LIST="$(mktemp -p ${SAFE_TMPDIR} live-snapshot-exclude-list.XXXXXX)"
+                       echo "./${EXCLUDE_LIST}" > "${EXCLUDE_LIST}"
+                       cd "${SNAP_COW}"
+                       find . -name '*.wh.*' >> "${EXCLUDE_LIST}"
+                       cd "${OLDPWD}"
+                       mksquashfs "${SNAP_COW}" "${DEST}" -ef "${EXCLUDE_LIST}"
+                       rm -f "${EXCLUDE_LIST}"
                        ;;
 
                cpio)
@@ -302,7 +308,7 @@ Do_snapshot ()
                ext2|ext3)
                        DU_DIM="$(du -ks ${SNAP_COW} | cut -f1)"
                        REAL_DIM="$(expr ${DU_DIM} + ${DU_DIM} / 20)" # Just 5% more to be sure, need something more sophistcated here...
-                       genext2fs --size-in-blocks=${REAL_DIM} --reserved-blocks=0 --root="${SNAP_COW}" "${DEST}"
+                       genext2fs --size-in-blocks=${REAL_DIM} --reserved-percentage=0 --root="${SNAP_COW}" "${DEST}"
                        ;;
 
                jffs2)
@@ -313,8 +319,13 @@ Do_snapshot ()
 
 Clean ()
 {
-       umount "${MOUNTP}"
-       rmdir "${MOUNTP}"
+       if echo "${DEST}" | grep -q "${MOUNTP}"
+       then
+               echo "${DEST} is present on ${MOUNTP}, therefore no automatic unmounting the latter." > /dev/null 1>&2
+       else
+               umount "${MOUNTP}"
+               rmdir "${MOUNTP}"
+       fi
 }
 
 Main ()