Removed all "cat | grep", with grep, awk and sed.
[live-boot-grml.git] / scripts / live
index 7e0b100..9c747d5 100755 (executable)
@@ -326,6 +326,15 @@ Arguments ()
                                export PERSISTENT
                                ;;
 
+                       persistent=*)
+                               PERSISTENT="${ARGUMENT#persistent=}"
+                               if [ -z "${PERSISTENT}" ]
+                               then
+                                       PERSISTENT="Yes"
+                               fi
+                               export PERSISTENT
+                               ;;
+
                        nopersistent)
                                NOPERSISTENT="Yes"
                                export NOPERSISTENT
@@ -604,7 +613,7 @@ copy_live_to ()
        if [ "${copytodev}" = "ram" ]
        then
                # copying to ram:
-               freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
+               freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\<Cached/{print $2}' /proc/meminfo ) )
                mount_options="-o size=${size}k"
                free_string="memory"
                fstype="tmpfs"
@@ -837,10 +846,10 @@ do_snap_copy ()
                # look for free mem
                if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
                then
-                       todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
-                       freespace=$(df -k  | grep -s ${todev} | awk '{print $4}')
+                       todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
+                       freespace=$(df -k | awk '/'${todev}'/{print $4}')
                else
-                       freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
+                       freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\<Cached/{print $2}' /proc/meminfo))
                fi
 
                tomount="/mnt/tmpsnap"
@@ -881,7 +890,13 @@ find_snap ()
 {
        # Look for ${snap_label}.* in block devices
        snap_label="${1}"
-       snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3 ${snap_label}.jffs2")
+
+       if [ "${PERSISTENT}" != "nofiles" ]
+       then
+               # search for image files
+               snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3 ${snap_label}.jffs2")
+       fi
+
        if [ -z "${snapdata}" ]
        then
                snapdata=$(find_cow_device "${snap_label}")
@@ -948,7 +963,7 @@ try_snap ()
                        # 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 ' ')
+                       snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
                else
                        snapdev="${dev}"
                fi
@@ -1136,11 +1151,20 @@ setup_unionfs ()
                        # snapshots to be sure to really store some e.g key config files,
                        # but not on the same media
                        blacklistdev="${cowprobe}"
+                       PERSISTENCE_IS_ON="1"
+                       export PERSISTENCE_IS_ON
                fi
                # homecow just mount something on /home, this should be generalized some way
                homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
+               if [ -b "${homecow}" ]
+               then
+                       PERSISTENCE_IS_ON="1"
+                       export PERSISTENCE_IS_ON
+               fi
                root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
-               # This second type should be removed when snapshot grow smarter
+               # This second type should be removed when snapshot will get smarter,
+               # hence when "/etc/live-snapshot*list" will be supported also by
+               # ext2|ext3|jffs2 snapshot types.
                home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
 
                if [ -b "${cowprobe}" ]