Enable image_to_usb to be run from outside the scripts directory.

Review URL: http://chromereview.prom.corp.google.com/1180043


git-svn-id: svn://chrome-svn/chromeos/trunk@154 06c00378-0e64-4dae-be16-12b19f9950a1
This commit is contained in:
tedbo@google.com 2009-11-04 03:23:20 +00:00
parent 3bfc11f2fe
commit 182c45ee72

View File

@ -17,7 +17,7 @@ DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`"
# Script can be run either inside or outside the chroot. # Script can be run either inside or outside the chroot.
if [ $INSIDE_CHROOT -eq 1 ] if [ $INSIDE_CHROOT -eq 1 ]
then then
# Inside the chroot, so output to usb.img in the same dir as the other # Inside the chroot, so output to usb.img in the same dir as the other
# images. # images.
DEFAULT_TO="${DEFAULT_FROM}/usb.img" DEFAULT_TO="${DEFAULT_FROM}/usb.img"
DEFAULT_TO_HELP="Destination file for USB image." DEFAULT_TO_HELP="Destination file for USB image."
@ -40,7 +40,7 @@ eval set -- "${FLAGS_ARGV}"
# Die on any errors. # Die on any errors.
set -e set -e
# Convert args to paths. Need eval to un-quote the string so that shell # Convert args to paths. Need eval to un-quote the string so that shell
# chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work.
FLAGS_from=`eval readlink -f $FLAGS_from` FLAGS_from=`eval readlink -f $FLAGS_from`
FLAGS_to=`eval readlink -f $FLAGS_to` FLAGS_to=`eval readlink -f $FLAGS_to`
@ -68,19 +68,21 @@ then
exit 1 exit 1
fi fi
fi fi
echo "attempting to unmount any mounts on the USB device" echo "attempting to unmount any mounts on the USB device"
for i in "$FLAGS_to"* for i in "$FLAGS_to"*
do do
! sudo umount "$i" ! sudo umount "$i"
done done
sleep 3 sleep 3
PART_SIZE=$(stat -c%s "${FLAGS_from}/rootfs.image") # Bytes PART_SIZE=$(stat -c%s "${FLAGS_from}/rootfs.image") # Bytes
echo "Copying root fs..." echo "Copying root fs..."
sudo ./file_copy.py if="${FLAGS_from}/rootfs.image" of="$FLAGS_to" bs=4M \ sudo "${SCRIPTS_DIR}"/file_copy.py \
seek_bytes=$(( ($PART_SIZE * 2) + 512 )) if="${FLAGS_from}/rootfs.image" \
of="$FLAGS_to" bs=4M \
seek_bytes=$(( ($PART_SIZE * 2) + 512 ))
# Set up loop device # Set up loop device
LOOP_DEV=$(sudo losetup -f) LOOP_DEV=$(sudo losetup -f)
@ -89,7 +91,7 @@ then
echo "No free loop device. Free up a loop device or reboot. exiting." echo "No free loop device. Free up a loop device or reboot. exiting."
exit 1 exit 1
fi fi
trap do_cleanup EXIT trap do_cleanup EXIT
echo "Creating stateful partition..." echo "Creating stateful partition..."
@ -98,11 +100,12 @@ then
sync sync
sudo losetup -d "$LOOP_DEV" sudo losetup -d "$LOOP_DEV"
sync sync
trap - EXIT trap - EXIT
echo "Copying MBR..." echo "Copying MBR..."
sudo ./file_copy.py if="${FLAGS_from}/mbr.image" of="$FLAGS_to" sudo "${SCRIPTS_DIR}"/file_copy.py \
if="${FLAGS_from}/mbr.image" of="$FLAGS_to"
sync sync
echo "Done." echo "Done."
else else
@ -114,7 +117,7 @@ else
dd if=/dev/zero of="${FLAGS_from}/stateful_partition.image" bs=1 count=1 \ dd if=/dev/zero of="${FLAGS_from}/stateful_partition.image" bs=1 count=1 \
seek=$(($PART_SIZE - 1)) seek=$(($PART_SIZE - 1))
mkfs.ext3 -F -L C-STATE "${FLAGS_from}/stateful_partition.image" mkfs.ext3 -F -L C-STATE "${FLAGS_from}/stateful_partition.image"
# Create a sparse output file # Create a sparse output file
dd if=/dev/zero of="${FLAGS_to}" bs=1 count=1 \ dd if=/dev/zero of="${FLAGS_to}" bs=1 count=1 \
seek=$(( ($PART_SIZE * 2) + 512 - 1)) seek=$(( ($PART_SIZE * 2) + 512 - 1))