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 and 1.9.4 upgrade + bugfixes #2

Open
wants to merge 147 commits into
base: grassbian
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
d6c238c
Update release notes
XECDesign Apr 17, 2018
1f51b8b
stage3: switch from xpdf to qpdfview
XECDesign Apr 24, 2018
4a5ecb6
export-noobs: bump kernel version in os.json
XECDesign Apr 24, 2018
df156f0
stage1: add missing netbase package to the net-tweaks sub stage
hhromic May 7, 2018
9d76d3a
stage2: clean unused/obsolete patch (#187)
hhromic Jun 4, 2018
fea9e29
export-image: clean additional backup files (#186)
hhromic Jun 4, 2018
8d9cfb3
stage0: add missing raspberrypi-kernel package to the firmware sub st…
hhromic Jun 4, 2018
1445894
stage4: Add piwiz and rp-prefapps
XECDesign Jun 5, 2018
3c3528a
stage5: add latest MagPi issue
XECDesign Jun 7, 2018
8e7faf7
stage4: install libreoffice-pi instead of libreoffice
XECDesign Jun 15, 2018
0d34fb9
Update release notes
XECDesign Apr 24, 2018
3478063
Release notes: Fix typo, bump header
XECDesign Jul 3, 2018
8e898a6
depends: add 'file'
XECDesign Jul 3, 2018
07bb3bd
depends: add 'git'
XECDesign Jul 3, 2018
568cfb0
Adding file to packages (#196)
KalleDK Jul 6, 2018
99e43ea
stage4: add libav-tools
XECDesign Jul 9, 2018
02e4c73
Add localisation packages
XECDesign Jul 13, 2018
330ce73
added Troubleshooting section to README.md, and addressed binfmt_misc…
attie Aug 3, 2018
6000d58
stage2: accept Mathematica EULA here instead of stage5
XECDesign Jul 31, 2018
37da684
stage2: Set default timezone to 'London'
XECDesign Sep 10, 2018
1133934
export-noobs: keep 'quiet' in cmdline.txt
XECDesign Sep 24, 2018
42279ee
Update release notes
XECDesign Sep 11, 2018
59cd0a3
stage2: add ssh-import-id
XECDesign Oct 4, 2018
7b40fd1
Remove Mathematica
XECDesign Oct 9, 2018
378a2bd
stage2: remove left-over debconf file
XECDesign Oct 11, 2018
7ccf818
Remove /debootstrap
XECDesign Oct 11, 2018
33e94c4
stage2: set timezone properly
XECDesign Oct 11, 2018
f8b629d
Check /debootstrap exists before trying to remove
XECDesign Oct 15, 2018
c9b658e
Add curl to apt-get script in README
kr15h Oct 20, 2018
4fc1423
scripts: do not ignore errors inside on_chroot calls
Nov 7, 2018
cbe273b
Add extra packages back and create a 4GB image
XECDesign Oct 17, 2018
6ffcafe
Update release notes
XECDesign Oct 17, 2018
181218e
Install libreoffice with all recommended packages
XECDesign Oct 29, 2018
0f7e3de
export-noobs: fix units
XECDesign Oct 30, 2018
7e0c786
stage4: add vlc
XECDesign Nov 6, 2018
980bdb9
Update release notes
XECDesign Nov 14, 2018
d1b7477
Add PINN restore support
XECDesign Dec 11, 2018
d07096e
Allow setting user name and password from config
samtygier Dec 9, 2018
f4dc2dc
Allow setting up wifi from config
samtygier Dec 17, 2018
cc66056
Allow enabling ssh server from config
samtygier Dec 18, 2018
7fbfdda
Add commandline argument for config file
samtygier Dec 18, 2018
08405eb
Allow custom image filename
bjsowa Dec 17, 2018
d7ca8e8
Allow custom deploy zip filename
bjsowa Dec 19, 2018
d7ef46b
Allow custom stages
samtygier Jan 6, 2019
189b8f0
Fixed a hard reference to the 'pi' user name
rkubes Jan 14, 2019
3b1d051
Fixed another hard reference to the 'pi' user name
m-roberts Jan 15, 2019
640027d
build script is build.sh
gudata Jan 20, 2019
21aeca1
fixeb package realpath (via coreutils)
k0rventen Jan 18, 2019
d88f536
IMG_SUFFIX evaluation in export image (fix #241)
bjsowa Jan 21, 2019
9714a11
Add username validation
samtygier Jan 5, 2019
c72f0b4
Quote wpa wifi variables
samtygier Jan 5, 2019
d945d42
Update 00-run.sh
XECDesign Jan 23, 2019
61a994c
Add a DEPLOY_ZIP setting
LouisMT Jan 30, 2019
3961bff
Decrease zerofree verbosity
LouisMT Jan 30, 2019
3b90b7f
Improve bootstrap() function in common script
hhromic Feb 15, 2019
9e6af47
Improve update_issue() function in common script
hhromic Feb 15, 2019
c147df9
Ensure extra config file is passed to docker
samtygier Feb 16, 2019
a8eb03a
Check binfmt_misc module is loaded
samtygier Feb 16, 2019
82bcfa4
Use different rsync options for boot and root
samtygier Feb 17, 2019
9d38bfa
README.md: Add more info on Docker
samtygier Feb 17, 2019
7068086
Make sure unmount_image finds stale loop devices
samtygier Feb 16, 2019
564f8ef
Silence shellcheck warnings (#255)
hhromic Feb 18, 2019
b781227
Warn early if proxy not reachable (#262)
samtygier Feb 18, 2019
67241b9
Handle cases where binfmt_misc is built into the kernel
XECDesign Mar 6, 2019
91bc38d
Update Dockerfile
XECDesign Mar 11, 2019
fb23b8b
Replace pxz with xz -T0
XECDesign Mar 11, 2019
30a1528
Switch to using parted's machine parseable output (#270)
lurch Mar 18, 2019
3e9b176
stage2: install rng-tools
XECDesign Mar 29, 2019
ee11b80
stage2: ethtool
XECDesign Mar 27, 2019
e910bf5
Update release notes
XECDesign Apr 2, 2019
042f769
Add new changelog entry
XECDesign Apr 17, 2019
407663a
Silence shellcheck warnings (#279)
hhromic Apr 25, 2019
8acf95f
Do not assume the changelog file is always present for the info file …
hhromic Apr 25, 2019
4ad5196
Better docs for STAGE_LIST (#289)
samtygier May 30, 2019
a90b6bd
build.sh: run quilt upgrade before editing patches
XECDesign Jun 7, 2019
0552ef2
Update to Buster
XECDesign Jun 7, 2019
22c8878
Remove Oracle Java
XECDesign Jun 7, 2019
0308e92
export-image: Set /boot size to 256MB
XECDesign Jun 7, 2019
d7aa47e
os_list: add checksums for PINN
XECDesign Jun 7, 2019
7e3b160
os_list: add Pi 4 support
XECDesign Jun 7, 2019
9005ba0
os_list: Bump kernel to 4.19
XECDesign Jun 7, 2019
17ef760
config.txt: Enable FKMS and set max_framebuffers=2 in [pi4]
XECDesign Jun 7, 2019
33dfe54
stage4: remove timidity
XECDesign Jun 7, 2019
ba8909f
partition_setup.sh: Fix cmdline.txt handling
XECDesign Jun 7, 2019
e14a403
stage2: Disable wifi on 5GHz models
XECDesign Jun 7, 2019
f86cb0d
script/common: Handle aarch64 host builds
XECDesign Jun 7, 2019
0b4d95c
stage4: enable xcompmgr
XECDesign Jun 7, 2019
3682a74
Java 8 workaround
XECDesign Jun 7, 2019
a3c76f3
Replace IDLE with Thonny in stage 4 and add Mu to stage 5
XECDesign Jun 7, 2019
6b78e86
stage3: include arandr
XECDesign Jun 7, 2019
1ffc374
Fix Buster packages
XECDesign Jun 7, 2019
73fc146
stage5: Remove wolfram-engine until Buster version is available
XECDesign Jun 7, 2019
265f342
stage4: fix autologin
XECDesign Jun 7, 2019
afeea46
export-image: remove /etc/network/interfaces.dpkg-old
XECDesign Jun 7, 2019
0cdec86
Disable ld.so.preload while building
XECDesign Jun 7, 2019
d942d54
export-noobs: update OS.png
XECDesign Jun 7, 2019
e5310d6
stage5: install greenfoot-unbundled
XECDesign Jun 17, 2019
150e25c
Revert "Java 8 workaround"
XECDesign Jun 17, 2019
a4be08e
Update release notes
XECDesign Jun 21, 2019
cf50ff2
Update Dockerfile base image to Debian Buster (#295)
hhromic Jun 27, 2019
3c559ae
64 bit message (#298)
ryanteck Jun 28, 2019
4ca539c
Fix build.sh to run dependencies_check prior to using curl. (#299)
rkubes Jul 1, 2019
3db1168
Remove obsolete IPv6 turnoff (#300)
oskar456 Jul 1, 2019
57ef9b8
stage2/00-copies-and-fills/02-run.sh: Fix re-runs of script (#301)
xranby Jul 2, 2019
ae4ec64
build-docker.sh does not assume PWD=<repo root> (#302)
macisamuele Jul 2, 2019
fd21eff
README.md shouldn’t be executable (#303)
gszy Jul 3, 2019
1143530
Revert "stage2: Add apt-transport-https" (#304)
gszy Jul 3, 2019
4118f8d
stage5: Add Mathematica
XECDesign Jul 8, 2019
3748227
stage2: Add vl805fw
XECDesign Jul 8, 2019
175dfb0
Update release notes
XECDesign Jul 8, 2019
4c575d7
Add missing release notes
XECDesign Jul 10, 2019
210b51c
stage3: remove Epiphany
XECDesign Jul 10, 2019
9c0a25d
stage2: add ntfs-3g
XECDesign Jul 18, 2019
c0714e3
Update Stretch to Buster in README (#310)
132ikl Jul 23, 2019
5436273
Make build_docker.sh portable again (#308)
hilli Jul 23, 2019
920e22b
Ensure that the configuration file is an absolute path in Docker buil…
hhromic Jul 30, 2019
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
660ea88
Fix broken paths and upgrade gg
Nov 12, 2019
deb0ea5
Revert and skip original stages from pi-gen
Nov 13, 2019
5743ff3
Merge remote-tracking branch 'upstream/master' into buster-upgrade
Nov 13, 2019
3a27a3a
Fix image description after merge
Nov 13, 2019
dfbf1e6
Use recommended default AWS certificate
Nov 13, 2019
b3a1bcf
Allow to build Lite and Full versions
Nov 13, 2019
fae804f
Fix systemd service file
Nov 13, 2019
d434cc5
Note how to build own image
Nov 13, 2019
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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ deploy/*
work/*
config
postrun.sh
SKIP
SKIP_IMAGES
.pc
*-pc
apt-cacher-ng/
14 changes: 14 additions & 0 deletions BUILD-GREENGRASS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# How to build custom Grassbian image?

Place create `./config` file. The sensible minimal one might look like
the following:

```
IMG_NAME=CustomGrassbian
HOSTNAME=grassbian
```

`HOSTNAME` is optional but it will be randomly-generated otherwise.

If interested in building a full desktop version please remove `SKIP`
and `SKIP_IMAGES` files from all stages.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM debian:stretch
FROM debian:buster

ENV DEBIAN_FRONTEND noninteractive

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

COPY . /pi-gen/
Expand Down
114 changes: 108 additions & 6 deletions README.md
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Grassbian Users

[use this guide](./SETUP-GREENGRASS.md) to get started
* [Get started](./SETUP-GREENGRASS.md)
* [Build own image](./BUILD-GREENGRASS.md)

# pi-gen

Expand All @@ -10,14 +11,15 @@ _Tool used to create the raspberrypi.org Raspbian images_
## Dependencies

pi-gen runs on Debian based operating systems. Currently it is only supported on
either Debian Stretch or Ubuntu Xenial and is known to have issues building on
earlier releases of these systems.
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:

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

The file `depends` contains a list of tools needed. The format of this
Expand Down Expand Up @@ -65,25 +67,86 @@ 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.

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

Output directory for target system images and NOOBS bundles.

* `DEPLOY_ZIP` (Default: `1`)

Setting to `0` will deploy the actual image (`.img`) instead of a zipped image (`.zip`).

* `USE_QEMU` (Default: `"0"`)

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.

* `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

* `FIRST_USER_PASS` (Default: "raspberry")

Password for the first user

* `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.

* `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.

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

If set, then instead of working through the numeric stages in order, this list will be followed. For example setting to `"stage0 stage1 mystage stage2"` will run the contents of `mystage` before stage2. Note that quotes are needed around the list. An absolute or relative path can be given for stages outside the pi-gen directory.

A simple example for building Raspbian:

```bash
IMG_NAME='Raspbian'
```

The config file can also be specified on the command line as an argument the `build.sh` or `build-docker.sh` scripts.

```
./build.sh -c myconfig
```

This is parsed after `config` so can be used to override values set there.

## How the build process works

Expand Down Expand Up @@ -132,6 +195,13 @@ It is recommended to examine build.sh for finer details.

## Docker Build

Docker can be used to perform the build inside a container. This partially isolates
the build from the host system, and allows using the script on non-debian based
systems (e.g. Fedora Linux). The isolate is not complete due to the need to use
some kernel level services for arm emulation (binfmt) and loop devices (losetup).

To build:

```bash
vi config # Edit your config file. See above.
./build-docker.sh
Expand All @@ -147,6 +217,12 @@ continue:
CONTINUE=1 ./build-docker.sh
```

To examine the container after a failure you can enter a shell within it using:

```bash
sudo docker run -it --privileged --volumes-from=pigen_work pi-gen /bin/bash
```

After successful build, the build container is by default removed. This may be undesired when making incremental changes to a customized build. To prevent the build script from remove the container add

```bash
Expand Down Expand Up @@ -253,3 +329,29 @@ follows:
* Once you're happy with the image you can remove the SKIP_IMAGES files and
export your image to test

# Troubleshooting

## `64 Bit Systems`
Please note there is currently an issue when compiling with a 64 Bit OS. See https://github.com/RPi-Distro/pi-gen/issues/271

## `binfmt_misc`

Linux is able execute binaries from other architectures, meaning that it should be
possible to make use of `pi-gen` on an x86_64 system, even though it will be running
ARM binaries. This requires support from the [`binfmt_misc`](https://en.wikipedia.org/wiki/Binfmt_misc)
kernel module.

You may see the following error:

```
update-binfmts: warning: Couldn't load the binfmt_misc module.
```

To resolve this, ensure that the following files are available (install them if necessary):

```
/lib/modules/$(uname -r)/kernel/fs/binfmt_misc.ko
/usr/bin/qemu-arm-static
```

You may also need to load the module by hand - run `modprobe binfmt_misc`.
3 changes: 2 additions & 1 deletion SETUP-GREENGRASS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ You can get the latest image [here](https://github.com/iopipe/pi-gen-greengrass/
2. Burn the image
3. Eject and re-insert the card, go into the mounted drive partition (boot partition for Linux afficionados)
4. Copy the certs/ and config/ folders from the .tar.gz you recieved when you created a greengrass core into the boot partition in the greengrass folder
5. If default AWS certificate (*Amazon Root CA 1*) is not suitable please copy the one used into the boot partition in `greengrass/certs` folder
6. (optional) Add a file titled `ssh` with no extension if you want to ssh into your raspberry pi
7. (optional) [Set up WiFi headlessly](https://www.raspberrypi.org/documentation/configuration/wireless/headless.md)
7. Eject sd and place it into raspberry pi and apply power to pi
8. If you haven't set wifi up on the SD card, [do so now](https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md) with an attached keybeard and mouse. Otherwise, you can ssh in if you completed the ssh and headless wifi step.
8. On the Pi, after boot, run `sudo systemctl status greengrass.service` to ensure greengrass service has booted and is running
9. If not, `sudo systemctl stop greengrass.service` and `cd /greengrass/ggc/core/`, then `./greengrassd` to see output from startup sequences for troubleshooting
9. If not, `sudo systemctl stop greengrass.service` and `cd /greengrass/ggc/core/`, then `./greengrassd` to see output from startup sequences for troubleshooting
114 changes: 68 additions & 46 deletions build-docker.sh
Original file line number Diff line number Diff line change
@@ -1,86 +1,108 @@
#!/bin/bash -e
#!/bin/bash -eu
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

BUILD_OPTS="$*"

DOCKER="docker"
set +e
$DOCKER ps >/dev/null 2>&1
if [ $? != 0 ]; then

if ! ${DOCKER} ps >/dev/null 2>&1; then
DOCKER="sudo docker"
fi
if ! $DOCKER ps >/dev/null; then
if ! ${DOCKER} ps >/dev/null; then
echo "error connecting to docker:"
$DOCKER ps
${DOCKER} ps
exit 1
fi
set -e

config_file=()
if [ -f config ]; then
config_file=("--env-file" "$(pwd)/config")
source config
CONFIG_FILE=""
if [ -f "${DIR}/config" ]; then
CONFIG_FILE="${DIR}/config"
fi

while getopts "c:" flag
do
case "${flag}" in
c)
CONFIG_FILE="${OPTARG}"
;;
*)
;;
esac
done

# Ensure that the configuration file is an absolute path
if test -x /usr/bin/realpath; then
CONFIG_FILE=$(realpath -s "$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}"
fi

CONTAINER_NAME=${CONTAINER_NAME:-pigen_work}
CONTINUE=${CONTINUE:-0}
PRESERVE_CONTAINER=${PRESERVE_CONTAINER:-0}

if [ "$*" != "" ] || [ -z "${IMG_NAME}" ]; then
if [ -z "${IMG_NAME}" ]; then
echo "IMG_NAME not set in 'config'" 1>&2
echo 1>&2
fi
cat >&2 <<EOF
Usage:
build-docker.sh [options]
Optional environment arguments: ( =<default> )
CONTAINER_NAME=pigen_work set a name for the build container
CONTINUE=1 continue from a previously started container
PRESERVE_CONTAINER=1 keep build container even on successful build
EOF
exit 1
if [ -z "${IMG_NAME}" ]; then
echo "IMG_NAME not set in 'config'" 1>&2
echo 1>&2
exit 1
fi

CONTAINER_EXISTS=$($DOCKER ps -a --filter name="$CONTAINER_NAME" -q)
CONTAINER_RUNNING=$($DOCKER ps --filter name="$CONTAINER_NAME" -q)
if [ "$CONTAINER_RUNNING" != "" ]; then
echo "The build is already running in container $CONTAINER_NAME. Aborting."
# 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
echo "The build is already running in container ${CONTAINER_NAME}. Aborting."
exit 1
fi
if [ "$CONTAINER_EXISTS" != "" ] && [ "$CONTINUE" != "1" ]; then
echo "Container $CONTAINER_NAME already exists and you did not specify CONTINUE=1. Aborting."
if [ "${CONTAINER_EXISTS}" != "" ] && [ "${CONTINUE}" != "1" ]; then
echo "Container ${CONTAINER_NAME} already exists and you did not specify CONTINUE=1. Aborting."
echo "You can delete the existing container like this:"
echo " $DOCKER rm -v $CONTAINER_NAME"
echo " ${DOCKER} rm -v ${CONTAINER_NAME}"
exit 1
fi

$DOCKER build -t pi-gen .
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 \
# 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}"
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 \
-e "GIT_HASH=${GIT_HASH}" \
--volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \
-e IMG_NAME="${IMG_NAME}"\
pi-gen \
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
cd /pi-gen; ./build.sh;
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 \
-e IMG_NAME="${IMG_NAME}"\
"${config_file[@]}" \
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 &&
cd /pi-gen; ./build.sh ${BUILD_OPTS} &&
rsync -av work/*/build.log deploy/" &
wait "$!"
fi
echo "copying results from deploy/"
$DOCKER cp "${CONTAINER_NAME}":/pi-gen/deploy .
${DOCKER} cp "${CONTAINER_NAME}":/pi-gen/deploy .
ls -lah deploy

# cleanup
if [ "$PRESERVE_CONTAINER" != "1" ]; then
$DOCKER rm -v $CONTAINER_NAME
if [ "${PRESERVE_CONTAINER}" != "1" ]; then
${DOCKER} rm -v "${CONTAINER_NAME}"
fi

echo "Done! Your image(s) should be in deploy/"
Loading