1
0
Fork 0
mirror of https://github.com/kou029w/yama.git synced 2025-01-19 00:18:06 +00:00
yama/bin/img-gen

26 lines
742 B
Text
Raw Normal View History

2021-09-05 13:47:00 +09:00
#!/bin/sh
# デバイスイメージファイルの生成
# Usage: bin/img-gen
# Required: gzip awk fallocate parted xargs losetup mkfs.fat tar
cd -- "$(dirname -- "$0")/.."
set -eux
2022-05-30 22:11:18 +09:00
size="$(gzip -l yama-armhf.tar.gz | awk 'END{printf"%.f",$2*1.02}')"
fallocate -l "${size}" yama-armhf.img
xargs -l parted -s yama-armhf.img <<EOF
2021-09-05 13:47:00 +09:00
mklabel msdos
mkpart primary fat32 0 100%
set 1 boot on
EOF
dev="$(losetup -f)"
finally="losetup -d '${dev}'"
trap 'sh -c "${finally}"' EXIT
2022-05-30 22:11:18 +09:00
losetup -P "${dev}" yama-armhf.img
2021-09-05 13:47:00 +09:00
part="${dev}p1"
mkfs.fat "${part}"
tmp="$(mktemp -d)"
finally="rmdir '${tmp}'; ${finally}"
mount "${part}" "${tmp}"
finally="umount '${tmp}'; ${finally}"
2022-05-30 22:11:18 +09:00
tar xf yama-armhf.tar.gz -C "${tmp}"
finally="${finally}; gzip -f yama-armhf.img"