loongbedrocklinux-userlandd/src/slash-bedrock/share/brl-fetch/distros/fedora

192 lines
7.4 KiB
Plaintext

#!/bedrock/libexec/busybox sh
#
# Fedora 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-2021 Daniel Thau <danthau@bedrocklinux.org>
#
# 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 "releases/${target_release}/Everything/${distro_arch}/os/repodata/repomd.xml"
}
list_mirrors() {
download -q "https://mirrors.fedoraproject.org/mirrorlist?repo=fedora-${target_release}&arch=${distro_arch}" - |
grep -ve '^[ \t]*#' |
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() {
list_releases |
sort -n |
tail -n1
}
list_releases() {
download -q 'https://dl.fedoraproject.org/pub/fedora/linux/releases/' - |
list_links |
grep '^[0-9][0-9]*/$' |
sed 's,/$,,' |
sort -n
}
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 fedora-gpg-keys"
}
fetch() {
suffix="releases/${target_release}/Everything/${distro_arch}/os"
step "Downloading package information database"
url="$(find_link "${target_mirror}/${suffix}/repodata/" "primary.xml.gz")"
download "${url}" "${bootstrap_dir}/primary.xml.gz"
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
# CentOS arch name is i386 in mirrors but i686 in package manager
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}"
# setup_ssl "${bootstrap_dir}" # fights with yum/dnf later on, not actually needed
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}" sh -c 'rpm --import /etc/pki/rpm-gpg/*'
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
step "Configuring"
setup_chroot "${target_dir}"
LC_ALL=C chroot "${target_dir}" "${package_manager}" -y update
# Fedora does not use localegen; need to special case locale handling.
LC_ALL=C chroot "${target_dir}" "${package_manager}" -y install glibc-locale-source
localegen="$(cfg_values "locale" "localegen")"
if [ -n "${localegen}" ]; then
unset IFS
echo "${localegen}" | while read -r line; do
name="$(echo "${line}" | cut -d'.' -f1)"
locale="$(echo "${line}" | cut -d' ' -f1)"
charset="$(echo "${line}" | cut -d' ' -f2)"
if [ -e "${target_dir}/usr/share/locale/${name}" ]; then
input="${name}"
else
notice "${color_warn}Could not set \"${locale} ${charset}\" locale, skipping.${color_norm}"
continue
fi
if [ -e "${target_dir}/usr/share/locale/locale.alias" ]; then
alias="-A /usr/share/locale/locale.alias"
else
unset alias
fi
if ! LC_ALL=C chroot "${target_dir}" localedef -i "${input:-}" -c -f "${charset}" ${alias:-} "${locale}"; then
notice "${color_warn}Could not set \"${locale} ${charset}\" locale, skipping.${color_norm}"
fi
done
fi
}