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

create setup-yama script

This commit is contained in:
Nebel 2022-06-01 01:07:38 +09:00
parent 5b4526ff20
commit b6009672e1
11 changed files with 60 additions and 41 deletions

View file

@ -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

1
.gitignore vendored
View file

@ -1,4 +1,3 @@
/apkovl/
/cache/
/dist/
/overlay.img.gz

View file

@ -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
## ライセンス

6
apkovl/etc/init.d/setup-yama Executable file
View file

@ -0,0 +1,6 @@
#!/sbin/openrc-run
start() {
if [ -x /media/mmcblk0p1/setup-yama ]; then
/media/mmcblk0p1/setup-yama
fi
}

View file

@ -0,0 +1 @@
/etc/init.d/setup-yama

View file

@ -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

View file

@ -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='

View file

@ -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 <<EOF
image="$1"
fallocate -l "${size}" "${image}"
xargs -l parted -s "${image}" <<EOF
mklabel msdos
mkpart primary fat32 0 100%
set 1 boot on
@ -14,7 +15,7 @@ EOF
dev="$(losetup -f)"
finally="losetup -d '${dev}'"
trap 'sh -c "${finally}"' EXIT
losetup -P "${dev}" yama-armhf.img
losetup -P "${dev}" "${image}"
part="${dev}p1"
mkfs.fat "${part}"
tmp="$(mktemp -d)"
@ -22,4 +23,4 @@ finally="rmdir '${tmp}'; ${finally}"
mount "${part}" "${tmp}"
finally="umount '${tmp}'; ${finally}"
tar xf yama-armhf.tar.gz -C "${tmp}"
finally="${finally}; gzip -f yama-armhf.img"
finally="${finally}; gzip -f '${image}'"

View file

@ -1,20 +1,20 @@
#!/bin/sh
# オーバーレイイメージファイルの生成
# Usage: bin/overlay-gen
# Usage: bin/overlay-gen dist/overlay.img
# Required: fallocate losetup mkfs.ext4 gzip
cd -- "$(dirname -- "$0")/.."
set -eux
size=512m
fallocate -l "${size}" overlay.img
mkfs.ext4 overlay.img
image="$1"
fallocate -l "${size}" "${image}"
mkfs.ext4 "${image}"
dev="$(losetup -f)"
finally="losetup -d '${dev}'"
trap 'sh -c "${finally}"' EXIT
losetup "${dev}" overlay.img
losetup "${dev}" "${image}"
tmp="$(mktemp -d)"
finally="rmdir '${tmp}'; ${finally}"
mount "${dev}" "${tmp}"
finally="umount '${tmp}'; ${finally}"
mkdir -p "${tmp}/work/usr"
mkdir -p "${tmp}/upper/usr"
finally="${finally}; gzip -f overlay.img"

27
src/setup-yama Executable file
View file

@ -0,0 +1,27 @@
#!/bin/sh
set -eu
cd -- "$(dirname -- "$0")"
exec > 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