From e355bd7ce9482662443feb963cee264390014aa8 Mon Sep 17 00:00:00 2001 From: Michael Shigorin Date: Thu, 21 Jun 2012 10:17:16 +0300 Subject: [PATCH] bashize tar2vm Finally tired of expr(1) quirks, and even ash(1) does $((arithmetic-expansion))! --- bin/tar2vm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/tar2vm b/bin/tar2vm index f53f7d10..9be60ddb 100755 --- a/bin/tar2vm +++ b/bin/tar2vm @@ -1,4 +1,4 @@ -#!/bin/sh -e +#!/bin/bash -e . shell-error @@ -27,10 +27,10 @@ IMG="$2" # image size in bytes (256M is a fallback) TARSIZE="$(stat -Lc %s "$TAR")" -DEFSIZE="$(expr 3 '*' "$TARSIZE" '/' 2)" +DEFSIZE="$((3 * $TARSIZE / 2))" DISKSIZE="${3:-${DEFSIZE:-268435456}}" # ...and in megabytes -DISKSIZEM="$(expr "$DISKSIZE" / 1048576)" +DISKSIZEM="$(($DISKSIZE / 1048576))" # tested to work: ext[234], jfs ROOTFSTYPE="${4:-ext4}" @@ -68,7 +68,8 @@ trap exit_handler EXIT # prepare disk image and a filesystem inside it rm -f -- "$IMG" -dd if=/dev/zero of="$IMG" bs=1 count=1 seek="$DISKSIZE" conv=notrunc +dd if=/dev/zero of="$IMG" conv=notrunc \ + bs=1 count=1 seek="$(($DISKSIZE - 1))" losetup "$LOOPDEV" "$IMG" parted --script "$LOOPDEV" mklabel msdos