diff --git a/src/slash-bedrock/share/brl-fetch/distros/fedora-rawhide b/src/slash-bedrock/share/brl-fetch/distros/fedora-rawhide new file mode 100644 index 00000000..e4e4727c --- /dev/null +++ b/src/slash-bedrock/share/brl-fetch/distros/fedora-rawhide @@ -0,0 +1,153 @@ +#!/bedrock/libexec/busybox sh +# +# Fedora Rawhide bootstrap support +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 2 as published by the Free Software Foundation. +# +# Copyright (c) 2016-2020 Daniel Thau q +# + +# shellcheck source=src/slash-bedrock/libexec/brl-fetch +. /bedrock/share/common-code +trap 'fetch_abort "Unexpected error occurred."' EXIT + +check_supported() { + true +} + +speed_test_url() { + echo "development/rawhide/Everything/${distro_arch}/os/repodata/repomd.xml" +} + +list_mirrors() { + wget -O- "https://mirrors.fedoraproject.org/mirrorlist?repo=fedora-rawhide&arch=${distro_arch}" 2>/dev/null | + sed -e 's,/$,,' | + sed 's,/[^/]*/[^/]*/[^/]*/[^/]*/[^/]*$,,' +} + +brl_arch_to_distro() { + case "${1}" in + "aarch64") echo "aarch64" ;; + "armv7hl") echo "armhfp" ;; + "ppc64le") echo "ppc64le" ;; + "s390x") echo "s390x" ;; + # Mirrors call it i386, but repo calls it i686. + "i686") echo "i386" ;; + "x86_64") echo "x86_64" ;; + *) abort "brl does not know how to translate arch \"${1}\" to ${distro} format" ;; + esac +} + +list_architectures() { + cat <' "${bootstrap_dir}/brldb/depends/dn"; then + echo "dnf" + else + echo "yum" + fi +} + +bootstrap_deps() { + echo "${package_manager} rpm fedora-release filesystem" +} + +fetch() { + suffix="development/rawhide/Everything/${distro_arch}/os" + + step "Downloading package information database" + url="$(find_link "${target_mirror}/${suffix}/repodata/" "primary.xml.gz")" + wget -O "${bootstrap_dir}/primary.xml.gz" "${url}" + + step "Extracting package information database" + gunzip "${bootstrap_dir}/primary.xml.gz" + + step "Converting distro package information database to brl format" + if [ "${target_arch}" = i686 ]; then + distro_arch="i686" rpmdb_to_brldb "${bootstrap_dir}/primary.xml" "${bootstrap_dir}/brldb" + else + rpmdb_to_brldb "${bootstrap_dir}/primary.xml" "${bootstrap_dir}/brldb" + fi + + step "Calculating required bootstrap packages" + package_manager="$(determine_package_manager)" + brldb_calculate_required_packages "${bootstrap_dir}/brldb" "${bootstrap_dir}/required_packages" "$(bootstrap_deps)" + + step "Downloading bootstrap packages" + checksum_downloads "${cache}/packages/" "$(awk -v"m=${target_mirror}/${suffix}" '{print m"/"$0}' "${bootstrap_dir}/required_packages")" + + step "Extracting bootstrap packages" + # This round is just to bootstrap the distro's rpm. + # Next step we'll use the distro's rpm to install everything properly. + # Need to extract filesystem first to ensure symlinks are set up + bootstrap_packages="$(awk -v"d=${cache}/packages/" '{sub(/^.*\//,d);print $1}' "${bootstrap_dir}/required_packages")" + # shellcheck disable=SC2086 + extract_rpms "${bootstrap_dir}" "${cache}/packages"/filesystem*.rpm ${bootstrap_packages} + + step "Installing bootstrap packages" + setup_chroot "${bootstrap_dir}" + share_cache "packages" "${bootstrap_dir}/packages" + bootstrap_packages="$(awk -v"d=/packages/" '{sub(/^.*\//,d);print $1}' "${bootstrap_dir}/required_packages")" + # shellcheck disable=SC2086 + LC_ALL=C chroot "${bootstrap_dir}" rpm -i ${bootstrap_packages} + + step "Running bootstrap software" + # By default, yum clears anything in its package cache. Configure it + # to retain them so we can leverage previous cached packages. + if [ -e "${bootstrap_dir}/etc/dnf/dnf.conf" ] && grep -q "^keepcache=1$" "${bootstrap_dir}/etc/dnf/dnf.conf"; then + share_cache "dnf-cache" "${bootstrap_dir}/target-root/var/cache/dnf" + elif [ -e "${bootstrap_dir}/etc/dnf/dnf.conf" ] && grep -q "^keepcache=0$" "${bootstrap_dir}/etc/dnf/dnf.conf"; then + sed 's/^keepcache=0$/keepcache=1/' "${bootstrap_dir}/etc/dnf/dnf.conf" >"${bootstrap_dir}/etc/dnf/dnf.conf-new" + mv "${bootstrap_dir}/etc/dnf/dnf.conf-new" "${bootstrap_dir}/etc/dnf/dnf.conf" + share_cache "dnf-cache" "${bootstrap_dir}/target-root/var/cache/dnf" + elif [ -r "${bootstrap_dir}/etc/dnf/dnf.conf" ]; then + echo "keepcache=1" >>"${bootstrap_dir}/etc/dnf/dnf.conf" + share_cache "dnf-cache" "${bootstrap_dir}/target-root/var/cache/dnf" + elif [ -e "${bootstrap_dir}/etc/yum.conf" ] && grep -q "^keepcache=1$" "${bootstrap_dir}/etc/yum.conf"; then + share_cache "yum-cache" "${bootstrap_dir}/target-root/var/cache/yum" + elif [ -e "${bootstrap_dir}/etc/yum.conf" ] && grep -q "^keepcache=0$" "${bootstrap_dir}/etc/yum.conf"; then + sed 's/^keepcache=0$/keepcache=1/' "${bootstrap_dir}/etc/yum.conf" >"${bootstrap_dir}/etc/yum.conf-new" + mv "${bootstrap_dir}/etc/yum.conf-new" "${bootstrap_dir}/etc/yum.conf" + share_cache "yum-cache" "${bootstrap_dir}/target-root/var/cache/yum" + elif [ -r "${bootstrap_dir}/etc/yum.conf" ]; then + echo "keepcache=1" >>"${bootstrap_dir}/etc/yum.conf" + share_cache "yum-cache" "${bootstrap_dir}/target-root/var/cache/yum" + fi + + # Configure the package manager to utilize the desired architecture + if [ "${target_arch}" = "i686" ]; then + mkdir -p "${bootstrap_dir}/etc/${package_manager}/vars/" + echo 'i686' >"${bootstrap_dir}/etc/${package_manager}/vars/arch" + echo 'i386' >"${bootstrap_dir}/etc/${package_manager}/vars/basearch" + mkdir -p "${target_dir}/etc/${package_manager}/vars/" + echo 'i686' >"${target_dir}/etc/${package_manager}/vars/arch" + echo 'i386' >"${target_dir}/etc/${package_manager}/vars/basearch" + fi + + LC_ALL=C chroot "${bootstrap_dir}" rpm -i --root=/target-root --nodeps ./packages/fedora-release-*.rpm 2>/dev/null || true + LC_ALL=C chroot "${bootstrap_dir}" "${package_manager}" --installroot=/target-root install -y rpm-build "${package_manager}" fedora-repos + # Need to set database timestamps for pmm due to `dnf -C` usage + umount -l "${bootstrap_dir}/var/cache/dnf" >/dev/null 2>&1 || true + umount -l "${bootstrap_dir}/var/cache/yum" >/dev/null 2>&1 || true + setup_chroot "${target_dir}" + LC_ALL=C chroot "${target_dir}" "${package_manager}" -y update +}