From b6009672e15118dc32a0acb40f7c3b5d49471827 Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Wed, 1 Jun 2022 01:07:38 +0900 Subject: [PATCH] create setup-yama script --- .github/workflows/build.yml | 4 +--- .gitignore | 1 - README.md | 26 ++++++++++-------------- apkovl/etc/init.d/setup-yama | 6 ++++++ apkovl/etc/runlevels/default/setup-yama | 1 + bin/build | 6 +++--- bin/conf-gen | 9 --------- bin/img-gen | 11 +++++----- bin/overlay-gen | 10 ++++----- src/setup-yama | 27 +++++++++++++++++++++++++ usercfg.txt => src/usercfg.txt | 0 11 files changed, 60 insertions(+), 41 deletions(-) create mode 100755 apkovl/etc/init.d/setup-yama create mode 120000 apkovl/etc/runlevels/default/setup-yama delete mode 100755 bin/conf-gen create mode 100755 src/setup-yama rename usercfg.txt => src/usercfg.txt (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0e57388..2545437 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,9 +11,7 @@ jobs: - uses: actions/checkout@v2 - run: sudo apt-get update - run: sudo apt-get install -y qemu-user-static - - run: sudo bin/overlay-gen - - run: bin/build - - run: sudo bin/img-gen + - run: sudo bin/build - uses: actions/upload-artifact@v2 with: name: yama-armhf diff --git a/.gitignore b/.gitignore index 2d69006..08b7e77 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -/apkovl/ /cache/ /dist/ /overlay.img.gz diff --git a/README.md b/README.md index cfee0f3..dcc0a93 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,20 @@ Raspberry Pi Zero 向け OS のビルドするためのツール群 - WiFi 対応 - その他オレオレカスタマイズ +## 使い方 + +1. [Releases](https://github.com/kou029w/yama/releases) からイメージをダウンロード +2. イメージを microSD カードに書き込む +3. (必要に応じて) microSD カードの中の setup-yama ファイルを編集して保存 +4. microSD カードを Raspberry Pi Zero に差し込む +5. Raspberry Pi Zero の電源投入 + +電源投入後、2 分で起動完了 + ## ビルド ```sh -bin/overlay-gen bin/build -bin/img-gen ``` ### 前提条件 @@ -21,19 +29,7 @@ bin/img-gen - Docker - Docker Compose - qemu-user-static -- awk, bash, curl, fallocate, grep, gzip, losetup, mkfs.ext4, mkfs.fat, parted, python3, ssh-keygen, tar, xargs - -### WiFi の設定 - -`apkovl/etc/wpa_supplicant/wpa_supplicant.conf` 配置後ビルド - -```sh -bin/conf-gen | tee apkovl/etc/wpa_supplicant/wpa_supplicant.conf -``` - -### ssh の設定 - -`apkovl/root/.ssh/authorized_keys` をパーミッション 600 で配置後ビルド +- awk, curl, fallocate, gzip, losetup, mkfs.ext4, mkfs.fat, parted, python3, tar, xargs ## ライセンス diff --git a/apkovl/etc/init.d/setup-yama b/apkovl/etc/init.d/setup-yama new file mode 100755 index 0000000..4f6664e --- /dev/null +++ b/apkovl/etc/init.d/setup-yama @@ -0,0 +1,6 @@ +#!/sbin/openrc-run +start() { + if [ -x /media/mmcblk0p1/setup-yama ]; then + /media/mmcblk0p1/setup-yama + fi +} diff --git a/apkovl/etc/runlevels/default/setup-yama b/apkovl/etc/runlevels/default/setup-yama new file mode 120000 index 0000000..7dea946 --- /dev/null +++ b/apkovl/etc/runlevels/default/setup-yama @@ -0,0 +1 @@ +/etc/init.d/setup-yama \ No newline at end of file diff --git a/bin/build b/bin/build index 2fc1bbe..59047b3 100755 --- a/bin/build +++ b/bin/build @@ -10,9 +10,9 @@ rm -rf dist mkdir dist bin/download "${version}" dist docker compose run --rm minirootfs sh -c 'apk update && apk add' -ssh-keygen -A -f apkovl -cp -a usercfg.txt cache -t dist -gzip -cdk overlay.img.gz > dist/overlay.img +cp -a src/* cache -t dist +bin/overlay-gen dist/overlay.img docker compose run --rm builder tar czf dist/localhost.apkovl.tar.gz --owner=0 --group=0 -C apkovl . tar czf yama-armhf.tar.gz --owner=0 --group=0 -C dist . +bin/img-gen yama-armhf.img diff --git a/bin/conf-gen b/bin/conf-gen deleted file mode 100755 index bb6e695..0000000 --- a/bin/conf-gen +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -# wpa_supplicant.conf の生成 -# Usage: bin/conf-gen -# Required: wpa_supplicant grep -set -euo pipefail -read -p 'Please enter ssid: ' ssid -read -p 'Please enter passphrase: ' -s passphrase -wpa_passphrase "$ssid" "$passphrase" \ - | grep -v '#psk=' diff --git a/bin/img-gen b/bin/img-gen index 9f249e9..02f44ca 100755 --- a/bin/img-gen +++ b/bin/img-gen @@ -1,12 +1,13 @@ #!/bin/sh # デバイスイメージファイルの生成 -# Usage: bin/img-gen +# Usage: bin/img-gen yama-armhf.img # Required: gzip awk fallocate parted xargs losetup mkfs.fat tar cd -- "$(dirname -- "$0")/.." set -eux 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 < setup-yama.log 2>&1 + +ssid="" +passphrase="" +authorized_key="" + +if [ -n "$ssid" ]; then + wpa_passphrase "$ssid" "$passphrase" > /etc/wpa_supplicant/wpa_supplicant.conf + service wpa_supplicant restart +fi + +if [ -n "$authorized_key" ]; then + mkdir -p /root/.ssh + chmod 700 /root/.ssh + echo "$authorized_key" > /root/.ssh/authorized_keys + chmod 600 /root/.ssh/authorized_keys + ssh-keygen -A + service sshd restart +fi + +lbu include /root +lbu commit -d mmcblk0p1 +rm -f -- "$0" +echo ok diff --git a/usercfg.txt b/src/usercfg.txt similarity index 100% rename from usercfg.txt rename to src/usercfg.txt