live-snapshot: now supports a static keep file list.
[live-boot-grml.git] / scripts / live
index 46dcb74..e211263 100755 (executable)
@@ -65,6 +65,16 @@ Arguments ()
                                export HOOK
                                ;;
 
+                       ftpfs=*)
+                               FTPFS="${ARGUMENT#ftpfs=}"
+                               export FTPFS
+                               ;;
+
+                       httpfs=*)
+                               HTTPFS="${ARGUMENT#httpfs=}"
+                               export HTTPFS
+                               ;;
+
                        hostname=*)
                                HOSTNAME="${ARGUMENT#hostname=}"
                                LIVECONF="changed"
@@ -154,6 +164,12 @@ Arguments ()
                                export LIVE_MEDIA_TIMEOUT
                                ;;
 
+                       language=*|debian-installer/language=*)
+                               language=${x#debian-installer/language=}
+                               locale="$(lang2locale "$language")"
+                               set_locale="true"
+                               ;;
+
                        locale=*|debian-installer/locale=*)
                                LOCALE="${ARGUMENT#*=}"
                                export LOCALE
@@ -473,7 +489,7 @@ matches_uuid ()
        path="${1}"
        uuid="$(cat /conf/uuid.conf)"
 
-       for try_uuid_file in "${mountpoint}/.disk/casper-uuid"*
+       for try_uuid_file in "${mountpoint}/.disk/live-uuid"*
        do
                [ -e "${try_uuid_file}" ] || continue
 
@@ -492,7 +508,7 @@ get_backing_device ()
 {
        case "${1}" in
                *.squashfs|*.ext2|*.ext3|*.jffs2)
-                       echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
+                       echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
                        ;;
 
                *.dir)
@@ -550,20 +566,6 @@ is_nice_device ()
        return 1
 }
 
-is_supported_fs ()
-{
-       # FIXME: do something better like the scan of supported filesystems
-       fstype="${1}"
-
-       case ${fstype} in
-               vfat|iso9660|udf|ext2|ext3|ntfs|jffs2)
-                       return 0
-                       ;;
-       esac
-
-       return 1
-}
-
 copy_live_to ()
 {
        copyfrom="${1}"
@@ -623,7 +625,7 @@ copy_live_to ()
                cd "${copyto}"
                tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
                rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
-               mount -r --move "${copyto}" "${rootmnt}"
+               mount -r -move "${copyto}" "${rootmnt}"
                cd "${OLDPWD}"
        else
                if [ -n "${MODULETORAMFILE}" ]
@@ -635,7 +637,7 @@ copy_live_to ()
 
                livefs_root
                umount ${copyfrom}
-               mount -r --move ${copyto} ${copyfrom}
+               mount -r -move ${copyto} ${copyfrom}
        fi
 
        rmdir ${copyto}
@@ -664,7 +666,7 @@ do_netmount ()
                NFSROOT=${ROOTSERVER}:${ROOTPATH}
        fi
 
-       if [ -n "${FETCH}" ] && do_httpmount
+       if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) && do_httpmount
        then
                rc=0
                return ${rc}
@@ -694,20 +696,53 @@ do_netmount ()
 do_httpmount ()
 {
        rc=1
-       extension=$(echo "${FETCH}" | sed 's/\(.*\)\.\(.*\)/\2/')
-
-       case "${extension}" in
-               squashfs|tgz|tar)
-                       [ "${quiet}" != "y" ] && log_begin_msg "Trying wget ${FETCH} -O ${mountpoint}/$(basename ${FETCH})"
-                       mkdir -p "${mountpoint}/${LIVE_MEDIA_PATH}"
-                       wget "${FETCH}" -O "${mountpoint}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
-                       [ ${?} -eq 0 ] && rc=0
-                       [ "${extension}" = "tgz" ] && live_dest="ram"
-                       ;;
+       dest="${mountpoint}/${LIVE_MEDIA_PATH}"
+       mount -t ramfs ram "${mountpoint}"
+       mkdir -p "${dest}"
 
