sdinstall-rpi.sh: various changes

- ask confirmation before proceeding unless -y (assume yes) flag is passed from command line
- use parted to create partition table and partitions
- add some info and error messages and exit points in case of error
This commit is contained in:
Silvan Calarco 2013-06-19 10:33:50 +02:00
parent 2139bc2ac6
commit bd01ee2e19

View File

@ -5,9 +5,12 @@
# #
DRIVE=$1 DRIVE=$1
ROOTFSARCHIVE=$2 ROOTFSARCHIVE=$2
[ "$3" = "-y" ] && ASSUMEYES=1
[ "$DRIVE" -a "$ROOTFSARCHIVE" ] || { [ "$DRIVE" -a "$ROOTFSARCHIVE" ] || {
echo "Usage: $0 device rootfs-archive" echo "Usage: $0 device rootfs-archive [-y]"
echo
echo "-y: assume yes to all questions (script mode)"
echo echo
echo "Example: $0 /dev/sdb /tmp/openmamba-rootfs-light.arm.tar.xz" echo "Example: $0 /dev/sdb /tmp/openmamba-rootfs-light.arm.tar.xz"
exit 1 exit 1
@ -26,37 +29,42 @@ else
PARTITION2=${DRIVE}2 PARTITION2=${DRIVE}2
fi fi
dd if=/dev/zero of=$DRIVE bs=1024 count=1024 || { [ "$ASSUMEYES" ] || {
echo "ERROR: dd returned an error code of $?; aborting." echo -n "All current data in ${DRIVE} will be lost, do you want to proceed [y/N]?"
exit $? read ans
[ "$ans" = "y" -o "$ans" = "Y" ] || exit 0
} }
set -- $(LC_ALL=C fdisk -l "$DRIVE" | grep "^Disk.*bytes") sudo parted -s ${DRIVE} mktable msdos
SIZE="$5" if [ "$?" != "0" ]; then
echo "ERROR: parted exited with error $? while creating partition table on ${DRIVE}; aborting."
fi
# FAT partition
sudo parted -s -a cyl -- ${DRIVE} mkpart primary fat32 0 40M
if [ "$?" != "0" ]; then
echo "ERROR: parted exited with error $? while creating boot partition on ${DRIVE}; aborting."
fi
# openmamba partition
sudo parted -s -a cyl -- ${DRIVE} mkpart primary ext4 40M -1
if [ "$?" != "0" ]; then
echo "ERROR: parted exited with error $? while creating system partition on ${DRIVE}; aborting."
fi
[ "$SIZE" ] || { echo "Formatting $PARTITION1..."
echo "ERROR: unable to detect disk size; aborting." mkfs.vfat -s 1 -F 32 -n "BOOT" $PARTITION1 || {
echo "ERROR: unable to format $PARTITION1; aborting."
exit 1 exit 1
} }
echo "Disk Size: $SIZE bytes" echo "Formatting $PARTITION2..."
mke2fs -q -t ext4 -j -L "openmamba" $PARTITION2 || {
CYLINDERS=`echo $SIZE/255/63/512 | bc` echo "ERROR: unable to format $PARTITION2; aborting."
echo "Cylinders: $CYLINDERS" exit 1
{
echo ,9,0x0C,*
echo ,,,-
} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE || {
echo "ERROR: sfdisk returned an error code of $?; aborting."
exit $?
} }
mkfs.vfat -F 32 -n "BOOT" $PARTITION1
mke2fs -t ext4 -j -L "openmamba" $PARTITION2
### SD-Card: install software ### SD-Card: install software
echo "Fetching firmware from git..."
SWHOME=`mktemp -d` SWHOME=`mktemp -d`
cd $SWHOME cd $SWHOME
@ -70,8 +78,14 @@ ROOTMP=/media/openmamba
exit 1 exit 1
} }
udisks --mount $PARTITION1 udisks --mount $PARTITION1 || {
udisks --mount $PARTITION2 echo "ERROR: unable to mount partition $PARTITION1; aborting."
exit 1
}
udisks --mount $PARTITION2 || {
echo "ERROR: unable to mount partition $PARTITION2; aborting."
exit 1
}
# bootcode.bin: 2nd stage bootloader, starts with SDRAM disabled # bootcode.bin: 2nd stage bootloader, starts with SDRAM disabled
# loader.bin : 3rd stage bootloader, starts with SDRAM enabled # loader.bin : 3rd stage bootloader, starts with SDRAM enabled
@ -113,7 +127,8 @@ framebuffer_ignore_alpha=1" > $BOOTMP/config.txt
# Not present in the initial release. # Not present in the initial release.
pushd $ROOTMP >/dev/null pushd $ROOTMP >/dev/null
tar xvf $ROOTFSARCHIVE echo "Uncompressing $ROOTFSARCHIVE..."
tar xf $ROOTFSARCHIVE
popd >/dev/null popd >/dev/null
# copy kernel modules # copy kernel modules
@ -136,9 +151,11 @@ cp -a $SWHOME/firmware/modules/* $ROOTMP/lib/modules/
#s@#no_auto_depmod.*@no_auto_depmod=1@" \ #s@#no_auto_depmod.*@no_auto_depmod=1@" \
# $ROOTMP/etc/sysconfig/rc # $ROOTMP/etc/sysconfig/rc
sync
udisks --unmount $PARTITION1 udisks --unmount $PARTITION1
udisks --unmount $PARTITION2 udisks --unmount $PARTITION2
[ "$SWHOME" -a "${SWHOME:0:4}" = "/tmp" ] && rm -rf $SWHOME [ "$SWHOME" -a "${SWHOME:0:4}" = "/tmp" ] && rm -rf $SWHOME
echo "Done."
exit 0 exit 0