[or-cvs] r11556: Update script that copies to a USB drive to optionally forma (in incognito/trunk: . arch/x86 root_overlay/usr/sbin)

double at seul.org double at seul.org
Fri Sep 21 16:18:17 UTC 2007


Author: double
Date: 2007-09-21 12:18:17 -0400 (Fri, 21 Sep 2007)
New Revision: 11556

Modified:
   incognito/trunk/ChangeLog
   incognito/trunk/arch/x86/livecd-stage1-tiny.spec
   incognito/trunk/arch/x86/livecd-stage1.spec
   incognito/trunk/livecd-stage2.sh
   incognito/trunk/root_overlay/usr/sbin/create-usb
Log:
Update script that copies to a USB drive to optionally format the drive. (from anonym)


Modified: incognito/trunk/ChangeLog
===================================================================
--- incognito/trunk/ChangeLog	2007-09-21 13:59:58 UTC (rev 11555)
+++ incognito/trunk/ChangeLog	2007-09-21 16:18:17 UTC (rev 11556)
@@ -1,12 +1,14 @@
-changes since 20070824.1:
+20070824.2 changes since 20070824.1:
 
 	- Full version CD may be run in a virtual PC. For computers that do
 	not allow booting from media this allows Incognito to run on a Windows
 	x86 platform. Note that keystroke recorders may still be able to
 	capture what you type!
+	- Update script that copies to a USB drive to optionally format the
+	drive. (anonym)
 	- On tiny changed back from dhcp to dhcpcd as it is more robust and
 	some cards drop link status after the initial IP address. Full needs
-	to use dhcp because that is what NetworkManager uses.
+	to use dhcp because that is what NetworkManager requires.
 	- Add video driver fall back to VESA for video cards that are not
 	supported by a card specific driver.
 	- Clean up task bar and background.

Modified: incognito/trunk/arch/x86/livecd-stage1-tiny.spec
===================================================================
--- incognito/trunk/arch/x86/livecd-stage1-tiny.spec	2007-09-21 13:59:58 UTC (rev 11555)
+++ incognito/trunk/arch/x86/livecd-stage1-tiny.spec	2007-09-21 16:18:17 UTC (rev 11556)
@@ -101,6 +101,7 @@
 	sys-apps/hdparm
 	sys-apps/hwsetup
 	sys-apps/netplug
+	sys-fs/dosfstools
 	sys-power/acpid
 	www-client/mozilla-firefox-bin
 	x11-plugins/noscript

Modified: incognito/trunk/arch/x86/livecd-stage1.spec
===================================================================
--- incognito/trunk/arch/x86/livecd-stage1.spec	2007-09-21 13:59:58 UTC (rev 11555)
+++ incognito/trunk/arch/x86/livecd-stage1.spec	2007-09-21 16:18:17 UTC (rev 11556)
@@ -113,6 +113,7 @@
 	sys-apps/memtester
 	sys-apps/netplug
 	sys-fs/lsscsi
+	sys-fs/dosfstools
 	sys-libs/gpm
 	sys-power/acpid
 	www-client/links

Modified: incognito/trunk/livecd-stage2.sh
===================================================================
--- incognito/trunk/livecd-stage2.sh	2007-09-21 13:59:58 UTC (rev 11555)
+++ incognito/trunk/livecd-stage2.sh	2007-09-21 16:18:17 UTC (rev 11556)
@@ -69,9 +69,9 @@
 export INCOGNITO INCOGNITO_TITLE INCOGNITO_VERSION
 
 find "${DIR}" -type f | while read FILE; do
-	sed -i "s/__INCOGNITO__/${INCOGNITO//\//\/}/" "${FILE}"
-	sed -i "s/__INCOGNITO_TITLE__/${INCOGNITO_TITLE//\//\/}/" "${FILE}"
-	sed -i "s/__INCOGNITO_VERSION__/${INCOGNITO_VERSION//\//\/}/" "${FILE}"
+	sed -i "s/__INCOGNITO__/${INCOGNITO//\//\/}/g" "${FILE}"
+	sed -i "s/__INCOGNITO_TITLE__/${INCOGNITO_TITLE//\//\/}/g" "${FILE}"
+	sed -i "s/__INCOGNITO_VERSION__/${INCOGNITO_VERSION//\//\/}/g" "${FILE}"
 done
 
 # Install QEMU

