Commit e355bd7c authored by Michael Shigorin's avatar Michael Shigorin

bashize tar2vm

Finally tired of expr(1) quirks, and even ash(1) does $((arithmetic-expansion))!
parent 0a5f164d
#!/bin/sh -e #!/bin/bash -e
. shell-error . shell-error
...@@ -27,10 +27,10 @@ IMG="$2" ...@@ -27,10 +27,10 @@ IMG="$2"
# image size in bytes (256M is a fallback) # image size in bytes (256M is a fallback)
TARSIZE="$(stat -Lc %s "$TAR")" TARSIZE="$(stat -Lc %s "$TAR")"
DEFSIZE="$(expr 3 '*' "$TARSIZE" '/' 2)" DEFSIZE="$((3 * $TARSIZE / 2))"
DISKSIZE="${3:-${DEFSIZE:-268435456}}" DISKSIZE="${3:-${DEFSIZE:-268435456}}"
# ...and in megabytes # ...and in megabytes
DISKSIZEM="$(expr "$DISKSIZE" / 1048576)" DISKSIZEM="$(($DISKSIZE / 1048576))"
# tested to work: ext[234], jfs # tested to work: ext[234], jfs
ROOTFSTYPE="${4:-ext4}" ROOTFSTYPE="${4:-ext4}"
...@@ -68,7 +68,8 @@ trap exit_handler EXIT ...@@ -68,7 +68,8 @@ trap exit_handler EXIT
# prepare disk image and a filesystem inside it # prepare disk image and a filesystem inside it
rm -f -- "$IMG" 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" losetup "$LOOPDEV" "$IMG"
parted --script "$LOOPDEV" mklabel msdos parted --script "$LOOPDEV" mklabel msdos
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment