From d86773ccc1ada3df0ac4043f00f95f92637ebed7 Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Tue, 21 Jul 2020 01:06:43 +0900 Subject: [PATCH] create projects --- .github/workflows/build.yml | 11 ++++++ .gitignore | 3 ++ README.md | 47 ++++++++++++++++++++++++ apkovl/etc/.default_boot_services | 0 apkovl/etc/apk/cache | 1 + apkovl/etc/apk/repositories | 3 ++ apkovl/etc/apk/world | 3 ++ apkovl/etc/network/interfaces | 6 +++ apkovl/etc/runlevels/boot/networking | 1 + apkovl/etc/runlevels/boot/wpa_supplicant | 1 + apkovl/etc/runlevels/default/ntpd | 1 + apkovl/etc/runlevels/default/sshd | 1 + apkovl/etc/ssh/sshd_config | 4 ++ bin/build | 15 ++++++++ bin/conf-gen | 9 +++++ bin/download | 8 ++++ bin/import | 7 ++++ bin/version | 10 +++++ docker-compose.yml | 8 ++++ 19 files changed, 139 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .gitignore create mode 100644 README.md create mode 100644 apkovl/etc/.default_boot_services create mode 120000 apkovl/etc/apk/cache create mode 100644 apkovl/etc/apk/repositories create mode 100644 apkovl/etc/apk/world create mode 100644 apkovl/etc/network/interfaces create mode 120000 apkovl/etc/runlevels/boot/networking create mode 120000 apkovl/etc/runlevels/boot/wpa_supplicant create mode 120000 apkovl/etc/runlevels/default/ntpd create mode 120000 apkovl/etc/runlevels/default/sshd create mode 100644 apkovl/etc/ssh/sshd_config create mode 100755 bin/build create mode 100755 bin/conf-gen create mode 100755 bin/download create mode 100755 bin/import create mode 100755 bin/version create mode 100644 docker-compose.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..105fb6c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,11 @@ +name: build +on: + schedule: [{ cron: "0 21 * * sun" }] # Every Monday at 6am Asia/Tokyo UTC+9 +jobs: + main: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: docker login docker.pkg.github.com -u "${GITHUB_ACTOR}" -p "${{ github.token }}" + - run: bin/build + - run: docker-compose push diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5c82d99 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/apkovl/ +/cache/ +/dist/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..075dfc3 --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# Yama + +Raspberry Pi 向け OS のビルドするためのツール群 + +- Alpine Linux ベース (armhf) +- WiFi 対応 +- その他オレオレカスタマイズ + +## ビルド + +```sh +bin/build +``` + +### SD カードのフォーマット + +- FAT32 (LBA) +- boot フラグ付ける +- ボリュームラベル付けない + +### SD カードに書き込み + +```sh +rsync -a dist/ /path/to/sd/ +``` + +### 前提条件 + +- Docker Compose +- curl +- grep +- jq +- ruby +- ssh-keygen +- bash + +### 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 で配置後ビルド diff --git a/apkovl/etc/.default_boot_services b/apkovl/etc/.default_boot_services new file mode 100644 index 0000000..e69de29 diff --git a/apkovl/etc/apk/cache b/apkovl/etc/apk/cache new file mode 120000 index 0000000..2c6b62b --- /dev/null +++ b/apkovl/etc/apk/cache @@ -0,0 +1 @@ +/media/mmcblk0p1/cache \ No newline at end of file diff --git a/apkovl/etc/apk/repositories b/apkovl/etc/apk/repositories new file mode 100644 index 0000000..497308a --- /dev/null +++ b/apkovl/etc/apk/repositories @@ -0,0 +1,3 @@ +/media/mmcblk0p1/apks +http://dl-cdn.alpinelinux.org/alpine/v3.12/main +http://dl-cdn.alpinelinux.org/alpine/v3.12/community diff --git a/apkovl/etc/apk/world b/apkovl/etc/apk/world new file mode 100644 index 0000000..652e062 --- /dev/null +++ b/apkovl/etc/apk/world @@ -0,0 +1,3 @@ +alpine-base +openssh +wpa_supplicant diff --git a/apkovl/etc/network/interfaces b/apkovl/etc/network/interfaces new file mode 100644 index 0000000..f4bde3f --- /dev/null +++ b/apkovl/etc/network/interfaces @@ -0,0 +1,6 @@ +auto lo +iface lo inet loopback + +auto wlan0 +iface wlan0 inet dhcp + hostname localhost diff --git a/apkovl/etc/runlevels/boot/networking b/apkovl/etc/runlevels/boot/networking new file mode 120000 index 0000000..79fa8db --- /dev/null +++ b/apkovl/etc/runlevels/boot/networking @@ -0,0 +1 @@ +/etc/init.d/networking \ No newline at end of file diff --git a/apkovl/etc/runlevels/boot/wpa_supplicant b/apkovl/etc/runlevels/boot/wpa_supplicant new file mode 120000 index 0000000..da25b62 --- /dev/null +++ b/apkovl/etc/runlevels/boot/wpa_supplicant @@ -0,0 +1 @@ +/etc/init.d/wpa_supplicant \ No newline at end of file diff --git a/apkovl/etc/runlevels/default/ntpd b/apkovl/etc/runlevels/default/ntpd new file mode 120000 index 0000000..1342392 --- /dev/null +++ b/apkovl/etc/runlevels/default/ntpd @@ -0,0 +1 @@ +/etc/init.d/ntpd \ No newline at end of file diff --git a/apkovl/etc/runlevels/default/sshd b/apkovl/etc/runlevels/default/sshd new file mode 120000 index 0000000..b969430 --- /dev/null +++ b/apkovl/etc/runlevels/default/sshd @@ -0,0 +1 @@ +/etc/init.d/sshd \ No newline at end of file diff --git a/apkovl/etc/ssh/sshd_config b/apkovl/etc/ssh/sshd_config new file mode 100644 index 0000000..22b2769 --- /dev/null +++ b/apkovl/etc/ssh/sshd_config @@ -0,0 +1,4 @@ +AuthorizedKeysFile .ssh/authorized_keys +PasswordAuthentication no +ChallengeResponseAuthentication no +Subsystem sftp /usr/lib/ssh/sftp-server diff --git a/bin/build b/bin/build new file mode 100755 index 0000000..cf96534 --- /dev/null +++ b/bin/build @@ -0,0 +1,15 @@ +#!/bin/sh +# ビルド +# Usage: bin/build +# Required: docker-compose +cd -- "$(dirname -- "$0")/.." +set -eux +version="$(bin/version)" +bin/import "${version}" docker.pkg.github.com/kou029w/yama/minirootfs +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 cache dist +tar czf dist/localhost.apkovl.tar.gz --owner=0 --group=0 -C apkovl . diff --git a/bin/conf-gen b/bin/conf-gen new file mode 100755 index 0000000..bb6e695 --- /dev/null +++ b/bin/conf-gen @@ -0,0 +1,9 @@ +#!/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/download b/bin/download new file mode 100755 index 0000000..ab0cb5f --- /dev/null +++ b/bin/download @@ -0,0 +1,8 @@ +#!/bin/sh +# ベースのイメージをダウンロード +# Usage: bin/download version dist +# Required: curl +set -eu +base="http://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/armhf" +curl "${base}/alpine-rpi-${1}-armhf.tar.gz" \ + | tar xzf - -C "${2}" diff --git a/bin/import b/bin/import new file mode 100755 index 0000000..27f7102 --- /dev/null +++ b/bin/import @@ -0,0 +1,7 @@ +#!/bin/sh +# イメージを取得 +# Usage: bin/import version my-image-name +# Required: docker +set -eux +base="http://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/armhf" +docker import "${base}/alpine-minirootfs-${1}-armhf.tar.gz" "${2}" diff --git a/bin/version b/bin/version new file mode 100755 index 0000000..8ba5475 --- /dev/null +++ b/bin/version @@ -0,0 +1,10 @@ +#!/bin/sh +# 最新のバージョンを取得 +# Usage: bin/version +# Required: curl grep jq ruby +set -eu +base="http://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/armhf" +curl -s "${base}/latest-releases.yaml" \ + | ruby -ryaml -rjson -e 'puts(YAML.load($<).to_json)' \ + | jq -r '.[] | select(.title == "Raspberry Pi").file' \ + | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9191977 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: "3" +services: + minirootfs: + image: docker.pkg.github.com/kou029w/yama/minirootfs + volumes: + - ./cache:/etc/apk/cache + - ./apkovl/etc/apk/repositories:/etc/apk/repositories + - ./apkovl/etc/apk/world:/etc/apk/world