-#! /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
# 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.
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).
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.
#