Modified: incognito/trunk/root_overlay/usr/sbin/create-usb
===================================================================
--- incognito/trunk/root_overlay/usr/sbin/create-usb	2007-09-21 13:59:58 UTC (rev 11555)
+++ incognito/trunk/root_overlay/usr/sbin/create-usb	2007-09-21 16:18:17 UTC (rev 11556)
@@ -4,42 +4,79 @@
 # Creates a USB bootable disk from a Gentoo based Live CD
 #
 
-# Required files
-IMAGE="image.squashfs"
-REQUIRED_FILES="isolinux/isolinux.cfg isolinux/vesamenu.c32 isolinux/splash.png isolinux/gentoo isolinux/gentoo.igz ${IMAGE}"
-COPY_FILES="livecd README.txt readme.html isolinux/isolinux.cfg isolinux/vesamenu.c32 isolinux/splash.png isolinux/*.msg isolinux/gentoo isolinux/gentoo.igz ${IMAGE}"
+DEFAULT_WIDTH=80
 
-# Root of the Live CD
-if [[ -z "${MEDIAROOT}" ]]; then
-	MEDIAROOT="/mnt/cdrom"
-fi
+# show an xdialog of available USB drives. the one which the user choses is partitioned into
+# a single big partition. USBPART will stored the new partition and USBDEV the device.
+format_usb() {
+    # Find the mkfs.vfat command
+    MKFS_VFAT="$(which mkfs.vfat 2>/dev/null)"
+    if [[ -z "${MKFS_VFAT}" ]]; then
+	echo "Could not find mkfs.vfat. Install dosfstools."
+	exit 1
+    fi
 
-# Find the dialog command
-DIALOG="$(which Xdialog 2>/dev/null)"
-if [ -z "${DIALOG}" -o -z "${DISPLAY}" ]; then
-	DIALOG="$(which dialog 2>/dev/null)"
-fi
+    I=0
 
-if [[ -z "${DIALOG}" ]]; then
-	echo "Could not find Xdialog or dialog"
+    for DEV in $(ls /sys/block/sd*/dev); do
+        DEV_DIR="$(dirname ${DEV})"
+        ON_USB="$(ls -l ${DEV_DIR}/device | grep -c usb)"
+        REM="$(cat ${DEV_DIR}/removable)"
+        DEV_NODE="$(find /dev -type b | xargs stat --format 'echo %n $(( 0x%t )):$(( 0x%T ))' | bash -s | grep [^0-9]$(<${DEV_DIR}/dev)$ | awk '{ print $1 }')"
+	
+        if [ "${ON_USB}" -eq 1 -a "${REM}" -eq 1 -a -w "${DEV_NODE}" ]; then
+	    DEVICES[$I]="${DEV_NODE}"
+	    SYSPATH[$I]="${DEV_DIR}"
+	    LIST[$I]="$( echo ${DEV_NODE} - $(<${DEV_DIR}/device/vendor) $(<${DEV_DIR}/device/model) $(( $(<${DEV_DIR}/size)/2048 ))MB | tr -s [:space:] )"
+	    echo ${LIST[$I]}
+	    I=$(( ${I}+1 ))
+        fi
+    done
+    
+    # Select USB drive
+    if [[ -z "${LIST}" ]]; then
+	${DIALOG} --msgbox "No usable USB drives detected." 0 ${DEFAULT_WIDTH}
 	exit 1
-fi
+    fi
+    
+    USBDEV="$( ${DIALOG} --stdout --combobox "Please select a USB drive to copy the CD onto. Please note that this process will destroy all data on the selected USB drive, it is your responsibility to ensure any important data is backed up elsewhere." 0 ${DEFAULT_WIDTH} "${LIST}" | awk '{ print $1 }' )"
 
-# Verify availability of LiveCD files
-for FILE in ${REQUIRED_FILES}; do
-	FP="${MEDIAROOT}/${FILE}"
-	if [[ ! -r "${FP}" ]]; then
-		${DIALOG} --msgbox "Required LiveCD file ${FP} not found" 0 0
-		exit 1
-	fi
-done
+    if [[ -z "${USBDEV}" ]]; then
+	${DIALOG} --msgbox "No USB drive selected, exiting" 0 ${DEFAULT_WIDTH}
+	exit 1
+    fi
 
-if [[ -z "${USBPART}" ]]; then
+    # Make a single bootable partition consisting of all available space
+    sfdisk --DOS --no-reread ${USBDEV} << EOF
+0,,0xb,*
+;
+;
+;
+EOF
 
-I=0
+    if [[ $? -ne 0 ]]; then
+	${DIALOG} --msgbox "Could not make USB partition on ${USBDEB}" 0 ${DEFAULT_WIDTH}
+	exit 1
+    fi
+    
+    USBPART="${USBDEV}1"
 
-# Find available USB drives with vfat partitions
-for DEV in $(ls /sys/block/sd*/sd*/dev); do
+    # Format partition as vfat
+    ${MKFS_VFAT} ${USBPART} 
+
+    if [[ $? -ne 0 ]]; then
+	${DIALOG} --msgbox "Formatting of USB partition ${USBPART} to vfat failed" 0 ${DEFAULT_WIDTH}
+	exit 1
+    fi
+}
+
+# show an xdialog of available vfat partitions on attached USB drives. The chosen partition
+# will be stored in USBPART and the device it resides on is stored in USBDEV.
+get_vfat() {
+    I=0
+
+    # Find available USB drives with vfat partitions
+    for DEV in $(ls /sys/block/sd*/sd*/dev); do
 	PART_DIR="$(dirname ${DEV})"
 	DEV_DIR="$(dirname ${PART_DIR})"
 	ON_USB="$(ls -l ${DEV_DIR/device} | grep -c usb)"
@@ -47,113 +84,164 @@
 	DEV_NODE="$(find /dev -type b | xargs stat --format 'echo %n $(( 0x%t )):$(( 0x%T ))' | bash -s | grep [^0-9]$(<${DEV})$ | awk '{ print $1 }')"
 	FSTYPE="$(/lib/udev/vol_id -t ${DEV_NODE})"
 	if [ "${ON_USB}" -eq 1 -a "${REM}" -eq 1 -a -w "${DEV_NODE}" -a "${FSTYPE}" == "vfat" ]; then
-		DEVICES[$I]="${DEV_NODE}"
-		SYSPATH[$I]="${DEV_DIR}"
-		LIST[$I]="$( echo ${DEV_NODE} - $(<${DEV_DIR}/device/vendor) $(<${DEV_DIR}/device/model) $(( $(<${PART_DIR}/size)/2048 ))MB | tr -s [:space:] )"
-		I=$(( ${I}+1 ))
+	    DEVICES[$I]="${DEV_NODE}"
+	    SYSPATH[$I]="${DEV_DIR}"
+	    LIST[$I]="$( echo ${DEV_NODE} - $(<${DEV_DIR}/device/vendor) $(<${DEV_DIR}/device/model) $(( $(<${PART_DIR}/size)/2048 ))MB | tr -s [:space:] )"
+	    I=$(( ${I}+1 ))
 	fi
-done
+    done
 
-# Select USB drive
-if [[ -z "${LIST}" ]]; then
-	${DIALOG} --msgbox "No usable USB drives detected. The USB drive must have at least one Windows (vfat) partition. You may want to try re-formatting the drive." 0 0
+    # Select USB drive
+    if [[ -z "${LIST}" ]]; then
+	${DIALOG} --yesno "No usable USB drives detected. The USB drive must have at least one Windows (vfat) partition. Do you want to re-format the drive? Note that this will remove all data from the USB drive so move any valuable data elsewhere before continuing further." 0 ${DEFAULT_WIDTH}
+	if [ "$?" == 0 ]; then
+	    format_usb
+	    return
+	else
+	    exit 1
+	fi
+    fi
+
+    USBPART="$( ${DIALOG} --stdout --combobox "Please select a USB partition to copy the CD onto. Please note that this process may destroy the data on your USB drive, it is your responsibility to ensure any important data is backed up elsewhere." 9 ${DEFAULT_WIDTH} "${LIST}" | awk '{ print $1 }' )"
+
+    if [[ -z "${USBPART}" ]]; then
+	${DIALOG} --msgbox "No USB drive partition selected, exiting" 0 ${DEFAULT_WIDTH}
 	exit 1
+    fi
+
+    USBDEV="${USBPART/%[0-9]}"
+}
+
+
+# Main script:
+
+# Required files
+IMAGE="image.squashfs"
+REQUIRED_FILES="isolinux/isolinux.cfg isolinux/vesamenu.c32 isolinux/splash.png isolinux/gentoo isolinux/gentoo.igz ${IMAGE}"
+COPY_FILES="livecd README.txt readme.html isolinux/isolinux.cfg isolinux/vesamenu.c32 isolinux/splash.png isolinux/*.msg isolinux/gentoo isolinux/gentoo.igz ${IMAGE}"
+
+# Root of the Live CD
+if [[ -z "${MEDIAROOT}" ]]; then
+    MEDIAROOT="/mnt/cdrom"
 fi
 
