[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r14653: Fixed an issue that prevented all files from being copied by (incognito/trunk/root_overlay/usr/sbin)
Author: anonym
Date: 2008-05-17 09:16:10 -0400 (Sat, 17 May 2008)
New Revision: 14653
Modified:
incognito/trunk/root_overlay/usr/sbin/create-usb
Log:
Fixed an issue that prevented all files from being copied by the USB copying
script, introduced in the previous revision.
Modified: incognito/trunk/root_overlay/usr/sbin/create-usb
===================================================================
--- incognito/trunk/root_overlay/usr/sbin/create-usb 2008-05-17 13:14:14 UTC (rev 14652)
+++ incognito/trunk/root_overlay/usr/sbin/create-usb 2008-05-17 13:16:10 UTC (rev 14653)
@@ -33,7 +33,6 @@
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
@@ -52,7 +51,7 @@
fi
# Make a single bootable partition consisting of all available space
- sfdisk --DOS --no-reread ${USBDEV} << EOF
+ sfdisk --DOS --no-reread ${USBDEV} &> /dev/null << EOF
0,,0xb,*
;
;
@@ -67,7 +66,7 @@
USBPART="${USBDEV}1"
# Format partition as vfat
- ${MKFS_VFAT} ${USBPART}
+ ${MKFS_VFAT} ${USBPART} &> /dev/null
if [[ $? -ne 0 ]]; then
${DIALOG} --msgbox "Formatting of USB partition ${USBPART} to vfat failed" 0 ${DEFAULT_WIDTH}
@@ -123,43 +122,48 @@
USBDEV="${USBPART/%[0-9]}"
}
+# Parameter 1 is a file, Parameter 2 is the block size in bytes. Writes the
+# number of blocks the file occupy into BLOCKS.
+calc_blocks() {
+ local FILE=$1
+ local BLOCK_SIZE=$2
+ local SIZE=$( stat --format=%s ${FILE} )
+ BLOCKS=0
+ let "BLOCKS = (SIZE + BLOCK_SIZE - 1)/BLOCK_SIZE"
+}
+
# Copies the file with path equal to the first parameter to the file with path
# equal to the second paramter. When a 1MB block has been copied (or block of
# less than 1MB if it's the last one) a dot (.) is written, which can be used
# by Xdialog. Upon error, ERR will be set to 1, otherwise 0.
-file_copy() {
- SRC=$1
- DST=$2
+copy_file() {
+ local SRC=$1
+ local DST=$2
+ local BLOCK_SIZE=$(( 1024*1024 ))
ERR=0
- # Size of source file and the block size, in bytes
- SIZE=$( stat --format=%s $SRC )
- BLOCK_SIZE=$(( 1024*1024 ))
-
- # The number of blocks, accounting for the last block even if smaller
- # than BLOCK_SIZE.
- BLOCKS=$(( (${SIZE}+${BLOCK_SIZE}-1)/${BLOCK_SIZE} ))
-
# Make sure permissions are OK
- if [[ -r ${SRC} ]]; then
- if [[ -e ${DST} ]]; then
- if [[ -w ${DST} ]]; then
- rm $DST
- else
- ERR=1
- return
- fi
- fi
- else
+ if [[ ! -r ${SRC} ]]; then
ERR=1
return
fi
+ if [[ -e ${DST} ]]; then
+ if [[ -w ${DST} ]]; then
+ rm ${DST}
+ else
+ ERR=1
+ return
+ fi
+ fi
+ touch ${DST}
+
+ calc_blocks ${SRC} ${BLOCK_SIZE}
+
# Copy the file, one block at a time
for i in $(seq 0 1 $(( ${BLOCKS} - 1 ))); do
dd if=${SRC} of=${DST} oflag=append conv=notrunc \
seek=${i} skip=${i} bs=${BLOCK_SIZE}c count=1 &> /dev/null
- sync
echo -n "."
done
@@ -226,16 +230,13 @@
# Mount the drive
MTPT="$(mktemp -t -d incognitoXXXXXXXX)"
-mkdir -p ${MTPT}
-mount -v -t vfat "${USBPART}" "${MTPT}"
+mkdir -p ${MTPT} 2> /dev/null
+mount -t vfat "${USBPART}" "${MTPT}"
if [[ $? -ne 0 ]]; then
${DIALOG} --msgbox "Could not mount USB partition ${USBPART}" 0 ${DEFAULT_WIDTH}
exit 1
fi
-# Maximum capacity in KB
-TOTALSIZE="$(df -k -P "${MTPT}" | tail -n 1 | awk '{ print $2 }')"
-
# Verify free space in KB
MEDIAFREE="$(df -k -P "${MTPT}" | tail -n 1 | awk '{ print $4 }')"
# Account for files that will be overwritten
@@ -264,44 +265,50 @@
mkdir -p "${MTPT}/${DIR}" 2>/dev/null
done
-# Size of files to copy in MB
-COPY_SIZE=$(( (${TOTALSIZE}-${MEDIAFREE})/1024 ))
+# Total number of 1MB blocks required to copy all files.
+COPY_BLOCKS=0
+for FILE in ${COPY_FILES}; do
+ calc_blocks ${MEDIAROOT}/${FILE} $(( 1024*1024 ))
+ let "COPY_BLOCKS += BLOCKS"
+done
-# Copy files and show progress (note that the progress is approximate, and the
-# the number of dots file_copy probably are greater than COPY_SIZE)
+# Copy files and show progress. copy_file will output one dot for each 1MB
+# block copied, used by Xdialog --progress
ERR=0
for FILE in ${COPY_FILES}; do
- FP="${MEDIAROOT}/${FILE}"
- file_copy "${FP}" "${MTPT}/${FILE//isolinux/syslinux}"
- if [[ ${ERR} -ne 0 ]]; then
- echo "Error copying file ${FP} to ${MTPT}/${FILE//isolinux/syslinux}" >&2
+ SRC="${MEDIAROOT}/${FILE}"
+ DST="${MTPT}/${FILE//isolinux/syslinux}"
+ copy_file "${SRC}" "${DST}"
+ sync
+ if [[ ${ERR} == 1 ]]; then
+ echo "Error copying file ${SRC} to ${DST}" >&2
${DIALOG} --msgbox "Could not copy file ${FILE} to USB drive" 0 ${DEFAULT_WIDTH}
umount -v "${MTPT}"
rmdir "${MTPT}"
exit 1
fi
-done | ${DIALOG} --progress "Copying files" 0 ${DEFAULT_WIDTH} ${COPY_SIZE}
+done | ${DIALOG} --progress "Copying files" 0 ${DEFAULT_WIDTH} ${COPY_BLOCKS}
# Unmount the drive
-umount -v "${MTPT}"
+umount "${MTPT}"
rmdir "${MTPT}"
# Make bootable
-sfdisk "${USBDEV}" "-A${USBPART/${USBDEV}/}"
+sfdisk "${USBDEV}" "-A${USBPART/${USBDEV}/}" 2> /dev/null
if [[ $? -ne 0 ]]; then
${DIALOG} --msgbox "Could not make USB partition ${USBPART} bootable (sfdisk)" 0 ${DEFAULT_WIDTH}
exit 1
fi
# Copy syslinux MBR
-dd if=/usr/lib/syslinux/mbr.bin "of=${USBDEV}"
+dd if=/usr/lib/syslinux/mbr.bin "of=${USBDEV}" 2> /dev/null
if [[ $? -ne 0 ]]; then
${DIALOG} --msgbox "Could not copy Master Boot Record to USB drive ${USBDEV} (dd)" 0 ${DEFAULT_WIDTH}
exit 1
fi
# Install syslinux
-syslinux "${USBPART}"
+syslinux "${USBPART}" 2> /dev/null
if [[ $? -ne 0 ]]; then
${DIALOG} --msgbox "Could not setup boot loader on USB partition ${USBPART} (syslinux)" 0 ${DEFAULT_WIDTH}
exit 1