#!/bin/sh set -e # This script builds and upgrades a bunch of prerequisite tools for gentoo # There's just too many small details about these to cover properly in a text file... # Maintenance note: Run gentoo_gen.sh in a fully-updated stable system to get # the appropriate package versions and URLs. version_xz=5.2.5 version_zlib=1.2.11 version_libffi=3.3 version_python=3.7.9 version_perl=5.30.3 version_openssl=1.1.1g version_wget=1.20.3 version_rsync=3.2.3 version_mktemp=1.7 version_ca_certificates=20200601 version_portage=3.0.8 version_m4=1.4.18 version_bison=3.7.1 version_make=4.2.1 version_sed=4.8 export MAKEFLAGS="-j${NPROC:-$(getconf _NPROCESSORS_ONLN)}" # This symlink isn't provided by the bootstrap, but is necessary for a ton of tools mkdir -p /usr/bin ln -sf ../../bootstrap/bin/env /usr/bin/env cd /sources export PATH=/bootstrap/bin # Xz is required to unpack a lot of tarballs, including the Portage tree. # app-arch/xz-utils: rm -rf xz-$version_xz tar zxf xz-$version_xz.tar.gz ( cd xz-$version_xz ./configure --prefix=/bootstrap make make install ) rm -rf xz-$version_xz # Zlib is required for the zlib Python module, used by Portage. # sys-libs/zlib: rm -rf zlib-$version_zlib tar zxf zlib-$version_zlib.tar.gz ( cd zlib-$version_zlib ./configure --prefix=/bootstrap make make install ) rm -rf zlib-$version_zlib # Libffi is required for the _ctypes Python module, used by Portage. # dev-libs/libffi: rm -rf libffi-$version_libffi tar zxf libffi-$version_libffi.tar.gz ( cd libffi-$version_libffi # Fix an error that crops up due to using coreutils-5.0 sed -i -e 's/tail -1/tail -n 1/g' configure ./configure --prefix=/bootstrap make make install ) rm -rf libffi-$version_libffi # Portage is written in Python. Modern glibc also needs it to build. # dev-lang/python: rm -rf Python-$version_python tar Jxf Python-$version_python.tar.xz ( cd Python-$version_python ./configure --prefix=/bootstrap --without-ensurepip make make install ln -sf python3 /bootstrap/bin/python ) rm -rf Python-$version_python # Perl is required to build OpenSSL as well as some other things. # dev-lang/perl: rm -rf perl-$version_perl tar Jxf perl-$version_perl.tar.xz ( cd perl-$version_perl # Fix pwd hardcode sed -i -e "s@'/bin/pwd'@'/bootstrap/bin/pwd'@" dist/PathTools/Cwd.pm ./Configure -des -Dprefix=/bootstrap -Dcc=gcc -Dinstallusrbinperl=n make make install ) rm -rf perl-$version_perl # OpenSSL is required for https support in wget. # dev-libs/openssl: rm -rf openssl-$version_openssl tar zxf openssl-$version_openssl.tar.gz ( cd openssl-$version_openssl ./config --prefix=/bootstrap --openssldir=/bootstrap/etc/ssl make make install ) rm -rf openssl-$version_openssl # Wget is required to download the portage tree and packages. # net-misc/wget: rm -rf wget-$version_wget tar zxf wget-$version_wget.tar.gz ( cd wget-$version_wget ./configure --prefix=/bootstrap --with-ssl=openssl --with-libssl-prefix=/bootstrap make make install ) rm -rf wget-$version_wget # Rsync is optional to run emerge-webrsync or emerge --sync, # and required for linux-headers. # net-misc/rsync: rm -rf rsync-$version_rsync tar zxf rsync-$version_rsync.tar.gz ( cd rsync-$version_rsync ./configure --prefix=/bootstrap --disable-simd --disable-xxhash --disable-zstd --disable-lz4 make make install ) rm -rf rsync-$version_rsync # Mktemp is required by ca-certificates as well as Portage for installing packages. # To avoid upgrading all coreutils, this standalone version is used. # custom/mktemp: rm -rf mktemp-$version_mktemp tar zxf mktemp-$version_mktemp.tar.gz ( cd mktemp-$version_mktemp ./configure --prefix=/bootstrap make make install ) rm -rf mktemp-$version_mktemp # To verify https connections, wget/openssl need some certificates. # They're installed directly here, instead of properly installing # update-ca-certificates. # app-misc/ca-certificates: rm -rf ca-certificates_$version_ca_certificates tar Jxf ca-certificates_$version_ca_certificates.tar.xz mv work ca-certificates_$version_ca_certificates ( cd ca-certificates_$version_ca_certificates make -C mozilla mkdir -p /bootstrap/share/ca-certificates/mozilla make -C mozilla CERTSDIR=/bootstrap/share/ca-certificates/mozilla install find mozilla -name '*.crt' | LC_ALL=C sort > ca-certificates.conf ./sbin/update-ca-certificates \ --certsconf "$PWD/ca-certificates.conf" \ --certsdir /bootstrap/share/ca-certificates \ --etccertsdir /bootstrap/etc/ssl/certs ) rm -rf ca-certificates_$version_ca_certificates # Finally, install the package manager. # sys-apps/portage: rm -rf portage-$version_portage tar jxf portage-$version_portage.tar.bz2 ( cd portage-$version_portage python3 setup.py install --system-prefix=/bootstrap # This path is hardcoded... # Symlinking the individual files so installing the final package will replace them properly. mkdir -p /usr/share/portage/config/sets ln -sf ../../../../bootstrap/share/portage/config/make.globals /usr/share/portage/config/make.globals ln -sf ../../../../bootstrap/share/portage/config/repos.conf /usr/share/portage/config/repos.conf ln -sf ../../../../../bootstrap/share/portage/config/sets/portage.conf /usr/share/portage/config/sets/portage.conf ) rm -rf portage-$version_portage ## ...but that's not all! ## Here come the dependencies to build the initial gcc/glibc! ## These can be installed directly with portage but it's significantly cleaner not to... # sys-devel/m4 (required by glibc-2.31): rm -rf m4-$version_m4 tar Jxf m4-$version_m4.tar.xz ( cd m4-$version_m4 ./configure --prefix=/bootstrap make make install ) rm -rf m4-$version_m4 # sys-devel/bison (required by glibc-2.31): rm -rf bison-$version_bison tar Jxf bison-$version_bison.tar.xz ( cd bison-$version_bison ./configure --prefix=/bootstrap make make install ) rm -rf bison-$version_bison # sys-devel/make (>=4.0 required by glibc-2.31): rm -rf make-$version_make tar jxf make-$version_make.tar.bz2 ( cd make-$version_make ./configure --prefix=/bootstrap make make install ) rm -rf make-$version_make # sys-apps/sed (>=4.3 required by glibc-2.31 for -E option): rm -rf sed-$version_sed tar Jxf sed-$version_sed.tar.xz ( cd sed-$version_sed ./configure --prefix=/bootstrap make make install ) rm -rf sed-$version_sed