-USBPART="$( ${DIALOG} --stdout --combobox "Please select a USB partition to copy the CD onto. Please note that this process may destroy the data on your USB drive, it is your responsibility to ensure any important data is backed up elsewhere." 9 80 "${LIST}" | awk '{ print $1 }' )"
+# Find the dialog command
+DIALOG="$(which Xdialog 2>/dev/null)"
+if [ -z "${DIALOG}" -o -z "${DISPLAY}" ]; then
+    DIALOG="$(which dialog 2>/dev/null)"
+fi
 
+if [[ -z "${DIALOG}" ]]; then
+    echo "Could not find Xdialog or dialog"
+    exit 1
 fi
 
-if [[ -z "${USBPART}" ]]; then
-	${DIALOG} --msgbox "No USB drive selected, exiting" 0 0
+DIALOG="${DIALOG} --wrap --cr-wrap --left"
+
+# Verify availability of LiveCD files
+for FILE in ${REQUIRED_FILES}; do
+    FP="${MEDIAROOT}/${FILE}"
+    if [[ ! -r "${FP}" ]]; then
+	${DIALOG} --msgbox "Required LiveCD file ${FP} not found" 0 ${DEFAULT_WIDTH}
 	exit 1
+    fi
+done
+
+# Choose installation method
+CHOICE=$(${DIALOG} --stdout --radiolist "For this procedure, you have the option to either:\n\n1: Use an existing vfat partition on a USB drive. This requires that you have a USB drive with a Windows (vfat) partition on it. If you already have copied __INCOGNITO__ onto a USB drive and just want to do it again, this is the right choice as any persistant volumes will be preserved. As such, this option should be used if you want to update an existing __INCOGNITO__ USB installation.\n\n2: Format a USB drive. This will destory all partitions on the drive and create a single big Windows (vfat) partition consisting of all available space which __INCOGNITO__ will be copied onto. Note that this will remove all data from the USB drive so backup any valuable data elsewhere before continuing further.\n\nIf you are unsure which option to choose, try with option 1 (Use an existing vfat partition) first and then resort to optoin 2 (Format a USB drive) if that doesn't work." 0 ${DEFAULT_WIDTH} 2 "1" "Use an existing vfat partition on a USB drive" "" "2" "Format a USB drive" "" )
+
+if [ "${CHOICE}" == "1" ]; then
+    get_vfat
+elif [ "${CHOICE}" == "2" ]; then
+    format_usb
+else
+    exit 0
 fi
 
