Changeset 2726 in /cluster/svnroot


Ignore:
Timestamp:
Oct 14, 2010 5:19:17 PM (10 years ago)
Author:
fitz
Message:

#536:

  • mktemp for temporary directories
  • check dependancies
  • minor formatting and consistency updates
  • use find to find mbr.bin instead of locate (because the BCCD image doesn't have locate readily available).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • bccd-ng/trunk/bin/build_bootable_USB.sh

    r2283 r2726  
    33
    44if [ $1 ]; then
    5 DRIVE=$1
     5  DRIVE=$1
    66else
    7 echo "USAGE:\n $0 <USB DRIVE>"
    8 exit
     7  echo -e "USAGE:\n $0 <USB DRIVE> <ISO>"
     8  exit
    99fi
    1010
    1111if [ $2 ]; then
    12 ISO_PATH=$2
     12  ISO_PATH=$2
    1313else
    14 echo "USAGE:\n $0 <USB DRIVE> <ISO>"
    15 exit
     14  echo -e "USAGE:\n $0 <USB DRIVE> <ISO>"
     15  exit
    1616fi
    1717
    1818if [ `id -u` != 0 ]; then
    19 echo "error: superuser privileges required"
    20 exit
     19  echo "error: superuser privileges required"
     20  exit
    2121fi
    2222
     23echo 'Checking dependencies'
     24parted=`which parted`
     25syslinux=`which syslinux`
     26rsync=`which rsync`
     27
     28if test -z $parted; then
     29  echo "Error: Missing depenedency: parted"
     30  exit
     31fi
     32if test -z $syslinux; then
     33  echo "Error: Missing depenedency: syslinux"
     34  exit
     35fi
     36if test -z $rsync; then
     37  echo "Error: Missing depenedency: rsync"
     38  exit
     39fi
     40
    2341echo 'Removing existing partitions'
    24 PARTITIONS=`parted $DRIVE print | grep ^\ [0-9] | awk '{print $1}'`
    25 if [ "$PARTITIONS" ]
    26 then
    27 for i in $PARTITIONS
    28 do
    29 echo "removing partition $i:"
    30 parted $DRIVE rm $i;
    31 done
     42PARTITIONS=`$parted $DRIVE print | grep ^\ [0-9] | awk '{print $1}'`
     43if [ "$PARTITIONS" ]; then
     44  for i in $PARTITIONS; do
     45    echo "removing partition $i:"
     46    $parted $DRIVE rm $i;
     47  done
    3248fi
    3349
    3450echo 'Creating and formatting the one-gigabyte partition'
    35 parted $DRIVE mkpartfs primary fat32 0 1028
     51$parted $DRIVE mkpartfs primary fat32 0 1028
    3652echo 'Making partition bootable'
    37 parted $DRIVE set 1 boot on
     53$parted $DRIVE set 1 boot on
    3854
    3955echo 'Copying mbr.bin'
    40 cat `locate mbr.bin` >> $DRIVE
     56mbr=`find /usr/lib -name mbr.bin | head -1`
     57cat $mbr >> $DRIVE
    4158
    4259echo 'Running syslinux'
    43 syslinux -s "${DRIVE}1"
     60$syslinux -s "${DRIVE}1"
    4461
    4562echo 'Making temporary directories'
    46 mkdir iso-tmp
    47 mkdir usb-tmp
     63ISO_DIR=`mktemp -d iso-XXXXXXXX`
     64USB_DIR=`mktemp -d usb-XXXXXXXX`
    4865
    4966echo 'Mounting image and partition to temporary directories'
    50 mount -o loop $ISO_PATH iso-tmp/
    51 mount ${DRIVE}1 usb-tmp/
     67mount -o loop $ISO_PATH $ISO_DIR/
     68mount ${DRIVE}1 $USB_DIR/
    5269
    5370echo 'Copying files from image to partition'
    5471echo 'This will take a while...'
    55 rsync -Plarv iso-tmp/ usb-tmp/
    56 cp iso-tmp/boot/isolinux/* usb-tmp/
    57 mv usb-tmp/isolinux.cfg usb-tmp/syslinux.cfg
     72$rsync -Plarv $ISO_DIR/ $USB_DIR/
     73cp $ISO_DIR/boot/isolinux/* $USB_DIR/
     74mv $USB_DIR/isolinux.cfg $USB_DIR/syslinux.cfg
    5875
    5976echo 'Unmounting image and partition'
    60 umount iso-tmp/
    61 umount usb-tmp/
     77umount $ISO_DIR/
     78umount $USB_DIR/
    6279
    6380echo 'Removing temporary directories'
    64 rm -r iso-tmp/
    65 rm -r usb-tmp/
     81rm -r $ISO_DIR/
     82rm -r $USB_DIR/
    6683
    6784echo 'Script finished.'
    68 beep -l 1000 
Note: See TracChangeset for help on using the changeset viewer.