From 8f4dc4b2086d886895a190335628208d1ecba4db Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Sun, 5 Sep 2021 13:47:00 +0900 Subject: [PATCH] add build job for disk image file --- .github/workflows/build.yml | 1 + .gitignore | 1 + README.md | 21 ++------------------- bin/img-gen | 25 +++++++++++++++++++++++++ 4 files changed, 29 insertions(+), 19 deletions(-) create mode 100755 bin/img-gen diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4cb7c21..712797c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,3 +9,4 @@ jobs: - run: sudo apt-get update - run: sudo apt-get install -y qemu-user-static - run: bin/build + - run: sudo bin/img-gen diff --git a/.gitignore b/.gitignore index 7b79e86..3b57b86 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /cache/ /dist/ /megabit-armhf.tar.gz +/megabit-armhf.img.gz diff --git a/README.md b/README.md index 899a9ba..cbba19c 100644 --- a/README.md +++ b/README.md @@ -39,18 +39,7 @@ blink(); ```sh bin/build -``` - -### SD カードのフォーマット - -- FAT32 (LBA) -- boot フラグ付ける -- ボリュームラベル付けない - -### SD カードに書き込み - -```sh -tar xf megabit-armhf.tar.gz -C /path/to/sd/ +bin/img-gen ``` ### 前提条件 @@ -59,14 +48,8 @@ tar xf megabit-armhf.tar.gz -C /path/to/sd/ - binfmt-support 2.1.7+ - Docker - Docker Compose -- curl -- grep -- gzip -- jq -- ruby -- ssh-keygen -- bash - qemu-user-static +- awk, bash, curl, fallocate, grep, gzip, gzip, jq, losetup, mkfs.fat, parted, ruby, ssh-keygen, tar, xargs ### WiFi の設定 diff --git a/bin/img-gen b/bin/img-gen new file mode 100755 index 0000000..abfdb29 --- /dev/null +++ b/bin/img-gen @@ -0,0 +1,25 @@ +#!/bin/sh +# デバイスイメージファイルの生成 +# Usage: bin/img-gen +# Required: gzip awk fallocate parted xargs losetup mkfs.fat tar +cd -- "$(dirname -- "$0")/.." +set -eux +size="$(gzip -l megabit-armhf.tar.gz | awk 'END{printf"%.f",$2*1.02}')" +fallocate -l "${size}" megabit-armhf.img +xargs -l parted -s megabit-armhf.img <