-USBDEV="${USBPART/%[0-9]}"
-
 # Mount the drive
 MTPT="/mnt/createusb-mp"
 mkdir -p ${MTPT}
 mount -v -t vfat "${USBPART}" "${MTPT}"
 if [[ $? -ne 0 ]]; then
-	${DIALOG} --msgbox "Could not mount USB partition ${USBPART}" 0 0
-	exit 1
+    ${DIALOG} --msgbox "Could not mount USB partition ${USBPART}" 0 ${DEFAULT_WIDTH}
+    exit 1
 fi
 
 # Verify free space
 MEDIAFREE="$(df -k -P "${MTPT}" | tail -n 1 | awk '{ print $4 }')"
 # Account for files that will be overwritten
 for FILE in ${COPY_FILES}; do
-	for FP in $(ls ${MTPT}/$(basename ${FILE}) 2>/dev/null); do
-		MEDIAFREE=$(( ${MEDIAFREE}+$(stat --format=%s ${FP})/1024 ))
-	done
+    for FP in $(ls ${MTPT}/$(basename ${FILE}) 2>/dev/null); do
+	MEDIAFREE=$(( ${MEDIAFREE}+$(stat --format=%s ${FP})/1024 ))
+    done
 done
 # Decrement by space of files to copy
 for FILE in ${COPY_FILES}; do
-	for FP in $(ls ${MEDIAROOT}/${FILE} 2>/dev/null); do
-		MEDIAFREE=$(( ${MEDIAFREE}-$(stat --format=%s ${FP})/1024 ))
-	done
+    for FP in $(ls ${MEDIAROOT}/${FILE} 2>/dev/null); do
+	MEDIAFREE=$(( ${MEDIAFREE}-$(stat --format=%s ${FP})/1024 ))
+    done
 done
 
 echo "Free space of ${MEDIAFREE}k"
 
 if [[ ${MEDIAFREE} -lt 128 ]]; then
