diff options
Diffstat (limited to 'mkimage.sh.in')
-rw-r--r-- | mkimage.sh.in | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/mkimage.sh.in b/mkimage.sh.in index 246693c..493f359 100644 --- a/mkimage.sh.in +++ b/mkimage.sh.in @@ -50,30 +50,38 @@ die() { } usage() { - echo "Usage: $PROGNAME [-b fstype] [-o filename] [-r fstype] [-hV] <rootfs-tarball> [size]" - echo - echo " The <rootfs-tarball> argument expects a file generated by void-mkrootfs." - echo " The <size> argument expects a number (GB). If <size> is not set, defaults to 2." - echo - echo "OPTIONS" - echo " -b <fstype> Set /boot <fstype> (defaults to FAT, 32MB)" - echo " -o <filename> Set output <filename>." - echo " -r <fstype> Set / <fstype> (defaults to ext4, 32MB - <size>)" - echo " -p <platform> Set platform type: cubieboard2, rpi, odroid-u2" - echo - echo " Resulting image will have 2 partitions, /boot and / of total <size>." + cat <<_EOF +Usage: $PROGNAME [options] <rootfs-tarball> + +The <rootfs-tarball> argument expects a tarball generated by void-mkrootfs. +The platform is guessed automatically by its name. + +Accepted sizes suffixes: K, M, G, T, E. + +OPTIONS + -b <fstype> Set /boot filesystem type (defaults to FAT) + -B <bsize> Set /boot filesystem size (defaults to 64MB) + -r <fstype> Set / filesystem type (defaults to EXT4) + -s <totalsize> Set total image size (defaults to 2GB) + -o <output> Set image filename (guessed automatically) + -h Show this help + -V Show version + +Resulting image will have 2 partitions, /boot and /. +_EOF exit 0 } # # main() # -while getopts "b:o:r:p:hV" opt; do +while getopts "b:B:o:r:s:hV" opt; do case $opt in b) BOOT_FSTYPE="$OPTARG";; + B) BOOT_FSSIZE="$OPTARG";; o) FILENAME="$OPTARG";; r) ROOT_FSTYPE="$OPTARG";; - p) PLATFORM="$OPTARG";; + s) IMGSIZE="$OPTARG";; V) echo "$PROGNAME @@MKLIVE_VERSION@@"; exit 0;; h) usage;; esac @@ -87,6 +95,9 @@ elif [ ! -r "$ROOTFS_TARBALL" ]; then die "Cannot read rootfs tarball: $ROOTFS_TARBALL" fi +PLATFORM="${ROOTFS_TARBALL#void-}" +PLATFORM="${PLATFORM%-rootfs*}" + if [ "$(id -u)" -ne 0 ]; then die "need root perms to continue, exiting." fi @@ -98,19 +109,18 @@ else IMGSIZE="${2}G" fi -if [ -z "$BOOT_FSTYPE" ]; then - BOOT_FSTYPE="vfat" -fi -if [ -z "$ROOT_FSTYPE" ]; then - ROOT_FSTYPE="ext4" -fi +: ${BOOT_FSTYPE:=vfat} +: ${BOOT_FSSIZE:=64M} +: ${ROOT_FSTYPE:=ext4} + if [ -z "$FILENAME" ]; then - FILENAME="void-image-$(date +%Y%m%d).img" + FILENAME="void-${PLATFORM}-$(date +%Y%m%d).img" fi +# double check PLATFORM is supported... case "$PLATFORM" in cubieboard2|odroid-u2|rpi);; - *) die "Unknown platform or platform unset, set it with -p!" + *) die "The $PLATFORM is not supported, exiting..." esac for f in parted partx losetup mount mkfs.${BOOT_FSTYPE} mkfs.${ROOT_FSTYPE}; do @@ -135,8 +145,8 @@ if [ "$BOOT_FSTYPE" = "vfat" ]; then _btype="fat32" _args="-I" fi -parted $FILENAME mkpart primary ${_btype} 4096s 64M -parted $FILENAME mkpart primary ext2 64M 100% +parted $FILENAME mkpart primary ${_btype} 4096s ${BOOT_FSSIZE} +parted $FILENAME mkpart primary ext2 ${BOOT_FSSIZE} 100% parted $FILENAME toggle 1 boot LOOPDEV=$(losetup --show --find $FILENAME) partx -a $LOOPDEV |