Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create fedora-rawhide #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions src/slash-bedrock/share/brl-fetch/distros/fedora-rawhide
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>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 <<EOF
aarch64
armv7hl
ppc64le
s390x
i686
x86_64
EOF
}

default_release() {
echo "rolling"
}

list_releases() {
echo "rolling"
}

determine_package_manager() {
if [ -e "${bootstrap_dir}/brldb/depends/dn" ] && grep -q '^dnf\>' "${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
}