]> git.sesse.net Git - debian-xu4/blobdiff - mkimage.sh
Minor cleanup.
[debian-xu4] / mkimage.sh
index f2d0e5d3cf2657992df0a8e1f5106a134c2a94ef..88b964d65c7736abe02b79dd6bd5072cd593d85c 100755 (executable)
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 
 # Install a bog-standard Debian bootable for ODROID XU3/XU4.
 # Note that this will only work for SD cards; MMC devices
 # Licensed under the GNU GPL, v2 or (at your option) any later version.
 
 set -e
-set -x
 
-DEVICE=$1
-BOOTPART_MB=$2
+DEVICE=
+BOOTPART_MB=256
+SUITE=stretch
+
+while getopts "b:s:" opt; do
+       case $opt in
+               b)
+                       BOOTPART_MB=$OPTARG
+                       ;;
+               s)
+                       # Sorry, jessie won't work; the kernel doesn't support XU3/XU4.
+                       SUITE=$OPTARG
+                       ;;
+               :)
+                       echo "Option -$OPTARG requires an argument."
+                       exit 1
+                       ;;
+       esac
+done
+shift $((OPTIND - 1))
 
-if [ ! -b "$DEVICE" ] || [ ! "$BOOTPART_MB" -gt 0 ]; then
-       echo "Usage: $0 DEVICE BOOTPARTITION_SIZE [SUITE [OTHER_DEBOOTSTRAP_ARGS...]]"
+DEVICE=$1
+if [ ! -b "$DEVICE" ]; then
+       echo "Usage: $0 [-b BOOTPARTITION_SIZE] [-s SUITE] DEVICE [OTHER_DEBOOTSTRAP_ARGS...]"
        echo "DEVICE is an SD card device, e.g. /dev/sdb."
        exit 1
 fi
-shift 2
+shift
 
-SUITE=$1
-if [ -z "$SUITE" ]; then
-       # Sorry, jessie won't work; the kernel doesn't support XU3/XU4.
-       SUITE=stretch
-else
-       shift
-fi
+set -x
 
 # Prerequisites.
 dpkg --add-architecture armhf
@@ -78,7 +90,8 @@ dd if=/dev/zero of=${DEVICE} seek=2560 count=32 bs=512 conv=sync
 # from ext4, but using FAT is somehow traditional and less likely to be broken
 # at any given time. (It doesn't support symlinks, though, which breaks flash-kernel,
 # but we don't use that anyway.)
-mkfs.vfat -F 32 ${DEVICE_STEM}1
+BOOT_PART=${DEVICE_STEM}1
+mkfs.vfat -F 32 ${BOOT_PART}
 
 # Put an LVM on the other partition; it's easier to deal with when expanding
 # partitions or otherwise moving them around.
@@ -97,7 +110,7 @@ mkfs.ext4 /dev/odroid/root
 mkdir -p /mnt/xu4/
 mount /dev/odroid/root /mnt/xu4
 mkdir /mnt/xu4/boot/
-mount ${DEVICE_STEM}1 /mnt/xu4/boot
+mount ${BOOT_PART} /mnt/xu4/boot
 debootstrap --include=linux-image-armmp-lpae,grub-efi-arm,lvm2,isc-dhcp-client --foreign --arch armhf ${SUITE} /mnt/xu4 "$@"
 
 # Run the second stage debootstrap under qemu (via binfmt_misc).
@@ -113,7 +126,7 @@ if [ "$SUITE" != "unstable" ] && [ "$SUITE" != "sid" ]; then
 fi
 
 # Create an fstab (this is normally done by partconf, in d-i).
-BOOT_UUID=$( blkid -s UUID -o value ${DEVICE_STEM}1 )
+BOOT_UUID=$( blkid -s UUID -o value ${BOOT_PART} )
 cat <<EOF > /mnt/xu4/etc/fstab
 # /etc/fstab: static file system information.
 #