-	${DIALOG} --msgbox "Not enough free space on USB partition ${USBPART}, need $(( 128-${MEDIAFREE} ))k" 0 0
-	umount -v "${MTPT}"
-	exit 1
+    ${DIALOG} --msgbox "Not enough free space on USB partition ${USBPART}, need $(( 128-${MEDIAFREE} ))k" 0 ${DEFAULT_WIDTH}
+    umount -v "${MTPT}"
+    exit 1
 fi
 
 # Copy files
 TOTAL=8
 CURRENT=0
 for FILE in ${COPY_FILES}; do
-	FP="${MEDIAROOT}/${FILE}"
-	if [[ -r "${FP}" ]]; then
-		cp -v "${FP}" "${MTPT}/$(basename ${FILE//isolinux/syslinux})"
-	else
-		cp -v ${FP} "${MTPT}"
-	fi
-	ERR=$?
-	if [[ $? -ne 0 ]]; then
-		echo "cp gave error ${ERR}" >&2
-		${DIALOG} --msgbox "Could not copy file ${FILE} to USB drive" 0 0
-		umount -v "${MTPT}"
-		rmdir "${MTPT}"
-		export FAILED=1
-		exit 1
-	fi
-	echo $(( (${CURRENT}*100)/${TOTAL} ))
-	CURRENT=$(( ${CURRENT}+1 ))
-done | ${DIALOG} --progress "Copying files" 0 0
+    FP="${MEDIAROOT}/${FILE}"
+    if [[ -r "${FP}" ]]; then
+	cp -v "${FP}" "${MTPT}/$(basename ${FILE//isolinux/syslinux})"
+    else
+	cp -v ${FP} "${MTPT}"
+    fi
+    ERR=$?
+    if [[ $? -ne 0 ]]; then
+	echo "cp gave error ${ERR}" >&2
+	${DIALOG} --msgbox "Could not copy file ${FILE} to USB drive" 0 ${DEFAULT_WIDTH}
+	umount -v "${MTPT}"
+	rmdir "${MTPT}"
+	export FAILED=1
+	exit 1
+    fi
+    echo $(( (${CURRENT}*100)/${TOTAL} ))
+    CURRENT=$(( ${CURRENT}+1 ))
+done | ${DIALOG} --progress "Copying files" 0 ${DEFAULT_WIDTH}
 
 if [[ "${FAILED}" -eq 1 ]]; then
-	exit 1
+    exit 1
 fi
 
 # Unmount the drive
-( echo 90 ; echo 90 ; umount -v "${MTPT}" ) | ${DIALOG} --progress "Completing USB file copy" 0 0
+( echo 90 ; echo 90 ; umount -v "${MTPT}" ) | ${DIALOG} --progress "Completing USB file copy" 0 ${DEFAULT_WIDTH}
 rmdir "${MTPT}"
 
 # Make bootable
 sfdisk "${USBDEV}" "-A${USBPART/${USBDEV}/}"
 if [[ $? -ne 0 ]]; then
-	${DIALOG} --msgbox "Could not make USB partition ${USBPART} bootable (sfdisk)" 0 0
-	exit 1
+    ${DIALOG} --msgbox "Could not make USB partition ${USBPART} bootable (sfdisk)" 0 ${DEFAULT_WIDTH}
+    exit 1
 fi
 
 dd if=/usr/lib/syslinux/mbr.bin "of=${USBDEV}"
 if [[ $? -ne 0 ]]; then
-	${DIALOG} --msgbox "Could not copy Master Boot Record to USB drive ${USBDEV} (dd)" 0 0
-	exit 1
+    ${DIALOG} --msgbox "Could not copy Master Boot Record to USB drive ${USBDEV} (dd)" 0 ${DEFAULT_WIDTH}
+    exit 1
 fi
 
 syslinux "${USBPART}"
 if [[ $? -ne 0 ]]; then
-	${DIALOG} --msgbox "Could not setup boot loader on USB partition ${USBPART} (syslinux)" 0 0
-	exit 1
+    ${DIALOG} --msgbox "Could not setup boot loader on USB partition ${USBPART} (syslinux)" 0 ${DEFAULT_WIDTH}
+    exit 1
 fi
 
 # Success!
 
-${DIALOG} --msgbox "Bootable USB drive successfully created" 0 0
+${DIALOG} --msgbox "Bootable USB drive successfully created" 0 ${DEFAULT_WIDTH}
 
+exit 0



More information about the tor-commits mailing list