Skip to content

Commit

Permalink
contrib/rootfs-builder: Support multiple architectures
Browse files Browse the repository at this point in the history
The new Make handling is using:

* Default values [1] for ARCHES ?= amd64
* Substitution references [2] for $(ARCHES:%=rootfs-%.tar.gz).
* % [3] and $* [4] for pattern rules like rootfs-%.tar.gz.
* .PRECIOUS [5] to avoid errors like:

    rm downloads/stage3-amd64-current.tar.bz2 rootfs/amd64/bin/busyboxmake: unlink: rootfs/amd64/bin/busybox: Permission denied
    rootfs/amd64/bin/echomake: unlink: rootfs/amd64/bin/echo: Permission denied

  when Make completes.

Where Gentoo's architecture names don't match, the per-platform
tarballs should be renamed to use the Go names [6] when copying into
the root project directory.

[1]: https://www.gnu.org/software/make/manual/html_node/Setting.html#Setting
[2]: https://www.gnu.org/software/make/manual/html_node/Substitution-Refs.html
[3]: https://www.gnu.org/software/make/manual/html_node/Pattern-Rules.html
[4]: https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html
[5]: https://www.gnu.org/software/make/manual/html_node/Special-Targets.html#index-precious-targets
[6]: https://golang.org/doc/install/source#introduction

Signed-off-by: W. Trevor King <[email protected]>
  • Loading branch information
wking committed Sep 21, 2017
1 parent a94f1f6 commit ff5e578
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 25 deletions.
1 change: 1 addition & 0 deletions contrib/rootfs-builder/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.gz
30 changes: 18 additions & 12 deletions contrib/rootfs-builder/Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
rootfs.tar.gz: rootfs/bin/echo
tar -czf $@ -C rootfs .
ARCHES ?= amd64

rootfs/bin/busybox: downloads/stage3-amd64-current.tar.bz2 rootfs-files
all: $(ARCHES:%=rootfs-%.tar.gz)

rootfs-%.tar.gz: rootfs/%/bin/echo
tar -czf $@ -C rootfs/$* .

.PRECIOUS: rootfs/%/bin/busybox
rootfs/%/bin/busybox: downloads/stage3-%-current.tar.bz2 rootfs-files
gpg --verify $<.DIGESTS.asc
(cd downloads && \
grep -A1 '^# SHA512 HASH' stage3-amd64-current.tar.bz2.DIGESTS.asc | \
grep -A1 '^# SHA512 HASH' stage3-$*-current.tar.bz2.DIGESTS.asc | \
grep -v '^--' | \
sha512sum -c)
sudo rm -rf rootfs
sudo mkdir rootfs
sudo tar -xvf downloads/stage3-amd64-current.tar.bz2 -C rootfs \
sudo rm -rf rootfs/$*
sudo mkdir -p rootfs/$*
sudo tar -xvf downloads/stage3-$*-current.tar.bz2 -C rootfs/$* \
--no-recursion --wildcards $$(< rootfs-files)
sudo touch $@

rootfs/bin/echo: rootfs/bin/busybox
.PRECIOUS: rootfs/%/bin/echo
rootfs/%/bin/echo: rootfs/%/bin/busybox
sudo sh -c 'COMMANDS=$$($< --list) || exit 1; for COMMAND in $${COMMANDS}; do \
test -L "rootfs/bin/$${COMMAND}" || ln -rs $< "rootfs/bin/$${COMMAND}" || exit; \
test -L "rootfs/$*/bin/$${COMMAND}" || ln -rs $< "rootfs/$*/bin/$${COMMAND}" || exit; \
done'

downloads/stage3-amd64-current.tar.bz2: get-stage3.sh
./$<
touch downloads/stage3-amd64-*.tar.bz2
downloads/stage3-%-current.tar.bz2: get-stage3.sh
STAGE3_ARCH=$* ./$<
touch downloads/stage3-$*-*.tar.bz2

