Support further checks on loopback image and support skipping union mounts (Closes...
[live-boot-grml.git] / scripts / live
index 9b9a443..d06dd20 100755 (executable)
@@ -109,6 +109,11 @@ Arguments ()
                                export IGNORE_UUID
                                ;;
 
+                       integrity-check)
+                               INTEGRITY_CHECK="Yes"
+                               export INTEGRITY_CHECK
+                               ;;
+
                        ip=*)
                                STATICIP="${ARGUMENT#ip=}"
 
@@ -286,9 +291,9 @@ Arguments ()
                                export NOPROGRAMCRASHES
                                ;;
 
-                       norestrictedmanager)
-                               NORESTRICTEDMANAGER="Yes"
-                               export NORESTRICTEDMANAGER
+                       nojockey)
+                               NOJOCKEY="Yes"
+                               export NOJOCKEY
                                ;;
 
                        nosudo)
@@ -422,6 +427,11 @@ Arguments ()
                                export PLAIN_ROOT
                                ;;
 
+                       skipunion)
+                                SKIP_UNION_MOUNTS="Yes"
+                                export SKIP_UNION_MOUNTS
+                                ;;
+
                        root=*)
                                ROOT="${ARGUMENT#root=}"
                                export ROOT
@@ -570,7 +580,7 @@ mount_images_in_directory ()
                [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
                setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
        else
-               :
+               panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
        fi
 }
 
@@ -658,7 +668,6 @@ copy_live_to ()
                        cp -a ${copyfrom}/* ${copyto}   # "cp -a" from busybox also copies hidden files
                fi
 
-               livefs_root
                umount ${copyfrom}
                mount -r -o move ${copyto} ${copyfrom}
        fi
@@ -692,6 +701,15 @@ do_netmount ()
        [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
        export HOSTNAME
 
+       # Check if we have a network device at all
+       if ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
+          ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
+          ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
+          ! ls /sys/class/net/ra0 > /dev/null 2>&1
+       then
+               panic "No supported network device found, maybe a non-mainline driver is required."
+       fi
+
        if [ "${NFSROOT}" = "auto" ]
        then
                NFSROOT=${ROOTSERVER}:${ROOTPATH}
@@ -799,11 +817,13 @@ do_nfsmount ()
 
        log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
 
-       # FIXME: This for loop is an ugly HACK round an nfs bug
-       for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13
+       # FIXME: This while loop is an ugly HACK round an nfs bug
+       i=0
+       while [ "$i" -lt 60 ]
        do
                nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
                sleep 1
+               i="$(($i + 1))"
        done
 
        return ${rc}
@@ -1070,6 +1090,12 @@ setup_unionfs ()
        do
                imagename=$(basename "${image}")
 
+               export image devname
+               maybe_break live-realpremount
+               log_begin_msg "Running /scripts/live-realpremount"
+               run_scripts /scripts/live-realpremount
+               log_end_msg
+
                if [ -d "${image}" ]
                then
                        # it is a plain directory: do nothing
@@ -1227,8 +1253,12 @@ setup_unionfs ()
                mount --bind ${exposedrootfs} ${rootmnt} || \
                        panic "bind mount of ${exposedrootfs} failed"
 
-               cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool
-                       /home /var/lib/live'
+               if [ -z "${SKIP_UNION_MOUNTS}" ]
+               then
+                       cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
+               else
+                       cow_dirs=''
+               fi
 
                for dir in ${cow_dirs}; do
                        mkdir -p /cow${dir}
@@ -1416,6 +1446,32 @@ set_usplash_timeout ()
        fi ; fi
 }
 
+integrity_check ()
+{
+       media_mountpoint="${1}"
+
+       log_begin_msg "Checking media integrity"
+
+       cd ${media_mountpoint}
+       /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
+       RC="${?}"
+
+       log_end_msg
+
+       if [ "${RC}" -eq 0 ]
+       then
+               log_success_msg "Everything ok, will reboot in 10 seconds."
+               sleep 10
+               cd /
+               umount ${media_mountpoint}
+               sync
+               echo u > /proc/sysrq-trigger
+               echo b > /proc/sysrq-trigger
+       else
+               panic "Not ok, a media defect is likely, switch to VT8 for details."
+       fi
+}
+
 mountroot ()
 {
         if [ -x /scripts/local-top/cryptroot ]; then
@@ -1461,7 +1517,8 @@ mountroot ()
                        livefs_root=${ROOT}
                else
                        # Scan local devices for the image
-                       for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
+                       i=0
+                       while [ "$i" -lt 60 ]
                        do
                                livefs_root=$(find_livefs ${i})
 
@@ -1471,6 +1528,7 @@ mountroot ()
                                fi
 
                                sleep 1
+                               i="$(($i + 1))"
                        done
                fi
        fi
@@ -1480,6 +1538,11 @@ mountroot ()
                panic "Unable to find a medium containing a live file system"
        fi
 
+       if [ "${INTEGRITY_CHECK}" ]
+       then
+               integrity_check "${livefs_root}"
+       fi
+
        if [ "${TORAM}" ]
        then
                live_dest="ram"
@@ -1507,7 +1570,7 @@ mountroot ()
        log_end_msg
 
        maybe_break live-bottom
-       log_begin_msg "Running /scripts/live-bottom"
+       log_begin_msg "Running /scripts/live-bottom\n"
 
        run_scripts /scripts/live-bottom
        log_end_msg