-               *)
-                       [ "${quiet}" != "y" ] && log_begin_msg "Unrecognized archive extension for ${FETCH}"
-       esac
+       for webfile in HTTPFS FTPFS FETCH
+       do
+               url="$(eval echo \"\$\{${webfile}\}\")"
+               extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
+
+               if [ -n "$url" ]
+               then
+                       case "${extension}" in
+                               squashfs|tgz|tar)
+                                       if [ "${webfile}" = "FETCH" ]
+                                       then
+                                               [ "${quiet}" != "y" ] &&
+                                                       log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
+                                               wget "${url}" -O "${dest}/$(basename ${url})"
+                                       else
+                                               [ "${quiet}" != "y" ] &&
+                                                       log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
+                                               if [ "${webfile}" = "FTPFS" ]
+                                               then
+                                                       FUSE_MOUNT="curlftpfs"
+                                                       url="$(dirname ${url})"
+                                               else
+                                                       FUSE_MOUNT="httpfs"
+                                               fi
+                                               modprobe fuse
+                                               $FUSE_MOUNT "${url}" "${dest}"
+                                       fi
+                                       [ ${?} -eq 0 ] && rc=0
+                                       [ "${extension}" = "tgz" ] && live_dest="ram"
+                                       break
+                                       ;;
+
+                               *)
+                                       [ "${quiet}" != "y" ] && log_begin_msg "Unrecognized archive extension for ${url}"
+                                       ;;
+                       esac
+               fi
+       done
+
+       if [ ${rc} != 0 ]
+       then
+           umount "${mountpoint}"
+       fi
 
        return ${rc}
 }
@@ -840,7 +875,7 @@ try_snap ()
                        fi
                else
                        # cpio.gz snapshot
-                       if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null)
+                       if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories > /dev/null 2>&1)
                        then
                                log_warning_msg "Impossible to include the ${snapfile} Snapshot"
                                return 1
@@ -973,7 +1008,12 @@ setup_unionfs ()
                        rofslist="${image} ${rofslist}"
                elif [ -f "${image}" ]
                then
-                       backdev=$(get_backing_device "${image}")
+                       if /sbin/losetup --help 2>&1 | grep -q -- "-r\b"
+                       then
+                               backdev=$(get_backing_device "${image}" "-r")
+                       else
+                               backdev=$(get_backing_device "${image}")
+                       fi
                        fstype=$(get_fstype "${backdev}")
 
                        if [ "${fstype}" = "unknown" ]
@@ -1130,7 +1170,7 @@ setup_unionfs ()
                                        ;;
 
                                *)
-                                       mount --move "${d}" "${rootmnt}/live/${d##*/}"
+                                       mount -move "${d}" "${rootmnt}/live/${d##*/}"
                                        ;;
                        esac
                done
@@ -1138,7 +1178,7 @@ setup_unionfs ()
 
        # shows cow fs on /cow for use by live-snapshot
        mkdir -p "${rootmnt}/live/cow"
-       mount -o move /cow "${rootmnt}/live/cow"
+       mount -o move /cow "${rootmnt}/live/cow" || mount -o bind /cow "${rootmnt}/live/cow" || [ "${quiet}" != "y" ] && log_warning_msg "Unable to move or bind /cow to ${rootmnt}/live/cow"
 }
 
 check_dev ()
@@ -1158,6 +1198,19 @@ check_dev ()
                devname="${loopdevname}"
        fi
 
+       if [ -d "${devname}" ]
+       then
+               mount -o bind "${devname}" $mountpoint || continue
+
+               if is_live_path $mountpoint
+               then
+                       echo $mountpoint
+                       return 0
+               else
+                       umount $mountpoint
+               fi
+       fi
+
        fstype=$(get_fstype "${devname}")
 
        if is_supported_fs ${fstype}
@@ -1205,7 +1258,7 @@ find_livefs ()
        fi
 
        # or do the scan of block devices
-       for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram | grep -v 'dm-')
+       for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram | grep -v 'dm-' | grep -v fd )
        do
                devname=$(sys2dev "${sysblock}")
                fstype=$(get_fstype "${devname}")
@@ -1261,6 +1314,8 @@ mountroot ()
        exec 7>&2
        exec > live.log
        exec 2>&1
+       tail -f live.log >&7 &
+       tailpid="${!}"
 
        Arguments
 
@@ -1274,7 +1329,7 @@ mountroot ()
 
        set_usplash_timeout
 
-       if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ]
+       if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
        then
                if do_netmount
                then
@@ -1342,5 +1397,6 @@ mountroot ()
 
        exec 1>&6 6>&-
        exec 2>&7 7>&-
+       kill ${tailpid}
        cp live.log "${rootmnt}/var/log/"
 }