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

26 lines
689 B
Bash
Executable file

#!/bin/sh
# デバイスイメージファイルの生成
# Usage: bin/img-gen yama-armhf.img
# Required: gzip fallocate parted xargs losetup mkfs.fat tar
cd -- "$(dirname -- "$0")/.."
set -eux
size=768m
image="$1"
fallocate -l "${size}" "${image}"
xargs -l parted -s "${image}" <<EOF
mklabel msdos
mkpart primary fat32 0 100%
set 1 boot on
EOF
dev="$(losetup -f)"
finally="losetup -d '${dev}'"
trap 'sh -c "${finally}"' EXIT
losetup -P "${dev}" "${image}"
part="${dev}p1"
mkfs.fat "${part}"
tmp="$(mktemp -d)"
finally="rmdir '${tmp}'; ${finally}"
mount "${part}" "${tmp}"
finally="umount '${tmp}'; ${finally}"
tar xf yama-armhf.tar.gz -C "${tmp}"
finally="${finally}; gzip -f '${image}'"