Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into sync_with_upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
HLXEasy committed Oct 15, 2020
2 parents f5f604c + dd96ca1 commit fa87b1d
Show file tree
Hide file tree
Showing 31 changed files with 293 additions and 77 deletions.
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/*

RUN echo 'deb http://http.debian.net/debian stretch-backports main' > /etc/apt/sources.list.d/stretch-backports-main.list \
Expand Down
63 changes: 47 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pi-gen

_Tool used to create the raspberrypi.org Raspbian images, containing [Spectrecoin](https://spectreproject.io/) daemon_
Tool used to create Raspberry Pi OS images (Previously known as Raspbian), containing Alias wallet daemon.

## Changes and additions for Alias

Expand All @@ -24,16 +24,16 @@ On stage 3 the Aliaswallet image will be created. For this the following steps w

## 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 @@ -55,6 +55,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 Down Expand Up @@ -82,7 +87,7 @@ The following environment variables are supported:
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 @@ -101,18 +106,33 @@ The following environment variables are supported:

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 @@ -123,11 +143,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 @@ -263,7 +295,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 @@ -281,22 +313,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
18 changes: 15 additions & 3 deletions build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ 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}"
source ${CONFIG_FILE}
fi

CONTAINER_NAME=${CONTAINER_NAME:-pigen_work}
Expand Down Expand Up @@ -71,7 +73,17 @@ 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 \
Expand Down
25 changes: 20 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ EOF
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
apt-get -o APT::Acquire::Retries=3 install --no-install-recommends -y $PACKAGES
EOF
fi
log "End ${SUB_STAGE_DIR}/${i}-packages-nr"
Expand All @@ -30,7 +30,7 @@ EOF
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${i}-packages")"
if [ -n "$PACKAGES" ]; then
on_chroot << EOF
apt-get install -y $PACKAGES
apt-get -o APT::Acquire::Retries=3 install -y $PACKAGES
EOF
fi
log "End ${SUB_STAGE_DIR}/${i}-packages"
Expand Down Expand Up @@ -122,6 +122,8 @@ 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
Expand Down Expand Up @@ -154,19 +156,22 @@ 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 LOCALE_DEFAULT="${LOCALE_DEFAULT:-en_GB.UTF-8}"

Expand All @@ -177,7 +182,7 @@ export TIMEZONE_DEFAULT="${TIMEZONE_DEFAULT:-Europe/London}"

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

export BASE_DIR
export PUBKEY_SSH_FIRST_USER

export CLEAN
export IMG_NAME
Expand Down Expand Up @@ -219,6 +224,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 @@ -246,7 +261,7 @@ for EXPORT_DIR in ${EXPORT_DIRS}; do
fi
done

if [ -x postrun.sh ]; then
if [ -x ${BASE_DIR}/postrun.sh ]; then
log "Begin postrun.sh"
cd "${BASE_DIR}"
./postrun.sh
Expand Down
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
30 changes: 27 additions & 3 deletions export-image/prerun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ALIGN="$((4 * 1024 * 1024))"
# some overhead (since actual space usage is usually rounded up to the
# filesystem block size) and gives some free space on the resulting
# image.
ROOT_MARGIN=$((800*1024*1024))
ROOT_MARGIN="$(echo "($ROOT_SIZE * 0.2 + 200 * 1024 * 1024) / 1" | bc)"

BOOT_PART_START=$((ALIGN))
BOOT_PART_SIZE=$(((BOOT_SIZE + ALIGN - 1) / ALIGN * ALIGN))
Expand All @@ -39,8 +39,32 @@ BOOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^1:' | cut -d':' -f 4 | tr -d B)
ROOT_OFFSET=$(echo "$PARTED_OUT" | grep -e '^2:' | cut -d':' -f 2 | tr -d B)
ROOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^2:' | cut -d':' -f 4 | tr -d B)

BOOT_DEV=$(LOOPDEV_DEBUG=all losetup --show -f -o "${BOOT_OFFSET}" --sizelimit "${BOOT_LENGTH}" "${IMG_FILE}")
ROOT_DEV=$(LOOPDEV_DEBUG=all losetup --show -f -o "${ROOT_OFFSET}" --sizelimit "${ROOT_LENGTH}" "${IMG_FILE}")
echo "Mounting BOOT_DEV..."
cnt=0
until BOOT_DEV=$(losetup --show -f -o "${BOOT_OFFSET}" --sizelimit "${BOOT_LENGTH}" "${IMG_FILE}"); do
if [ $cnt -lt 5 ]; then
cnt=$((cnt + 1))
echo "Error in losetup for BOOT_DEV. Retrying..."
sleep 5
else
echo "ERROR: losetup for BOOT_DEV failed; exiting"
exit 1
fi
done

echo "Mounting ROOT_DEV..."
cnt=0
until ROOT_DEV=$(losetup --show -f -o "${ROOT_OFFSET}" --sizelimit "${ROOT_LENGTH}" "${IMG_FILE}"); do
if [ $cnt -lt 5 ]; then
cnt=$((cnt + 1))
echo "Error in losetup for ROOT_DEV. Retrying..."
sleep 5
else
echo "ERROR: losetup for ROOT_DEV failed; exiting"
exit 1
fi
done

echo "/boot: offset $BOOT_OFFSET, length $BOOT_LENGTH"
echo "/: offset $ROOT_OFFSET, length $ROOT_LENGTH"

Expand Down
1 change: 1 addition & 0 deletions export-noobs/00-release/00-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ sed "${NOOBS_DIR}/partitions.json" -i -e "s|ROOT_NOM|${ROOT_NOM}|"
sed "${NOOBS_DIR}/os.json" -i -e "s|UNRELEASED|${IMG_DATE}|"
sed "${NOOBS_DIR}/os.json" -i -e "s|NOOBS_NAME|${NOOBS_NAME}|"
sed "${NOOBS_DIR}/os.json" -i -e "s|NOOBS_DESCRIPTION|${NOOBS_DESCRIPTION}|"
sed "${NOOBS_DIR}/os.json" -i -e "s|RELEASE|${RELEASE}|"

sed "${NOOBS_DIR}/release_notes.txt" -i -e "s|UNRELEASED|${IMG_DATE}|"

Expand Down
Binary file modified export-noobs/00-release/files/OS.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion export-noobs/00-release/files/os.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
],
"url": "http://www.raspbian.org/",
"username": "pi",
"version": "buster"
"version": "RELEASE"
}
Loading

0 comments on commit fa87b1d

Please sign in to comment.