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

27 lines
689 B
Text
Raw Permalink Normal View History

2021-09-05 13:47:00 +09:00
#!/bin/sh
# デバイスイメージファイルの生成
2022-06-01 01:07:38 +09:00
# Usage: bin/img-gen yama-armhf.img
2022-06-01 11:02:46 +09:00
# Required: gzip fallocate parted xargs losetup mkfs.fat tar
2021-09-05 13:47:00 +09:00
cd -- "$(dirname -- "$0")/.."
set -eux
2022-06-01 11:02:46 +09:00
size=768m
2022-06-01 01:07:38 +09:00
image="$1"
fallocate -l "${size}" "${image}"
xargs -l parted -s "${image}" <<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-06-01 01:07:38 +09:00
losetup -P "${dev}" "${image}"
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}"
2022-06-01 01:07:38 +09:00
finally="${finally}; gzip -f '${image}'"