Skip to content

Commit

Permalink
Add support for desktop & full variants among other tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
meeDamian committed Jul 27, 2020
1 parent 1531ba5 commit 1086e1b
Show file tree
Hide file tree
Showing 5 changed files with 306 additions and 197 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,10 @@ jobs:
echo ::set-env name=SRC_URL::"$URL"
echo ::set-env name=SRC_FILE::"$(basename "$URL")"
- name: Build Docker image
if: env.VERSION != ''
run: docker build -t builder .

- name: Modify Raspberry Pi OS image
if: env.VERSION != ''
run: |
mkdir images/
docker run --rm --privileged -v="$(pwd)/images/:/raspios/" builder
./modify-image-in-docker.sh
echo ::set-env name=FILE::"$(cd images && ls *-firstboot.zip)"
- name: Create Github Release
Expand Down
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ RUN apt-get update && \
wget \
zip

ADD modify-image.sh /usr/local/bin/modify-image
RUN chmod +x /usr/local/bin/modify-image
RUN mkdir -p /mnt/raspios/ /data/
ADD ./firstboot*.service /data/

RUN mkdir -p /mnt/raspios/ /data/
ADD firstboot.service firstboot-script.service /data/
VOLUME /images/
WORKDIR /

VOLUME /raspios/
WORKDIR /raspios/
ADD modify-image.sh /usr/local/bin/modify-image
RUN chmod +x /usr/local/bin/modify-image

ENTRYPOINT ["/usr/local/bin/modify-image"]
CMD ["create", "/raspios/"]
CMD ["create"]
72 changes: 68 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,82 @@
Raspberry Pi OS
================

Literally just pure Raspberry Pi OS Lite, but with added the ability to run a script on the first boot by putting it onto `/boot/` as either:
Official Raspberry Pi OS Lite minimally **modified** with the ability to run a script on the first boot.

* `/boot/firstboot.sh` - Run provided script directly
* `/boot/firstboot-script.sh` - Run via [`script(1)`][script] for complete session recording, that can be later played back using [`scriptreplay(1)`][replay]
Supported script filenames:

* `/boot/firstboot.sh` - Just run the script on the first boot
* `/boot/firstboot-script.sh` - Same as above, **except** _script_ is run with [`script(1)`][script] for complete session recording, that can be later played back using [`scriptreplay(1)`][replay]

[script]: http://man7.org/linux/man-pages/man1/script.1.html
[replay]: http://man7.org/linux/man-pages/man1/scriptreplay.1.html

Repo is inspired by https://github.com/nmcclain/raspberian-firstboot, but has been automated, Dockerized, and fully scripted.

There are 4 ways to get the image:
> **NOTE:** If `firstboot-script.sh` is used, recording of script run is saved as `/boot/firstboot-script-log.out` (timing file alongside as `firstboot-script-log.tm`)
## Usage

1. Download [latest image][latest]
<details><summary><b>Alternatives?</b></summary>

If downloading images built by other people is not your thing, you can also:

1. Modify images yourself using provided scripts (in [Docker], or [not]), or even
1. [Manually] apply all necessary modifications
</details>

[latest]: #1-releases
[docker]: #2-docker
[not]: #3-script
[manually]: #4-manual
1. Burn it into a MicroSD Card
<details><summary><b>How?</b></summary>

1. Probably the easiest is to use [Etcher]
1. Another way is [using `dd`][dd] on Linux:
```shell script
dd bs=4M if=path/to/downloaded/file.img of=/dev/sdX conv=fsync
```
1. Or MacOS:
```shell script
dd bs=4M if=path/to/downloaded/file.img of=/dev/diskX conv=fsync
```

**NOTE:** `boot` partition will usually get mounted as `/Volumes/boot/` on MacOS, and _probably_ `/mnt/boot/` on Linux.
</details>

[Etcher]: https://www.balena.io/etcher/
[dd]: https://www.raspberrypi.org/documentation/installation/installing-images/linux.md
1. Mount it
<details><summary><b>How?</b></summary>

1. **\[MacOS\]** Simply re-inserting the card should do the trick, if not then `diskutil`, or `Disk Utility` should help
1. **\[Linux\]** Hard to say exactly, but sth like:
```sh
mkdir -p /mnt/boot/
sudo mount /dev/sdX /mnt/boot/
```
</details>

1. Add your script & mark it as executable
```sh
# MacOS example:
cd /Volumes/boot/
cat <<EOF > firstboot-script.sh
#!/bin/sh -e
echo "Hello World!"
EOF
chmod +x firstboot-script.sh
```
1. Safely eject, move the card into Raspberry Pi, and power it on
## Download
There are 4 possible ways, numbered from easiest to most manual.
### 1. Releases
Expand Down
33 changes: 28 additions & 5 deletions modify-image-in-docker.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
#!/usr/bin/env sh
#!/bin/sh -e

set -e
show_help() {
cat <<EOF >&2
Usage: ./${0##*/} [ --lite | --desktop | --full ] [ DOCKER_TAG ]
Defaults: --lite & DOCKER_TAG=raspios-firstboot
Variants --lite, --desktop, --full as per:
https://www.raspberrypi.org/downloads/raspberry-pi-os/
EOF
}

case "$1" in
-h|--help) show_help ; exit 0;;
--lite) VARIANT=lite ; shift ;;
--desktop) VARIANT=desktop ; shift ;;
--full) VARIANT=full ; shift ;;
--*)
>&2 printf "\n ERR: Flag unknown: '%s'\n" "$1"
show_help
exit 1 ;;
esac

export DOCKER_BUILDKIT=1

TAG=raspios-firstboot
TAG="${1:-raspios-firstboot}"
DIR="$(pwd)/images"

docker build --progress=plain --tag "$TAG" .
[ -d "$DIR" ] || mkdir "$DIR"

docker run --privileged --rm --volume="$(pwd)/images:/raspios/" "$TAG"
docker build --progress=plain --tag="$TAG" .
exec docker run --privileged --rm --volume="$DIR:/images/" "$TAG" create "${VARIANT:-lite}"
Loading

0 comments on commit 1086e1b

Please sign in to comment.