From c15fc69be31537bfce516c85db6b28547e0f9459 Mon Sep 17 00:00:00 2001 From: Adam Sax Date: Wed, 11 Mar 2020 10:41:47 -0400 Subject: [PATCH] initial implementation --- Dockerfile | 16 +- LICENSE | 25 ++ README.md | 384 ++---------------- build-docker.sh | 111 ++--- build.sh | 8 +- docs/customization.md | 297 ++++++++++++++ export-noobs/00-release/00-run.sh | 6 +- export-noobs/prerun.sh | 2 +- scripts/common | 2 +- stage2/01-sys-tweaks/01-run.sh | 8 + stage2/01-sys-tweaks/files/010_user-nopasswd | 1 + stage2/03-accept-mathematica-eula/00-debconf | 2 - stage2/EXPORT_IMAGE | 4 - stage2/EXPORT_NOOBS | 2 - stage3/00-configure-apt/00-packages | 2 + stage3/00-configure-apt/01-run.sh | 11 + stage3/00-configure-apt/files/docker.gpg.key | 62 +++ stage3/00-configure-apt/files/docker.list | 1 + .../00-configure-apt/files/kubernetes.gpg.key | Bin 0 -> 653 bytes stage3/00-configure-apt/files/kubernetes.list | 1 + stage3/00-install-packages/00-debconf | 2 - stage3/00-install-packages/00-packages | 15 - stage3/00-install-packages/00-packages-nr | 6 - stage3/00-install-packages/01-run.sh | 8 - stage3/01-install-docker/00-packages-nr | 2 + stage3/01-install-docker/01-run.sh | 8 + .../02-patches/00-disable-swap.diff | 6 + stage3/01-install-docker/02-patches/series | 1 + stage3/01-install-docker/files/daemon.json | 9 + stage3/01-tweaks/00-run.sh | 3 - stage4/00-install-packages/00-debconf | 2 - stage4/00-install-packages/00-packages | 25 -- stage4/00-install-packages/00-packages-nr | 2 - stage4/00-install-packages/01-packages | 22 - stage4/00-install-packages/02-packages | 4 - stage4/00-setup-bootstrap/00-run.sh | 12 + stage4/00-setup-bootstrap/files/bootstrap.sh | 70 ++++ .../files/pikube-bootstrap.service | 14 + stage4/01-console-autologin/00-run.sh | 5 - stage4/02-extras/00-run.sh | 7 - stage4/03-magpi/00-run.sh | 15 - stage4/03-magpi/files/.gitignore | 1 - stage4/04-enable-xcompmgr/00-run.sh | 5 - stage4/EXPORT_NOOBS | 2 - stage5/00-install-extras/00-packages | 16 - stage5/00-install-libreoffice/00-packages | 3 - stage5/EXPORT_IMAGE | 4 - stage5/EXPORT_NOOBS | 2 - stage5/prerun.sh | 5 - 49 files changed, 612 insertions(+), 609 deletions(-) create mode 100644 docs/customization.md create mode 100644 stage2/01-sys-tweaks/files/010_user-nopasswd delete mode 100644 stage2/03-accept-mathematica-eula/00-debconf delete mode 100644 stage2/EXPORT_IMAGE delete mode 100644 stage2/EXPORT_NOOBS create mode 100644 stage3/00-configure-apt/00-packages create mode 100755 stage3/00-configure-apt/01-run.sh create mode 100644 stage3/00-configure-apt/files/docker.gpg.key create mode 100644 stage3/00-configure-apt/files/docker.list create mode 100644 stage3/00-configure-apt/files/kubernetes.gpg.key create mode 100644 stage3/00-configure-apt/files/kubernetes.list delete mode 100644 stage3/00-install-packages/00-debconf delete mode 100644 stage3/00-install-packages/00-packages delete mode 100644 stage3/00-install-packages/00-packages-nr delete mode 100755 stage3/00-install-packages/01-run.sh create mode 100644 stage3/01-install-docker/00-packages-nr create mode 100755 stage3/01-install-docker/01-run.sh create mode 100644 stage3/01-install-docker/02-patches/00-disable-swap.diff create mode 100644 stage3/01-install-docker/02-patches/series create mode 100644 stage3/01-install-docker/files/daemon.json delete mode 100755 stage3/01-tweaks/00-run.sh delete mode 100644 stage4/00-install-packages/00-debconf delete mode 100644 stage4/00-install-packages/00-packages delete mode 100644 stage4/00-install-packages/00-packages-nr delete mode 100644 stage4/00-install-packages/01-packages delete mode 100644 stage4/00-install-packages/02-packages create mode 100755 stage4/00-setup-bootstrap/00-run.sh create mode 100644 stage4/00-setup-bootstrap/files/bootstrap.sh create mode 100644 stage4/00-setup-bootstrap/files/pikube-bootstrap.service delete mode 100755 stage4/01-console-autologin/00-run.sh delete mode 100755 stage4/02-extras/00-run.sh delete mode 100755 stage4/03-magpi/00-run.sh delete mode 100644 stage4/03-magpi/files/.gitignore delete mode 100755 stage4/04-enable-xcompmgr/00-run.sh delete mode 100644 stage4/EXPORT_NOOBS delete mode 100644 stage5/00-install-extras/00-packages delete mode 100644 stage5/00-install-libreoffice/00-packages delete mode 100644 stage5/EXPORT_IMAGE delete mode 100644 stage5/EXPORT_NOOBS delete mode 100755 stage5/prerun.sh diff --git a/Dockerfile b/Dockerfile index 2e53149..0d6fae5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,21 @@ -FROM debian:buster +FROM i386/debian:buster ENV DEBIAN_FRONTEND noninteractive RUN apt-get -y update && \ apt-get -y install --no-install-recommends \ git vim parted \ - quilt coreutils qemu-user-static debootstrap zerofree zip dosfstools \ + quilt coreutils debootstrap zerofree zip dosfstools \ bsdtar libcap2-bin rsync grep udev xz-utils curl xxd file kmod bc\ - binfmt-support ca-certificates \ + qemu-user-static binfmt-support ca-certificates gnupg\ && rm -rf /var/lib/apt/lists/* -COPY . /pi-gen/ +COPY export-image /pi-gen/export-image +COPY export-noobs /pi-gen/export-noobs +COPY scripts /pi-gen/scripts +COPY build.sh /pi-gen/build.sh +COPY config /pi-gen/config -VOLUME [ "/pi-gen/work", "/pi-gen/deploy"] +ENV GIT_HASH=develop + +WORKDIR /pi-gen \ No newline at end of file diff --git a/LICENSE b/LICENSE index a50089f..58404a5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,28 @@ +MIT License + +Copyright (c) 2020 adamthesax + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +----------------------------------------------- +Original `pi-gen` License + Copyright (c) 2015 Raspberry Pi (Trading) Ltd. All rights reserved. diff --git a/README.md b/README.md index 29d8166..75dc68c 100644 --- a/README.md +++ b/README.md @@ -1,356 +1,34 @@ -# pi-gen +# pikube-gen _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 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 coreutils quilt parted qemu-user-static debootstrap zerofree zip \ -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 -package is `[:]`. - - -## Config - -Upon execution, `build.sh` will source the file `config` in the current -working directory. This bash shell fragment is intended to set needed -environment variables. - -The following environment variables are supported: - - * `IMG_NAME` **required** (Default: unset) - - The name of the image to build with the current stage directories. Setting - `IMG_NAME=Raspbian` is logical for an unmodified RPi-Distro/pi-gen build, - 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 - will not be included in the image, making it safe to use an `apt-cacher` or - similar package for development. - - If you have Docker installed, you can set up a local apt caching proxy to - like speed up subsequent builds like this: - - docker-compose up -d - echo 'APT_PROXY=http://172.17.0.1:3142' >> config - - * `BASE_DIR` (Default: location of `build.sh`) - - **CAUTION**: Currently, changing this value will probably break build.sh - - Top-level directory for `pi-gen`. Contains stage directories, build - scripts, and by default both work and deployment directories. - - * `WORK_DIR` (Default: `"$BASE_DIR/work"`) - - Directory in which `pi-gen` builds the target system. This value can be - changed if you have a suitably large, fast storage location for stages to - 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. - - * `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 - - * `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. If `WPA_ESSID` is set and `WPA_PASSWORD` is unset an unprotected wifi 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 Raspberry Pi. - - * `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 - -The following process is followed to build images: - - * Loop through all of the stage directories in alphanumeric order - - * Move on to the next directory if this stage directory contains a file called - "SKIP" - - * Run the script ```prerun.sh``` which is generally just used to copy the build - directory between stages. - - * In each stage directory loop through each subdirectory and then run each of the - install scripts it contains, again in alphanumeric order. These need to be named - with a two digit padded number at the beginning. - There are a number of different files and directories which can be used to - control different parts of the build process: - - - **00-run.sh** - A unix shell script. Needs to be made executable for it to run. - - - **00-run-chroot.sh** - A unix shell script which will be run in the chroot - of the image build directory. Needs to be made executable for it to run. - - - **00-debconf** - Contents of this file are passed to debconf-set-selections - to configure things like locale, etc. - - - **00-packages** - A list of packages to install. Can have more than one, space - separated, per line. - - - **00-packages-nr** - As 00-packages, except these will be installed using - the ```--no-install-recommends -y``` parameters to apt-get. - - - **00-patches** - A directory containing patch files to be applied, using quilt. - If a file named 'EDIT' is present in the directory, the build process will - be interrupted with a bash session, allowing an opportunity to create/revise - the patches. - - * If the stage directory contains files called "EXPORT_NOOBS" or "EXPORT_IMAGE" then - add this stage to a list of images to generate - - * Generate the images for any stages that have specified them - -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 -``` - -If everything goes well, your finished image will be in the `deploy/` folder. -You can then remove the build container with `docker rm -v pigen_work` - -If something breaks along the line, you can edit the corresponding scripts, and -continue: - -```bash -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 -PRESERVE_CONTAINER=1 ./build-docker.sh -``` - -There is a possibility that even when running from a docker container, the -installation of `qemu-user-static` will silently fail when building the image -because `binfmt-support` _must be enabled on the underlying kernel_. An easy -fix is to ensure `binfmt-support` is installed on the host machine before -starting the `./build-docker.sh` script (or using your own docker build -solution). - - -## Stage Anatomy - -### Raspbian Stage Overview - -The build of Raspbian is divided up into several stages for logical clarity -and modularity. This causes some initial complexity, but it simplifies -maintenance and allows for more easy customization. - - - **Stage 0** - bootstrap. The primary purpose of this stage is to create a - usable filesystem. This is accomplished largely through the use of - `debootstrap`, which creates a minimal filesystem suitable for use as a - base.tgz on Debian systems. This stage also configures apt settings and - installs `raspberrypi-bootloader` which is missed by debootstrap. The - minimal core is installed but not configured, and the system will not quite - boot yet. - - - **Stage 1** - truly minimal system. This stage makes the system bootable by - installing system files like `/etc/fstab`, configures the bootloader, makes - the network operable, and installs packages like raspi-config. At this - stage the system should boot to a local console from which you have the - means to perform basic tasks needed to configure and install the system. - This is as minimal as a system can possibly get, and its arguably not - really usable yet in a traditional sense yet. Still, if you want minimal, - this is minimal and the rest you could reasonably do yourself as sysadmin. - - - **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, - 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. - - There are a few tools that may not make a whole lot of sense here for - development purposes on a minimal system such as basic Python and Lua - packages as well as the `build-essential` package. They are lumped right - in with more essential packages presently, though they need not be with - pi-gen. These are understandable for Raspbian's target audience, but if - you were looking for something between truly minimal and Raspbian-Lite, - here's where you start trimming. - - - **Stage 3** - desktop system. Here's where you get the full desktop system - with X11 and LXDE, web browsers, git for development, Raspbian custom UI - enhancements, etc. This is a base desktop system, with some development - tools installed. - - - **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 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` and `./stage5` (if building up to stage 2) or -to `./stage2` (if building a minimal system). - -```bash -# Example for building a lite system -echo "IMG_NAME='Raspbian'" > config -touch ./stage3/SKIP ./stage4/SKIP ./stage5/SKIP -touch ./stage4/SKIP_IMAGES ./stage5/SKIP_IMAGES -sudo ./build.sh # or ./build-docker.sh -``` - -If you wish to build further configurations upon (for example) the lite -system, you can also delete the contents of `./stage3` and `./stage4` and -replace with your own contents in the same format. - - -## Skipping stages to speed up development - -If you're working on a specific stage the recommended development process is as -follows: - - * Add a file called SKIP_IMAGES into the directories containing EXPORT_* files - (currently stage2, stage4 and stage5) - * Add SKIP files to the stages you don't want to build. For example, if you're - basing your image on the lite image you would add these to stages 3, 4 and 5. - * Run build.sh to build all stages - * Add SKIP files to the earlier successfully built stages - * Modify the last stage - * Rebuild just the last stage using ```sudo CLEAN=1 ./build.sh``` - * 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`. +|*If you are looking for a simple way to get started, use the [pikube cli tool](https://github.com/adamthesax/pikube-cli).*| +|-------| + +pikube-gen is a fork of [pi-gen](https://github.com/RPi-Distro/pi-gen) which intends to deliver a +simple way to setup a kubernetes cluster on a number of raspberry pi. To do so pi-kube generates a +single Raspbian based disk image with Docker and Kubernetes pre-installed. It also contains a +bootstraping service which will allow you to customize and secure your cluster by dropping a few +additional files onto the boot mount. + +To customize your image build further see the [customization guide](doc/customization.md) + +## Usage +`pikube` ships with a docker/kubernetes pre-installed as well as a bootstrapping service which will +initialize the cluster (on join an existing one), set up SSH keys and configure your hostname. + +To setup pikube: +1) Grab the image (either from grabbing a prebuilt from the releases or running `./build-docker.sh`) +2) Flash the image to your SD card +3) Create a `pikube.tar.gz` with the folowing files: + * `hostname`: Text file containing the hostname + * `ssh.pub` A public ssh key which will be installed into `~/.ssh/authorized_hosts` for passwordless ssh + * `kube.yaml` A `kubeadm` config file to be run upon first boot + * `pki/` directory of certs to be installed at `/etc/kubernetes/pki` for the master you will need the following: + * `ca.crt` + * `ca.key` + * `front-proxy-ca.crt` + * `front-proxy-ca.key` + * `etcd/ca.crt` + * `etcd/ca.key` +4) Copy `pikube.tar.gz` to `/boot/pikube.tar.gz` on your SD card. \ No newline at end of file diff --git a/build-docker.sh b/build-docker.sh index b6a9ea3..4901a47 100755 --- a/build-docker.sh +++ b/build-docker.sh @@ -14,95 +14,46 @@ if ! ${DOCKER} ps >/dev/null; then exit 1 fi -CONFIG_FILE="" -if [ -f "${DIR}/config" ]; then - CONFIG_FILE="${DIR}/config" +if [ -f config ]; then + # shellcheck disable=SC1091 + source 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" || realpath "$CONFIG_FILE") -fi +BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +STAGE_LIST=${STAGE_LIST:-${BASE_DIR}/stage*} +IMAGE_NAME=${IMAGE_NAME:-pikube_gen} -# 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} +echo "Building base image..." +${DOCKER} build -t ${IMAGE_NAME}:init "${DIR}" -if [ -z "${IMG_NAME}" ]; then - echo "IMG_NAME not set in 'config'" 1>&2 - echo 1>&2 -exit 1 -fi -# Ensure the Git Hash is recorded before entering the docker container -GIT_HASH=${GIT_HASH:-"$(git rev-parse HEAD)"} +PREVIOUS_IMAGE=${IMAGE_NAME}:init -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." - echo "You can delete the existing container like this:" - echo " ${DOCKER} rm -v ${CONTAINER_NAME}" - exit 1 -fi +for STAGE_DIR in $STAGE_LIST; do + STAGE_NAME=$(basename $STAGE_DIR) + CONTAINER_NAME=${IMAGE_NAME}_${STAGE_NAME} -# 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@')" + BASE_IMAGE_NAME="${IMAGE_NAME}:${STAGE_NAME}_base" -${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" \ - 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 \ - -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 "$!" -fi -echo "copying results from deploy/" -${DOCKER} cp "${CONTAINER_NAME}":/pi-gen/deploy . -ls -lah deploy +BEFORE_BUILD_ID=$(docker inspect --format {{.Id}} ${BASE_IMAGE_NAME} || echo "noexists") +docker build --rm -t ${IMAGE_NAME}:${STAGE_NAME}_base -f- $STAGE_DIR < This guide is largely adapted from [pi-gen]()'s README.md + +## Dependencies + +pikube-gen runs on Debian based operating systems or can be run within a docker container. +It is recommended to run this within a Docker container by using `./build-docker` see below. + +Currently if building natively, it is only supported on either Debian Buster or Ubuntu Xenial +and is known to have issues building on earlier releases of these systems. + +To install the required dependencies for pikube-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 bc +``` + +The file `depends` contains a list of tools needed. The format of this +package is `[:]`. + + +## Config + +Upon execution, `build.sh` will source the file `config` in the current +working directory. This bash shell fragment is intended to set needed +environment variables. + +The following environment variables are supported: + + * `IMG_NAME` (Default: pikube) + + The name of the image to build with the current stage directories. 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 + will not be included in the image, making it safe to use an `apt-cacher` or + similar package for development. + + If you have Docker installed, you can set up a local apt caching proxy to + like speed up subsequent builds like this: + + docker-compose up -d + echo 'APT_PROXY=http://172.17.0.1:3142' >> config + + * `BASE_DIR` (Default: location of `build.sh`) + + **CAUTION**: Currently, changing this value will probably break build.sh + + Top-level directory for `pikube-gen`. Contains stage directories, build + scripts, and by default both work and deployment directories. + + * `WORK_DIR` (Default: `"$BASE_DIR/work"`) + + Directory in which `pikube-gen` builds the target system. This value can be + changed if you have a suitably large, fast storage location for stages to + 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_US.UTF-8" ) + + Default system locale. + + * `TARGET_HOSTNAME` (Default: "pikube" ) + + Setting the hostname to the specified value. + + * `KEYBOARD_KEYMAP` (Default: "us" ) + + 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 (US)" ) + + 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 + + * `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 `WPA_ESSID` is set and `WPA_PASSWORD` is unset an unprotected wifi network will be configured. If set, `WPA_PASSWORD` must be between 8 and 63 characters. + + * `ENABLE_SSH` (Default: `1`) + Setting to `0` will disable ssh server for remote log in. pikube will setup an SSH keypair so you can login + using the generated private key. + + * `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 pikube-gen directory. + +## How the build process works + +The following process is followed to build images: + + * Loop through all of the stage directories in alphanumeric order + + * Move on to the next directory if this stage directory contains a file called + "SKIP" + + * Run the script ```prerun.sh``` which is generally just used to copy the build + directory between stages. + + * In each stage directory loop through each subdirectory and then run each of the + install scripts it contains, again in alphanumeric order. These need to be named + with a two digit padded number at the beginning. + There are a number of different files and directories which can be used to + control different parts of the build process: + + - **00-run.sh** - A unix shell script. Needs to be made executable for it to run. + + - **00-run-chroot.sh** - A unix shell script which will be run in the chroot + of the image build directory. Needs to be made executable for it to run. + + - **00-debconf** - Contents of this file are passed to debconf-set-selections + to configure things like locale, etc. + + - **00-packages** - A list of packages to install. Can have more than one, space + separated, per line. + + - **00-packages-nr** - As 00-packages, except these will be installed using + the ```--no-install-recommends -y``` parameters to apt-get. + + - **00-patches** - A directory containing patch files to be applied, using quilt. + If a file named 'EDIT' is present in the directory, the build process will + be interrupted with a bash session, allowing an opportunity to create/revise + the patches. + + * If the stage directory contains files called "EXPORT_NOOBS" or "EXPORT_IMAGE" then + add this stage to a list of images to generate + + * Generate the images for any stages that have specified them + +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 +``` + +If everything goes well, your finished image will be in the `deploy/` folder. +You can then remove the build container with `docker rm -v pigen_work` + +If something breaks along the line, you can edit the corresponding scripts, and +continue: + +```bash +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 pikube-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 +PRESERVE_CONTAINER=1 ./build-docker.sh +``` + +There is a possibility that even when running from a docker container, the +installation of `qemu-user-static` will silently fail when building the image +because `binfmt-support` _must be enabled on the underlying kernel_. An easy +fix is to ensure `binfmt-support` is installed on the host machine before +starting the `./build-docker.sh` script (or using your own docker build +solution). + + +## Stage Anatomy + +### Raspbian Stage Overview + +The build of Raspbian is divided up into several stages for logical clarity +and modularity. This causes some initial complexity, but it simplifies +maintenance and allows for more easy customization. + + - **Stage 0** - bootstrap. The primary purpose of this stage is to create a + usable filesystem. This is accomplished largely through the use of + `debootstrap`, which creates a minimal filesystem suitable for use as a + base.tgz on Debian systems. This stage also configures apt settings and + installs `raspberrypi-bootloader` which is missed by debootstrap. The + minimal core is installed but not configured, and the system will not quite + boot yet. + + - **Stage 1** - truly minimal system. This stage makes the system bootable by + installing system files like `/etc/fstab`, configures the bootloader, makes + the network operable, and installs packages like raspi-config. At this + stage the system should boot to a local console from which you have the + means to perform basic tasks needed to configure and install the system. + This is as minimal as a system can possibly get, and its arguably not + really usable yet in a traditional sense yet. Still, if you want minimal, + this is minimal and the rest you could reasonably do yourself as sysadmin. + + - **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, + dphys-swapfile, and other basics for managing the hardware. It also + creates necessary groups and gives the default user access to sudo and the + standard console hardware permission groups. + + - **Stage 3** - docker + kubernetes. This stage installs setups the docker and + kubernetes apt repos and installs `docker-ce` and `kubeadm`. It also makes sure + that pre-requisites for kubernetes are taken care of + (disabling swap, setting up c-group driver for docker, etc) + + - **Stage 4** - pikube bootstrapping. This stage sets up a service that runs on first + boot to configure you kubernetes master/worker and configures the ssh keypair + +### 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` and `./stage5` (if building up to stage 2) or +to `./stage2` (if building a minimal system). + +```bash +# Example for building a lite system +touch ./stage3/SKIP ./stage4/SKIP ./stage5/SKIP +touch ./stage4/SKIP_IMAGES ./stage5/SKIP_IMAGES +sudo ./build.sh # or ./build-docker.sh +``` + +If you wish to build further configurations upon (for example) the lite +system, you can also delete the contents of `./stage3` and `./stage4` and +replace with your own contents in the same format. + + +## Skipping stages to speed up development +The easiest way to speed up development is to use the `./docker-build.sh` workflow +which will use docker images to cache each stage. + + +If you're working on a specific stage the recommended development process is as +follows: + + * Add a file called SKIP_IMAGES into the directories containing EXPORT_* files + (currently stage2, stage4 and stage5) + * Add SKIP files to the stages you don't want to build. For example, if you're + basing your image on the lite image you would add these to stages 3, 4 and 5. + * Run build.sh to build all stages + * Add SKIP files to the earlier successfully built stages + * Modify the last stage + * Rebuild just the last stage using ```sudo CLEAN=1 ./build.sh``` + * Once you're happy with the image you can remove the SKIP_IMAGES files and + export your image to test \ No newline at end of file diff --git a/export-noobs/00-release/00-run.sh b/export-noobs/00-release/00-run.sh index 18a3a5d..f7171c1 100755 --- a/export-noobs/00-release/00-run.sh +++ b/export-noobs/00-release/00-run.sh @@ -1,6 +1,6 @@ #!/bin/bash -e -NOOBS_DIR="${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}" +NOOBS_DIR="${STAGE_WORK_DIR}/${IMG_VERSION}-${IMG_NAME}${IMG_SUFFIX}" install -v -m 744 files/partition_setup.sh "${NOOBS_DIR}/" install -v files/partitions.json "${NOOBS_DIR}/" @@ -33,11 +33,11 @@ sed "${NOOBS_DIR}/partitions.json" -i -e "s|ROOT_SIZE|${ROOT_SIZE}|" sed "${NOOBS_DIR}/partitions.json" -i -e "s|BOOT_NOM|${BOOT_NOM}|" 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|UNRELEASED|${IMG_VERSION}|" 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}|" +sed "${NOOBS_DIR}/release_notes.txt" -i -e "s|UNRELEASED|${IMG_VERSION}|" cp -a "${NOOBS_DIR}" "${DEPLOY_DIR}/" diff --git a/export-noobs/prerun.sh b/export-noobs/prerun.sh index 54e0c59..f7f248b 100755 --- a/export-noobs/prerun.sh +++ b/export-noobs/prerun.sh @@ -1,7 +1,7 @@ #!/bin/bash -e IMG_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img" -NOOBS_DIR="${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}" +NOOBS_DIR="${STAGE_WORK_DIR}/${IMG_VERSION}-${IMG_NAME}${IMG_SUFFIX}" unmount_image "${IMG_FILE}" mkdir -p "${STAGE_WORK_DIR}" diff --git a/scripts/common b/scripts/common index e2048d9..5cf1384 100644 --- a/scripts/common +++ b/scripts/common @@ -95,6 +95,6 @@ on_chroot() { export -f on_chroot update_issue() { - echo -e "Raspberry Pi reference ${IMG_DATE}\nGenerated using ${PI_GEN}, ${PI_GEN_REPO}, ${GIT_HASH}, ${1}" > "${ROOTFS_DIR}/etc/rpi-issue" + echo -e "Raspberry Pi reference ${IMG_VERSION}\nGenerated using ${PI_GEN}, ${PI_GEN_REPO}, ${GIT_HASH}, ${1}" > "${ROOTFS_DIR}/etc/rpi-issue" } export -f update_issue diff --git a/stage2/01-sys-tweaks/01-run.sh b/stage2/01-sys-tweaks/01-run.sh index 8d28adc..3753963 100755 --- a/stage2/01-sys-tweaks/01-run.sh +++ b/stage2/01-sys-tweaks/01-run.sh @@ -54,3 +54,11 @@ usermod --pass='*' root EOF rm -f "${ROOTFS_DIR}/etc/ssh/"ssh_host_*_key* + +install -m 440 files/010_user-nopasswd "${ROOTFS_DIR}/etc/sudoers.d/010_${FIRST_USER_NAME}-nopasswd" +sed -i "s/USER_NAME/${FIRST_USER_NAME}/g" "${ROOTFS_DIR}/etc/sudoers.d/010_${FIRST_USER_NAME}-nopasswd" + +if [ -n "${SSH_AUTHORIZED_KEY}" ]; then + mkdir -p ${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.ssh + echo $SSH_AUTHORIZED_KEY > ${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.ssh/authorized_keys +fi diff --git a/stage2/01-sys-tweaks/files/010_user-nopasswd b/stage2/01-sys-tweaks/files/010_user-nopasswd new file mode 100644 index 0000000..617b7b1 --- /dev/null +++ b/stage2/01-sys-tweaks/files/010_user-nopasswd @@ -0,0 +1 @@ +USER_NAME ALL=(ALL) NOPASSWD: ALL \ No newline at end of file diff --git a/stage2/03-accept-mathematica-eula/00-debconf b/stage2/03-accept-mathematica-eula/00-debconf deleted file mode 100644 index d9743fe..0000000 --- a/stage2/03-accept-mathematica-eula/00-debconf +++ /dev/null @@ -1,2 +0,0 @@ -# Do you accept the Wolfram - Raspberry PiĀ® Bundle License Agreement? -wolfram-engine shared/accepted-wolfram-eula boolean true diff --git a/stage2/EXPORT_IMAGE b/stage2/EXPORT_IMAGE deleted file mode 100644 index aa8f936..0000000 --- a/stage2/EXPORT_IMAGE +++ /dev/null @@ -1,4 +0,0 @@ -IMG_SUFFIX="-lite" -if [ "${USE_QEMU}" = "1" ]; then - export IMG_SUFFIX="${IMG_SUFFIX}-qemu" -fi diff --git a/stage2/EXPORT_NOOBS b/stage2/EXPORT_NOOBS deleted file mode 100644 index 136cc77..0000000 --- a/stage2/EXPORT_NOOBS +++ /dev/null @@ -1,2 +0,0 @@ -NOOBS_NAME="Raspbian Lite" -NOOBS_DESCRIPTION="A port of Debian with no desktop environment" diff --git a/stage3/00-configure-apt/00-packages b/stage3/00-configure-apt/00-packages new file mode 100644 index 0000000..471e94b --- /dev/null +++ b/stage3/00-configure-apt/00-packages @@ -0,0 +1,2 @@ +apt-transport-https +ca-certificates \ No newline at end of file diff --git a/stage3/00-configure-apt/01-run.sh b/stage3/00-configure-apt/01-run.sh new file mode 100755 index 0000000..8aa143d --- /dev/null +++ b/stage3/00-configure-apt/01-run.sh @@ -0,0 +1,11 @@ +#!/bin/bash -e + +install -m 644 files/docker.list "${ROOTFS_DIR}/etc/apt/sources.list.d/docker.list" +sed -i "s/RELEASE/${RELEASE}/g" "${ROOTFS_DIR}/etc/apt/sources.list.d/docker.list" +install -m 644 files/kubernetes.list "${ROOTFS_DIR}/etc/apt/sources.list.d/kubernetes.list" + +on_chroot apt-key add - < files/docker.gpg.key +on_chroot apt-key add - < files/kubernetes.gpg.key +on_chroot << EOF +apt-get update +EOF \ No newline at end of file diff --git a/stage3/00-configure-apt/files/docker.gpg.key b/stage3/00-configure-apt/files/docker.gpg.key new file mode 100644 index 0000000..ee7872e --- /dev/null +++ b/stage3/00-configure-apt/files/docker.gpg.key @@ -0,0 +1,62 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +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 +YT90qFF93M3v01BbxP+EIY2/9tiIPbrd +=0YYh +-----END PGP PUBLIC KEY BLOCK----- diff --git a/stage3/00-configure-apt/files/docker.list b/stage3/00-configure-apt/files/docker.list new file mode 100644 index 0000000..db776fd --- /dev/null +++ b/stage3/00-configure-apt/files/docker.list @@ -0,0 +1 @@ +deb [arch=armhf] https://download.docker.com/linux/raspbian RELEASE stable \ No newline at end of file diff --git a/stage3/00-configure-apt/files/kubernetes.gpg.key b/stage3/00-configure-apt/files/kubernetes.gpg.key new file mode 100644 index 0000000000000000000000000000000000000000..12e9f40fee769d77840d72838760203785b5469b GIT binary patch literal 653 zcmV;80&@Mvz)b{N!D!n72mtFBUkVAk8J3O>j0@Fy#K8)BdRf3wCz=w6zl8V5*Y%9& zP%6!?37!eSj8gQ&L_A+jpvlR$hq?#bYmMis85=f|cIvIis=cW$ai^w{S?LRfksvCpA!dLRGW)c6@<$|eWzIMsEvEh0~1RvRL< zpTIZJzS#vpk94o2WSvydmYR@E0SGjQr$~LYrd=}xNRnq znAY$p#0rrUgyKZv2fc$nPV*mv=F;jkU{O{ZimWh;suCzk|I&?L!I%cWty&C=qJrhI z(zloH9ag7&aybbzQ854!0RREbKu2$HXKZC4Lu_w#WFSysV{2h&Wpf}wb#!lSVRUI@ zAX8~)ZfS03AWLO=AUtPdEp%mJZ9r#lZ)a>}E@N+PKEl9w1QP)Q04xOpTES@B2@q-n z3n97(^!oxE4+RMYqndyQ3ke7Z0|EvW2m%QT3j`Jd0|5X4CcX#&&Sij|f=)!yyJ)cb z(Qt3wFNm~yTSIjUB#%=FwSqAUGQMlksHO%kgDtk5P*!#qh( ztgbH6>%fIhl%N9jysBB{zi6OAYOeq_%2ojCL$G&)8G^zRWzL503z}+J z;R=Dc;Edx*E=)9C=VQVoPMgtPZRa&Abf=1BBhWq@693xWVE=LuL7lT575!Ux3&>-? zg)o9&1#5dh;ix*60w4Q?rH~LEeqYQ^ /var/pikube.status +dphys-swapfile swapoff +dphys-swapfile uninstall +systemctl disable dphys-swapfile + +# TODO: VARIABLE EXAPNSION ON USERNAME +user=USER_NAME +if [ -f "$conf_dir/ssh.pub" ];then + echo "Installing ssh key" | tee /var/pikube.status + mkdir -p /home/$user/.ssh + cp $conf_dir/ssh.pub /home/$user/.ssh/authorized_keys + chown $user:$user /home/$user/.ssh/authorized_keys + chmod 644 /home/$user/.ssh/authorized_keys + passwd --delete kube +fi + + +if [ -f "$conf_dir/ca.crt" ];then + echo "Installing CA certificate" | tee /var/pikube.status + cp $conf_dir/pki/ca.crt /usr/local/share/ca-certificates/kubernetes.crt + update-ca-certificates +fi + +if [ -f "$conf_dir/kube.yaml" ];then + echo "Applying kubernetes config" | tee /var/pikube.status + + if [ -d "$conf_dir/pki" ];then + mkdir -p /etc/kubernetes/pki + cp $config_dir/pki/* /etc/kubernetes/pki + fi + + kubeadm init --config conf/kube.yaml + + # setup the kube config for the kube user + mkdir -p /home/kube/.kube + sudo cp -i /etc/kubernetes/admin.conf /home/kube/.kube/config + sudo chown $user:$user /home/kube/.kube/config + + # install weave network + kubectl apply --kubeconfig=/etc/kubernetes/admin.conf -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')" +fi + +echo "Initialized" > /var/pikube.status + +systemctl disable pikube-bootstrap +sleep 120 +reboot \ No newline at end of file diff --git a/stage4/00-setup-bootstrap/files/pikube-bootstrap.service b/stage4/00-setup-bootstrap/files/pikube-bootstrap.service new file mode 100644 index 0000000..f17703f --- /dev/null +++ b/stage4/00-setup-bootstrap/files/pikube-bootstrap.service @@ -0,0 +1,14 @@ +[Unit] +Description=pikube bootstrap +After=network.target + +[Service] +ExecStart=/usr/bin/bash bootstrap.sh +WorkingDirectory=/opt/pikube +StandardOutput=file:/var/log/pikube.log +StandardError=file:/var/log/pikube.log +Restart=no +User=root + +[Install] +WantedBy=multi-user.target diff --git a/stage4/01-console-autologin/00-run.sh b/stage4/01-console-autologin/00-run.sh deleted file mode 100755 index 665dcdb..0000000 --- a/stage4/01-console-autologin/00-run.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -e - -on_chroot << EOF - SUDO_USER="${FIRST_USER_NAME}" raspi-config nonint do_boot_behaviour B4 -EOF diff --git a/stage4/02-extras/00-run.sh b/stage4/02-extras/00-run.sh deleted file mode 100755 index 6a24f82..0000000 --- a/stage4/02-extras/00-run.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -e - -#Alacarte fixes -install -v -o 1000 -g 1000 -d "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.local" -install -v -o 1000 -g 1000 -d "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.local/share" -install -v -o 1000 -g 1000 -d "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.local/share/applications" -install -v -o 1000 -g 1000 -d "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.local/share/desktop-directories" diff --git a/stage4/03-magpi/00-run.sh b/stage4/03-magpi/00-run.sh deleted file mode 100755 index b27b85f..0000000 --- a/stage4/03-magpi/00-run.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -e - -magpi_regex="MagPi[[:digit:]]*.pdf" -magpi_loc="$(curl -s https://magpi.raspberrypi.org/latest-pdf)" -magpi_latest="$(echo "$magpi_loc" | grep "$magpi_regex" -m 1 -o)" - -if [ ! -f "files/$magpi_latest" ]; then - find files/ -regextype grep -regex "files/$magpi_regex" -delete - wget "$magpi_loc" -O "files/$magpi_latest" -fi - -file "files/$magpi_latest" | grep -q "PDF document" - -install -v -o 1000 -g 1000 -d "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/MagPi" -install -v -o 1000 -g 1000 -m 644 "files/$magpi_latest" "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/MagPi/" diff --git a/stage4/03-magpi/files/.gitignore b/stage4/03-magpi/files/.gitignore deleted file mode 100644 index a136337..0000000 --- a/stage4/03-magpi/files/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.pdf diff --git a/stage4/04-enable-xcompmgr/00-run.sh b/stage4/04-enable-xcompmgr/00-run.sh deleted file mode 100755 index ad6298d..0000000 --- a/stage4/04-enable-xcompmgr/00-run.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -e - -on_chroot << EOF - raspi-config nonint do_xcompmgr 0 -EOF diff --git a/stage4/EXPORT_NOOBS b/stage4/EXPORT_NOOBS deleted file mode 100644 index 2ef6d7b..0000000 --- a/stage4/EXPORT_NOOBS +++ /dev/null @@ -1,2 +0,0 @@ -NOOBS_NAME="Raspbian" -NOOBS_DESCRIPTION="A port of Debian with the Raspberry Pi Desktop" diff --git a/stage5/00-install-extras/00-packages b/stage5/00-install-extras/00-packages deleted file mode 100644 index 609e718..0000000 --- a/stage5/00-install-extras/00-packages +++ /dev/null @@ -1,16 +0,0 @@ -mu-editor -sonic-pi -scratch nuscratch scratch2 scratch3 -smartsim - -minecraft-pi python-minecraftpi python-picraft python3-picraft -python-sense-emu sense-emu-tools python-sense-emu-doc - -wolfram-engine -claws-mail -greenfoot-unbundled bluej -nodered -realvnc-vnc-viewer - -python-games -code-the-classics diff --git a/stage5/00-install-libreoffice/00-packages b/stage5/00-install-libreoffice/00-packages deleted file mode 100644 index 148e7b9..0000000 --- a/stage5/00-install-libreoffice/00-packages +++ /dev/null @@ -1,3 +0,0 @@ -libreoffice-pi -libreoffice-help-en-gb -libreoffice-l10n-en-gb diff --git a/stage5/EXPORT_IMAGE b/stage5/EXPORT_IMAGE deleted file mode 100644 index a81a844..0000000 --- a/stage5/EXPORT_IMAGE +++ /dev/null @@ -1,4 +0,0 @@ -IMG_SUFFIX="-full" -if [ "${USE_QEMU}" = "1" ]; then - export IMG_SUFFIX="${IMG_SUFFIX}-qemu" -fi diff --git a/stage5/EXPORT_NOOBS b/stage5/EXPORT_NOOBS deleted file mode 100644 index cb10203..0000000 --- a/stage5/EXPORT_NOOBS +++ /dev/null @@ -1,2 +0,0 @@ -NOOBS_NAME="Raspbian Full" -NOOBS_DESCRIPTION="A port of Debian with desktop and recommended applications" diff --git a/stage5/prerun.sh b/stage5/prerun.sh deleted file mode 100755 index 9acd13c..0000000 --- a/stage5/prerun.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -e - -if [ ! -d "${ROOTFS_DIR}" ]; then - copy_previous -fi