]> git.sesse.net Git - debian-xu4/blobdiff - mkimage.sh
Switch to getopt for more flexible option parsing.
[debian-xu4] / mkimage.sh
index f2d0e5d3cf2657992df0a8e1f5106a134c2a94ef..fd2a9210966c66bab49d92b3cfefdbbdace8da4a 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