Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buster upgrade #25

Open
wants to merge 67 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
18b945f
Moved git-hash determination to passed in build variable (#273)
kevinastone Aug 11, 2019
8110eb4
Remove unused interfaces file (#322)
christophehurpeau Aug 11, 2019
d1f7a38
Support regional config settings (#323)
jbussdieker Aug 14, 2019
28f3441
stage5: add scratch3
XECDesign Aug 12, 2019
c1ff2b1
stage4: rename thonny package
XECDesign Aug 12, 2019
a016561
export-image: Remove interfaces.dpkg-old
XECDesign May 7, 2019
c49261d
stage2: install pciutils
XECDesign Jun 3, 2019
77833ba
cmdline.txt: remove dwc_otg.lpm_enable=0
XECDesign Jun 3, 2019
e8460be
Revert "export-image: Remove interfaces.dpkg-old"
XECDesign Aug 14, 2019
00c22ab
Updated export-image to not depend on fake-hwclock and hardlink. (#326)
rkubes Aug 27, 2019
d1ed4a2
Include rpi-eeprom
XECDesign Sep 18, 2019
6527807
Update config.txt to replace lirc-rpi with gpio-ir (#328)
fpicalausa Sep 23, 2019
6538d5b
Update release notes
XECDesign Sep 23, 2019
946f164
stage3: Mousepad used as simple text editor instead of leafpad
XECDesign Sep 24, 2019
99f702f
Use parted for partitioning (#285)
matthijskooijman Sep 25, 2019
5780006
Update release notes
XECDesign Sep 25, 2019
80d4866
Update release notes
XECDesign Sep 25, 2019
8026d9d
Update changelog
XECDesign Oct 14, 2019
336ff21
Document how to get values for the localization values
matthijskooijman Oct 13, 2019
19c0188
Ensure debootstrap runs through 'sh' rather than 'bash'
XECDesign Oct 30, 2019
d30343f
Added hostname parameter
reneklootwijk Oct 26, 2019
95ba042
Add hostname to /etc/hosts
XECDesign Nov 6, 2019
a449c75
OS X does not have realpath (#342)
snoe925 Nov 11, 2019
7f143a1
Export base directory before loading config file (#347)
LCvanDinteren Nov 18, 2019
5e19033
Remove accidental trailing brace (#348)
LCvanDinteren Nov 18, 2019
5456c38
Explicitly check if postrun script exists in BASE_DIR (#351)
LCvanDinteren Nov 26, 2019
d7c1ae2
New types of images. (#352)
Nov 26, 2019
8bdbbfb
Added stage 5 to the text (#353)
Nov 27, 2019
18c3ceb
configure unprotected wifi when WPA_PASSWORD is unset (#357)
chrisdecker1201 Dec 5, 2019
32353a1
Updated info about stage4 and stage5 (#359)
Dec 9, 2019
9d15c0f
move picraft to stage where minecraft is installed (#362)
chrisdecker1201 Dec 12, 2019
271177a
Use tee with wpa_passphrase so errors are visable
samtygier Dec 23, 2019
0248400
Check WPA_PASSWORD length early
samtygier Dec 23, 2019
9d334be
WPA_PASSWORD length check should only occur if set
samtygier Jan 7, 2020
f9375cd
README.md - mention WPA_PASSWORD length requirement
Jan 8, 2020
f8f3d6f
capitalise Raspberry Pi
Jan 8, 2020
24bb01d
Rename HOSTNAME variable to TARGET_HOSTNAME
XECDesign Dec 5, 2019
0a6624b
Update ROOT_MARGIN
XECDesign Jan 24, 2020
ca31aef
stage5: install code-the-classics
XECDesign Jan 24, 2020
bdbd858
Update MagPi URL scheme
XECDesign Jan 27, 2020
b4ea63c
Update persistent rkfill files
XECDesign Jan 28, 2020
306c7eb
Update release notes
XECDesign Jan 27, 2020
87f7a59
Update release notes
XECDesign Feb 3, 2020
e577677
Update release notes
XECDesign Feb 5, 2020
6b72a64
Update release notes
XECDesign Feb 7, 2020
6d71ac0
Update release notes
XECDesign Feb 10, 2020
5f88437
Update release notes
XECDesign Feb 13, 2020
38d22e9
Retry apt downloads 3 times
luigifcruz Feb 20, 2020
65f91b8
BusyBox realpath does not support -s flag, fallback to use no flags (…
timvisee Feb 20, 2020
8ef3f47
Dockerfile: use --no-install-recommends in apt-get install (#383)
lpenz Feb 20, 2020
08fc0b9
Exposed RELEASE as a configurable variable (#391)
DragonForgedTheArtist Feb 26, 2020
b9bb59c
Bookshelf PDF download
XECDesign May 13, 2020
825107f
Update release notes
XECDesign May 13, 2020
f663d4c
Add new changelog entry
XECDesign Jun 22, 2020
9a3a10b
stage2: install raspinfo
XECDesign Jun 22, 2020
930d861
Update release notes
XECDesign Aug 20, 2020
78c9e2c
Raspbian -> Raspberry Pi OS
XECDesign Aug 24, 2020
d6207a6
Update OS.png
XECDesign Aug 24, 2020
c1a7dae
Enable adding SSH pubkey and setting pubkey only (#380)
Sep 8, 2020
d6ee1e5
Update README.md
Sep 16, 2020
be8daaa
Only disable wifi if WPA_COUNTRY is not set (#416)
rnestler Sep 18, 2020
d159645
workaround build failure on AWS M6g instances (#449)
Sep 23, 2020
dd96ca1
Automagically use i386/debian:buster (#415)
aniongithub Oct 6, 2020
4d5c78b
Solves merge conflicts
vpetersson Oct 20, 2020
69c4a4f
Removes file
vpetersson Oct 20, 2020
4786b2e
Removes another merge orphan
vpetersson Oct 20, 2020
6d3e477
Brings in more config changes and sets defaults.
vpetersson Oct 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
FROM debian:buster
ARG BASE_IMAGE=debian:buster
FROM ${BASE_IMAGE}

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get -y update && \
apt-get -y install \
apt-get -y install --no-install-recommends \
git vim parted \
quilt coreutils qemu-user-static debootstrap zerofree zip dosfstools \
bsdtar libcap2-bin rsync grep udev xz-utils curl xxd file kmod\
bsdtar libcap2-bin rsync grep udev xz-utils curl xxd file kmod bc\
binfmt-support ca-certificates \
&& rm -rf /var/lib/apt/lists/*

COPY . /pi-gen/
Expand Down
81 changes: 64 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# pi-gen

_Tool used to create the raspberrypi.org Raspbian images_
Tool used to create Raspberry Pi OS images. (Previously known as Raspbian).


## Dependencies

pi-gen runs on Debian based operating systems. Currently it is only supported on
pi-gen runs on Debian-based operating systems. Currently it is only supported on
either Debian Buster or Ubuntu Xenial and is known to have issues building on
earlier releases of these systems. On other Linux distributions it may be possible
to use the Docker build described below.

To install the required dependencies for pi-gen you should run:
To install the required dependencies for `pi-gen` you should run:

```bash
apt-get install coreutils quilt parted qemu-user-static debootstrap zerofree zip \
dosfstools bsdtar libcap2-bin grep rsync xz-utils file git curl
dosfstools bsdtar libcap2-bin grep rsync xz-utils file git curl bc
```

The file `depends` contains a list of tools needed. The format of this
Expand All @@ -36,6 +36,11 @@ The following environment variables are supported:
but you should use something else for a customized version. Export files
in stages may add suffixes to `IMG_NAME`.

* `RELEASE` (Default: buster)

The release version to build images against. Valid values are jessie, stretch
buster, bullseye, and testing.

* `APT_PROXY` (Default: unset)

If you require the use of an apt proxy, set it here. This proxy setting
Expand All @@ -62,8 +67,8 @@ The following environment variables are supported:
be built and cached. Note, `WORK_DIR` stores a complete copy of the target
system for each build stage, amounting to tens of gigabytes in the case of
Raspbian.
**CAUTION**: If your working directory is on an NTFS partition you probably won't be able to build. Make sure this is a proper Linux filesystem.

**CAUTION**: If your working directory is on an NTFS partition you probably won't be able to build: make sure this is a proper Linux filesystem.

* `DEPLOY_DIR` (Default: `"$BASE_DIR/deploy"`)

Expand All @@ -78,6 +83,37 @@ The following environment variables are supported:
Setting to '1' enables the QEMU mode - creating an image that can be mounted via QEMU for an emulated
environment. These images include "-qemu" in the image file name.

* `LOCALE_DEFAULT` (Default: "en_GB.UTF-8" )

Default system locale.

* `TARGET_HOSTNAME` (Default: "raspberrypi" )

Setting the hostname to the specified value.

* `KEYBOARD_KEYMAP` (Default: "gb" )

Default keyboard keymap.

To get the current value from a running system, run `debconf-show
keyboard-configuration` and look at the
`keyboard-configuration/xkb-keymap` value.

* `KEYBOARD_LAYOUT` (Default: "English (UK)" )

Default keyboard layout.

To get the current value from a running system, run `debconf-show
keyboard-configuration` and look at the
`keyboard-configuration/variant` value.

* `TIMEZONE_DEFAULT` (Default: "Europe/London" )

Default keyboard layout.

To get the current value from a running system, look in
`/etc/timezone`.

* `FIRST_USER_NAME` (Default: "pi" )

Username for the first user
Expand All @@ -88,11 +124,23 @@ The following environment variables are supported:

* `WPA_ESSID`, `WPA_PASSWORD` and `WPA_COUNTRY` (Default: unset)

If these are set, they are use to configure `wpa_supplicant.conf`, so that the raspberry pi can automatically connect to a wifi network on first boot.
If these are set, they are use to configure `wpa_supplicant.conf`, so that the Raspberry Pi can automatically connect to a wireless network on first boot. If `WPA_ESSID` is set and `WPA_PASSWORD` is unset an unprotected wireless network will be configured. If set, `WPA_PASSWORD` must be between 8 and 63 characters.

* `ENABLE_SSH` (Default: `0`)

Setting to `1` will enable ssh server for remote log in. Note that if you are using a common password such as the defaults there is a high risk of attackers taking over you RaspberryPi.
Setting to `1` will enable ssh server for remote log in. Note that if you are using a common password such as the defaults there is a high risk of attackers taking over you Raspberry Pi.

* `PUBKEY_SSH_FIRST_USER` (Default: unset)

Setting this to a value will make that value the contents of the FIRST_USER_NAME's ~/.ssh/authorized_keys. Obviously the value should
therefore be a valid authorized_keys file. Note that this does not
automatically enable SSH.

* `PUBKEY_ONLY_SSH` (Default: `0`)

* Setting to `1` will disable password authentication for SSH and enable
public key authentication. Note that if SSH is not enabled this will take
effect when SSH becomes enabled.

* `STAGE_LIST` (Default: `stage*`)

Expand Down Expand Up @@ -228,7 +276,7 @@ maintenance and allows for more easy customization.

- **Stage 2** - lite system. This stage produces the Raspbian-Lite image. It
installs some optimized memory functions, sets timezone and charmap
defaults, installs fake-hwclock and ntp, wifi and bluetooth support,
defaults, installs fake-hwclock and ntp, wireless LAN and bluetooth support,
dphys-swapfile, and other basics for managing the hardware. It also
creates necessary groups and gives the pi user access to sudo and the
standard console hardware permission groups.
Expand All @@ -246,22 +294,21 @@ maintenance and allows for more easy customization.
enhancements, etc. This is a base desktop system, with some development
tools installed.

- **Stage 4** - Raspbian system meant to fit on a 4GB card. More development
tools, an email client, learning tools like Scratch, specialized packages
like sonic-pi, system documentation, office productivity, etc. This is the
stage that installs all of the things that make Raspbian friendly to new
users.
- **Stage 4** - Normal Raspbian image. System meant to fit on a 4GB card. This is the
stage that installs most things that make Raspbian friendly to new
users like system documentation.

- **Stage 5** - The official Raspbian Desktop image. Right now only adds
Mathematica.
- **Stage 5** - The Raspbian Full image. More development
tools, an email client, learning tools like Scratch, specialized packages
like sonic-pi, office productivity, etc.

### Stage specification

If you wish to build up to a specified stage (such as building up to stage 2
for a lite system), place an empty file named `SKIP` in each of the `./stage`
directories you wish not to include.

Then add an empty file named `SKIP_IMAGES` to `./stage4` (if building up to stage 2) or
Then add an empty file named `SKIP_IMAGES` to `./stage4` and `./stage5` (if building up to stage 2) or
to `./stage2` (if building a minimal system).

```bash
Expand Down
48 changes: 33 additions & 15 deletions build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ while getopts "c:" flag; do
done

# Ensure that the configuration file is an absolute path
CONFIG_FILE=$(realpath -s "$CONFIG_FILE")
if test -x /usr/bin/realpath; then
CONFIG_FILE=$(realpath -s "$CONFIG_FILE" || realpath "$CONFIG_FILE")
fi

# Ensure that the confguration file is present
if test -z "${CONFIG_FILE}"; then
echo "Configuration file need to be present in '${DIR}/config' or path passed as parameter"
exit 1
else
# shellcheck disable=SC1090
source "${CONFIG_FILE}"
# shellcheck disable=SC1090
source ${CONFIG_FILE}
fi

CONTAINER_NAME=${CONTAINER_NAME:-pigen_work}
Expand All @@ -51,6 +53,9 @@ if [ -z "${IMG_NAME}" ]; then
exit 1
fi

# Ensure the Git Hash is recorded before entering the docker container
GIT_HASH=${GIT_HASH:-"$(git rev-parse HEAD)"}

CONTAINER_EXISTS=$(${DOCKER} ps -a --filter name="${CONTAINER_NAME}" -q)
CONTAINER_RUNNING=$(${DOCKER} ps --filter name="${CONTAINER_NAME}" -q)
if [ "${CONTAINER_RUNNING}" != "" ]; then
Expand All @@ -67,23 +72,36 @@ fi
# Modify original build-options to allow config file to be mounted in the docker container
BUILD_OPTS="$(echo "${BUILD_OPTS:-}" | sed -E 's@\-c\s?([^ ]+)@-c /config@')"

${DOCKER} build -t pi-gen "${DIR}"
# Check the arch of the machine we're running on. If it's 64-bit, use a 32-bit base image instead
case "$(uname -m)" in
x86_64|aarch64)
BASE_IMAGE=i386/debian:buster
;;
*)
BASE_IMAGE=debian:buster
;;
esac
${DOCKER} build --build-arg BASE_IMAGE=${BASE_IMAGE} -t pi-gen "${DIR}"

if [ "${CONTAINER_EXISTS}" != "" ]; then
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}_cont' SIGINT SIGTERM
time ${DOCKER} run --rm --privileged \
--volume "${CONFIG_FILE}":/config:ro \
--volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \
pi-gen \
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}_cont' SIGINT SIGTERM
time ${DOCKER} run --rm --privileged \
--volume "${CONFIG_FILE}":/config:ro \
-e "GIT_HASH=${GIT_HASH}" \
--volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \
pi-gen \
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&

cd /pi-gen; ./build.sh ${BUILD_OPTS} &&
rsync -av work/*/build.log deploy/" &
wait "$!"
else
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}' SIGINT SIGTERM
time ${DOCKER} run --name "${CONTAINER_NAME}" --privileged \
--volume "${CONFIG_FILE}":/config:ro \
pi-gen \
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}' SIGINT SIGTERM
time ${DOCKER} run --name "${CONTAINER_NAME}" --privileged \
--volume "${CONFIG_FILE}":/config:ro \
-e "GIT_HASH=${GIT_HASH}" \
pi-gen \
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
cd /pi-gen; ./build.sh ${BUILD_OPTS} &&
rsync -av work/*/build.log deploy/" &
wait "$!"
Expand Down
75 changes: 50 additions & 25 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ $(cat "${i}-debconf")
SELEOF
EOF

log "End ${SUB_STAGE_DIR}/${i}-debconf"
fi
if [ -f "${i}-packages-nr" ]; then
log "Begin ${SUB_STAGE_DIR}/${i}-packages-nr"
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" <"${i}-packages-nr")"
if [ -n "$PACKAGES" ]; then
on_chroot <<EOF
apt-get install --no-install-recommends -y $PACKAGES
log "End ${SUB_STAGE_DIR}/${i}-debconf"
fi
if [ -f "${i}-packages-nr" ]; then
log "Begin ${SUB_STAGE_DIR}/${i}-packages-nr"
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${i}-packages-nr")"
if [ -n "$PACKAGES" ]; then
on_chroot << EOF
apt-get -o APT::Acquire::Retries=3 install --no-install-recommends -y $PACKAGES
EOF
fi
log "End ${SUB_STAGE_DIR}/${i}-packages-nr"
fi
if [ -f "${i}-packages" ]; then
log "Begin ${SUB_STAGE_DIR}/${i}-packages"
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" <"${i}-packages")"
if [ -n "$PACKAGES" ]; then
on_chroot <<EOF
apt-get install -y $PACKAGES
fi
log "End ${SUB_STAGE_DIR}/${i}-packages-nr"
fi
if [ -f "${i}-packages" ]; then
log "Begin ${SUB_STAGE_DIR}/${i}-packages"
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${i}-packages")"
if [ -n "$PACKAGES" ]; then
on_chroot << EOF
apt-get -o APT::Acquire::Retries=3 install -y $PACKAGES
EOF
fi
log "End ${SUB_STAGE_DIR}/${i}-packages"
Expand Down Expand Up @@ -120,6 +120,9 @@ if [ "$(id -u)" != "0" ]; then
exit 1
fi

BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export BASE_DIR

if [ -f config ]; then
# shellcheck disable=SC1091
source config
Expand All @@ -138,7 +141,7 @@ while getopts "c:" flag; do
done

export PI_GEN=${PI_GEN:-pi-gen}
export PI_GEN_REPO=${PI_GEN_REPO:-https://github.com/RPi-Distro/pi-gen}
export PI_GEN_REPO=${PI_GEN_REPO:-https://github.com/Screenly/pi-gen}

if [ -z "${IMG_NAME}" ]; then
echo "IMG_NAME not set" 1>&2
Expand All @@ -160,21 +163,33 @@ export IMG_DATE="${IMG_DATE:-"$(date +%Y-%m-%d)"}"
export IMG_FILENAME="${IMG_FILENAME:-"${IMG_DATE}-${IMG_NAME}"}"
export ZIP_FILENAME="${ZIP_FILENAME:-"image_${IMG_DATE}-${IMG_NAME}"}"

BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export SCRIPT_DIR="${BASE_DIR}/scripts"
export WORK_DIR="${WORK_DIR:-"${BASE_DIR}/work/${IMG_DATE}-${IMG_NAME}"}"
export DEPLOY_DIR=${DEPLOY_DIR:-"${BASE_DIR}/deploy"}
export DEPLOY_ZIP="${DEPLOY_ZIP:-1}"
export LOG_FILE="${WORK_DIR}/build.log"

export TARGET_HOSTNAME=${TARGET_HOSTNAME:-raspberrypi}

export FIRST_USER_NAME=${FIRST_USER_NAME:-pi}
export FIRST_USER_PASS=${FIRST_USER_PASS:-raspberry}
export RELEASE=${RELEASE:-buster}
export WPA_ESSID
export WPA_PASSWORD
export WPA_COUNTRY
export ENABLE_SSH="${ENABLE_SSH:-0}"
export PUBKEY_ONLY_SSH="${PUBKEY_ONLY_SSH:-0}"

export BASE_DIR
export LOCALE_DEFAULT="${LOCALE_DEFAULT:-en_US.UTF-8}"

export KEYBOARD_KEYMAP="${KEYBOARD_KEYMAP:-us}"
export KEYBOARD_LAYOUT="${KEYBOARD_LAYOUT:-English (US)}"

export TIMEZONE_DEFAULT="${TIMEZONE_DEFAULT:-Europe/London}"

export GIT_HASH=${GIT_HASH:-"$(git rev-parse HEAD)"}

export PUBKEY_SSH_FIRST_USER

export CLEAN
export IMG_NAME
Expand Down Expand Up @@ -218,6 +233,16 @@ if [[ -n "${APT_PROXY}" ]] && ! curl --silent "${APT_PROXY}" >/dev/null; then
exit 1
fi

if [[ -n "${WPA_PASSWORD}" && ${#WPA_PASSWORD} -lt 8 || ${#WPA_PASSWORD} -gt 63 ]] ; then
echo "WPA_PASSWORD" must be between 8 and 63 characters
exit 1
fi

if [[ "${PUBKEY_ONLY_SSH}" = "1" && -z "${PUBKEY_SSH_FIRST_USER}" ]]; then
echo "Must set 'PUBKEY_SSH_FIRST_USER' to a valid SSH public key if using PUBKEY_ONLY_SSH"
exit 1
fi

mkdir -p "${WORK_DIR}"
log "Begin ${BASE_DIR}"

Expand Down Expand Up @@ -245,11 +270,11 @@ for EXPORT_DIR in ${EXPORT_DIRS}; do
fi
done

if [ -x postrun.sh ]; then
log "Begin postrun.sh"
cd "${BASE_DIR}"
./postrun.sh
log "End postrun.sh"
if [ -x ${BASE_DIR}/postrun.sh ]; then
log "Begin postrun.sh"
cd "${BASE_DIR}"
./postrun.sh
log "End postrun.sh"
fi

log "End ${BASE_DIR}"
6 changes: 6 additions & 0 deletions config
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
IMG_NAME='Screenly-OSE'
REPOSITORY='https://github.com/Screenly/screenly-ose.git'
BRANCH='production'
LOCALE_DEFAULT=en_US.UTF-8
TARGET_HOSTNAME=screenly-ose
KEYBOARD_KEYMAP=us
KEYBOARD_LAYOUT="English (US)"
STAGE_LIST="stage0 stage1"

1 change: 1 addition & 0 deletions depends
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ xxd
file
git
lsmod:kmod
bc
Loading