| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Test building the tarball on Gentoo. Adapted from test/alpine.sh.
|
| 4 | #
|
| 5 | # https://wiki.gentoo.org/wiki/Chroot
|
| 6 | #
|
| 7 | # Usage:
|
| 8 | # test/gentoo.sh <function name>
|
| 9 |
|
| 10 | set -o nounset
|
| 11 | set -o pipefail
|
| 12 | set -o errexit
|
| 13 |
|
| 14 | # 188 MB -- big!
|
| 15 | # TODO: These are http-only, and need to be verified!
|
| 16 | readonly ROOTFS_URL='http://distfiles.gentoo.org/releases/amd64/autobuilds/20180116T214503Z/stage3-amd64-20180116T214503Z.tar.xz'
|
| 17 | readonly CHROOT_DIR=_chroot/gentoo
|
| 18 |
|
| 19 | readonly PORTAGE_URL='http://distfiles.gentoo.org/snapshots/portage-20180202.tar.xz'
|
| 20 |
|
| 21 | download() {
|
| 22 | wget --no-clobber --directory _tmp $ROOTFS_URL
|
| 23 | wget --no-clobber --directory _tmp $PORTAGE_URL
|
| 24 | }
|
| 25 |
|
| 26 | _extract() {
|
| 27 | local dest=${1:-$CHROOT_DIR}
|
| 28 |
|
| 29 | local tarball=_tmp/$(basename $ROOTFS_URL)
|
| 30 |
|
| 31 | mkdir -p $dest
|
| 32 | # Must be run as root
|
| 33 | tar --extract --xz --directory $dest < $tarball
|
| 34 | }
|
| 35 | extract() { sudo $0 _extract "$@"; }
|
| 36 |
|
| 37 | _extract-portage() {
|
| 38 | local dest=${1:-$CHROOT_DIR}
|
| 39 | local portage_dest=$dest/usr
|
| 40 |
|
| 41 | local tarball=_tmp/$(basename $PORTAGE_URL)
|
| 42 |
|
| 43 | # Must be run as root
|
| 44 | tar --extract --xz --directory $portage_dest < $tarball
|
| 45 | }
|
| 46 | extract-portage() { sudo $0 _extract-portage "$@"; }
|
| 47 |
|
| 48 | # Copied from the wiki page.
|
| 49 | _mount-dirs() {
|
| 50 | mount --rbind /dev $CHROOT_DIR/dev
|
| 51 | mount --make-rslave $CHROOT_DIR/dev
|
| 52 | mount -t proc /proc $CHROOT_DIR/proc
|
| 53 | mount --rbind /sys $CHROOT_DIR/sys
|
| 54 | mount --make-rslave $CHROOT_DIR/sys
|
| 55 | mount --rbind /tmp $CHROOT_DIR/tmp
|
| 56 | }
|
| 57 | mount-dirs() { sudo $0 _mount-dirs "$@"; }
|
| 58 |
|
| 59 | _setup-portage() {
|
| 60 | cp -v $CHROOT_DIR/usr/share/portage/config/make.conf.example $CHROOT_DIR/etc/portage
|
| 61 | }
|
| 62 | setup-portage() { sudo $0 _setup-portage "$@"; }
|
| 63 |
|
| 64 | # From alpine:
|
| 65 |
|
| 66 | # Don't need chmod-chroot, I guess the tarball handles it.
|
| 67 | #
|
| 68 | # test/alpine.sh setup-dns _chroot/gentoo
|
| 69 | # test/alpine.sh copy-tar _chroot/gentoo
|
| 70 | # test/alpine.sh enter-chroot _chroot/gentoo
|
| 71 |
|
| 72 | # emerge --sync -- Ran it manually
|
| 73 |
|
| 74 | add-oil-build-deps() {
|
| 75 | local chroot_dir=${1:-$CHROOT_DIR}
|
| 76 | sudo chroot $chroot_dir /bin/sh <<EOF
|
| 77 | apk update
|
| 78 | apk add bash make gcc musl-dev
|
| 79 | EOF
|
| 80 | }
|
| 81 |
|
| 82 |
|
| 83 | "$@"
|