clean:
rm -f downloads/*
Expand Down
43 changes: 33 additions & 10 deletions contrib/rootfs-builder/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
Building `rootfs.tar.gz`
------------------------
# Building `rootfs-*.tar.gz`

The root filesystem tarball is based on [Gentoo][]'s [amd64
stage3][stage3-amd64] (which we check for a valid [GnuPG
The root filesystem tarball is based on [Gentoo][]'s stage3s (e.g. the
[amd64 stage3][stage3-amd64]). We check for a valid [GnuPG
signature][gentoo-signatures]), copying a [minimal
subset](rootfs-files) to the root filesytem, and adding symlinks for
all BusyBox commands. To rebuild the tarball based on a newer stage3,
just run:
all BusyBox commands. To rebuild the tarball based on a newer stage3,
run:

```
$ touch get-stage3.sh
$ make rootfs.tar.gz
$ make rootfs-amd64.tar.gz
```

### Getting Gentoo's Release Engineering public key
## Platform tarballs

If `make rootfs.tar.gz` gives an error like:
The extraction requires a local machine capable of executing the
extracted BusyBox. Extraction assumes amd64, but if your local
machine is a different platform, set `ARCHES`. For example:

```
$ make ARCHES='i486 i686 amd64'
```

The architecture identifiers can be found by browsing Gentoo's
[releases][] for `autobuilds/latest-stage3-{arch}.txt`. Examples
include:

* `amd64` (the default)
* `arm64`
* `arm7a`
* `i486`
* `i686`
* `ppc64-64ul`

and many more.

## Getting Gentoo's Release Engineering public key

If `make rootfs-….tar.gz` gives an error like:

```
gpg --verify downloads/stage3-amd64-current.tar.bz2.DIGESTS.asc
Expand All @@ -32,6 +54,7 @@ $ gpg --keyserver pool.sks-keyservers.net --recv-keys 2D182910
```

[Gentoo]: https://www.gentoo.org/
[stage3-amd64]: http://distfiles.gentoo.org/releases/amd64/autobuilds/
[gentoo-signatures]: https://www.gentoo.org/downloads/signatures/
[recv-keys]: https://www.gnupg.org/documentation/manuals/gnupg/Operational-GPG-Commands.html
[releases]: http://distfiles.gentoo.org/releases/
[stage3-amd64]: http://distfiles.gentoo.org/releases/amd64/autobuilds/
26 changes: 23 additions & 3 deletions contrib/rootfs-builder/get-stage3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,31 @@
# limitations under the License.

MIRROR="${MIRROR:-http://distfiles.gentoo.org/}"
BASE_ARCH_URL="${BASE_ARCH_URL:-${MIRROR}releases/amd64/autobuilds/}"
STAGE3_ARCH="${STAGE3_ARCH:-amd64}"

if test -z "${BASE_ARCH}"
then
case "${STAGE3_ARCH}" in
arm*)
BASE_ARCH=arm
;;
i[46]86)
BASE_ARCH=x86
;;
ppc*)
BASE_ARCH=ppc
;;
*)
BASE_ARCH="${STAGE3_ARCH}"
;;
esac
fi

BASE_ARCH_URL="${BASE_ARCH_URL:-${MIRROR}releases/${BASE_ARCH}/autobuilds/}"
LATEST=$(wget -O - "${BASE_ARCH_URL}latest-stage3.txt")
DATE=$(echo "${LATEST}" | sed -n 's|/stage3-amd64-[0-9]*[.]tar[.]bz2.*||p')
DATE=$(echo "${LATEST}" | sed -n "s|/stage3-${STAGE3_ARCH}-[0-9]*[.]tar[.]bz2.*||p")
ARCH_URL="${ARCH_URL:-${BASE_ARCH_URL}${DATE}/}"
STAGE3="${STAGE3:-stage3-amd64-${DATE}.tar.bz2}"
STAGE3="${STAGE3:-stage3-${STAGE3_ARCH}-${DATE}.tar.bz2}"
STAGE3_CONTENTS="${STAGE3_CONTENTS:-${STAGE3}.CONTENTS}"
STAGE3_DIGESTS="${STAGE3_DIGESTS:-${STAGE3}.DIGESTS.asc}"

Expand Down

0 comments on commit ff5e578

Please sign in to comment.