[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r15667: The USB creation script now excludes the device Incognito is (incognito/trunk/root_overlay/usr/sbin)



Author: anonym
Date: 2008-07-05 11:03:09 -0400 (Sat, 05 Jul 2008)
New Revision: 15667

Modified:
   incognito/trunk/root_overlay/usr/sbin/create-usb
Log:
The USB creation script now excludes the device Incognito is running from.
Also fixed a bug when running Incognito from USB.


Modified: incognito/trunk/root_overlay/usr/sbin/create-usb
===================================================================
--- incognito/trunk/root_overlay/usr/sbin/create-usb	2008-07-05 14:59:54 UTC (rev 15666)
+++ incognito/trunk/root_overlay/usr/sbin/create-usb	2008-07-05 15:03:09 UTC (rev 15667)
@@ -1,4 +1,4 @@
-#!/bin/sh
+	#!/bin/sh
 
 #
 # Creates a USB bootable disk from a Gentoo based Live CD
@@ -6,6 +6,12 @@
 
 DEFAULT_WIDTH=80
 
+# Root of the LiveCD
+MEDIAROOT="/mnt/cdrom"
+
+# Determine the device of the LiveCD. We assume only deviced hd? and sd?.
+MEDIADEV=$( basename $( mount | grep ${MEDIAROOT | cut -d ' ' -f 1 ) | cut -b 1-3 )
+
 # Show an Xdialog of available USB drives. The one which the user choses is
 # partitioned into a single big partition. USBPART will stored the path to
 # the new partition and USBDEV the path to the device.
@@ -20,7 +26,13 @@
     I=0
 
     for DEV in $(ls /sys/block/sd*/dev) ${OTHER_BLOCK:+$(ls /sys/block/hd*/dev)}; do
-        DEV_DIR="$(dirname ${DEV})"
+
+	# Exclude the device we run from 
+	if echo ${DEV} | grep -q ${MEDIADEV}; then
+		continue;
+	fi
+	
+	DEV_DIR="$(dirname ${DEV})"
 	if [[ -z "${OTHER_BLOCK}" ]]; then
 	        ON_USB="$(ls -l ${DEV_DIR}/device | grep -c usb)"
 	        REM="$(cat ${DEV_DIR}/removable)"
@@ -50,6 +62,17 @@
 	exit 1
     fi
 
+    # If the device is mounted, we need to unmount it
+    if mount | grep -q ${USBDEV}; then
+    	for X in $( mount | grep ${USBDEV} | cut -d ' ' -f 1 ); do
+    		umount ${X} &> /dev/null
+    		if [[ $? != 0 ]]; then
+    			${DIALOG} --msgbox "One or more partitions of the chosen device (${USBDEV}) are mounted but couldn't be unmounted. It is required that the device is unmounted so you will have to unmount these manually. One way to do this is to physically remove and re-insert the media, but make sure not to mount any of the device's partitions before re-running this script." 0 ${DEFAULT_WIDTH}
+    			exit 1
+    		fi
+    	done
+    fi
+
     # Make a single bootable partition consisting of all available space
     sfdisk --DOS --no-reread ${USBDEV} &> /dev/null << EOF
 0,,0xb,*
@@ -82,6 +105,12 @@
 
     # Find available USB drives with vfat partitions
     for DEV in $(ls /sys/block/sd*/sd*/dev) ${OTHER_BLOCK:+$(ls /sys/block/hd*/hd*/dev)}; do
+
+	# Exclude partitions from the device we run from
+	if echo ${DEV} | grep -q ${MEDIADEV}; then
+		continue;
+	fi
+
 	PART_DIR="$(dirname ${DEV})"
 	DEV_DIR="$(dirname ${PART_DIR})"
 	if [[ -z "${OTHER_BLOCK}" ]]; then
@@ -173,10 +202,6 @@
 
 # Main script:
 
-# Root of the Live CD
-if [[ -z "${MEDIAROOT}" ]]; then
-    MEDIAROOT="/mnt/cdrom"
-fi
 
 # Determine isolinux/syslinux config directory
 if [[ -d "${MEDIAROOT}/syslinux" ]]; then
@@ -190,7 +215,7 @@
 
 # Required files (relative path from cd root)
 IMAGE="image.squashfs"
-REQUIRED_FILES="${SYSLINUX}/isolinux.cfg ${SYSLINUX}/vesamenu.c32 ${SYSLINUX}/splash.png ${SYSLINUX}/gentoo ${SYSLINUX}/gentoo.igz ${IMAGE}"
+REQUIRED_FILES="${SYSLINUX}/${SYSLINUX}.cfg ${SYSLINUX}/vesamenu.c32 ${SYSLINUX}/splash.png ${SYSLINUX}/gentoo ${SYSLINUX}/gentoo.igz ${IMAGE}"
 EXCLUDE="System.map-gentoo|isolinux.bin|boot.cat|kernels.msg"
 COPY_FILES=$( find ${MEDIAROOT} ! -type d | egrep -v "$EXCLUDE" | sed "s|${MEDIAROOT}/||g" )
 DIRS=$( find ${MEDIAROOT} -type d | egrep -v "$EXCLUDE" | sed "s|${MEDIAROOT}||g" | sed "s|isolinux|syslinux|g" )