127 lines
3.9 KiB
Plaintext
127 lines
3.9 KiB
Plaintext
#!/bedrock/libexec/busybox sh
|
|
#
|
|
# Gentoo Linux 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/verify-digests.sh"
|
|
}
|
|
|
|
list_mirrors() {
|
|
mirror_list_url="https://www.gentoo.org/downloads/mirrors/"
|
|
download -q "${mirror_list_url}" - |
|
|
awk '/Region/,/<footer>/' |
|
|
list_links |
|
|
grep "^http"
|
|
}
|
|
|
|
brl_arch_to_distro() {
|
|
case "${1}" in
|
|
"aarch64") echo "arm64" ;;
|
|
"armv7hl") echo "armv7a_hardfp" ;;
|
|
"armv7l") echo "armv7a" ;;
|
|
"i486") echo "i486" ;;
|
|
"i686") echo "i686" ;;
|
|
"ppc") echo "ppc" ;;
|
|
"ppc64") echo "ppc64" ;;
|
|
"ppc64le") echo "ppc64le" ;;
|
|
"s390x") echo "s3960x" ;;
|
|
"x86_64") echo "amd64" ;;
|
|
*) abort "brl does not know how to translate arch \"${1}\" to ${distro} format" ;;
|
|
esac
|
|
}
|
|
|
|
list_architectures() {
|
|
cat <<EOF
|
|
armv7hl
|
|
armv7l
|
|
ppc
|
|
ppc64
|
|
ppc64le
|
|
s390x
|
|
i486
|
|
i686
|
|
x86_64
|
|
EOF
|
|
}
|
|
|
|
default_release() {
|
|
echo "rolling"
|
|
}
|
|
|
|
list_releases() {
|
|
echo "rolling"
|
|
}
|
|
|
|
fetch() {
|
|
# Which flavors are available for a given stage 3 appears to be
|
|
# variable depending on time and mirror. Iterate through possibilities
|
|
# in minimal-to-maximal order and go with the first found.
|
|
#
|
|
# TODO: In Bedrock 0.8.0 when `brl fetch --flavor` is available make desktop
|
|
# vs hardened vs musl, openrc vs systemd, etc flavors.
|
|
flavors="minimal openrc desktop-openrc"
|
|
|
|
step "Finding bootstrap software"
|
|
# stage3 balls are not necessarily in the obvious directory; need to
|
|
# search multiple to find where the tarball we are interested in is.
|
|
groups="$(download -q "${target_mirror}/releases/" - |
|
|
list_links |
|
|
grep '/$' |
|
|
sed -e 's,/$,,')"
|
|
group_flavor="$(for group in ${groups}; do
|
|
page="$(download -q "${target_mirror}/releases/${group}/autobuilds/" -)"
|
|
for flavor in ${flavors}; do
|
|
if echo "${page}" | list_links | grep "^current-stage3-${distro_arch}-${flavor}/$" >/dev/null; then
|
|
echo "${group}"
|
|
echo "${flavor}"
|
|
return
|
|
fi
|
|
done
|
|
done)"
|
|
echo "group_flavor: ${group_flavor}"
|
|
group="$(echo "${group_flavor}" | sed -n 1p)"
|
|
flavor="$(echo "${group_flavor}" | sed -n 2p)"
|
|
if [ -z "${group}" ] || [ -z "${flavor}" ]; then
|
|
abort "Could not find bootstrap software at ${target_mirror} for ${distro_arch}."
|
|
fi
|
|
|
|
step "Downloading bootstrap software"
|
|
bootstrap_url="$(find_link "${target_mirror}/releases/${group}/autobuilds/current-stage3-${distro_arch}-${flavor}/" "^stage3-${distro_arch}-${flavor}-[^.]*[.]tar[.]\(xz\|bz2\)$")"
|
|
bootstrap_name="$(echo "${bootstrap_url}" | sed 's,^.*/,,')"
|
|
download "${bootstrap_url}.DIGESTS" "${bootstrap_dir}/checksum"
|
|
bootstrap_checksum="$(awk -v"name=${bootstrap_name}" '/^# .* HASH$/ {hash=$2;next} hash == "SHA512" && $2 == name {print$1;exit}' "${bootstrap_dir}/checksum")"
|
|
cache_name="stage3.tar.$(echo "${bootstrap_name}" | sed 's/^.*[.]//')"
|
|
checksum_download "${cache}/${cache_name}" "sha512sum" "${bootstrap_checksum}" "${bootstrap_url}"
|
|
|
|
step "Preparing bootstrap software"
|
|
tar -xv -f "${cache}/${cache_name}" -C "${bootstrap_dir}" | awk 'NR%100==0' | progress_unknown
|
|
|
|
step "Running bootstrap software"
|
|
setup_chroot "${bootstrap_dir}"
|
|
setup_ssl "${bootstrap_dir}"
|
|
share_cache "." "${bootstrap_dir}/tarballs"
|
|
chroot "${bootstrap_dir}" sh -c "cd /target-root && tar xpfv /tarballs/stage3.tar.* --xattrs-include='*.*' --numeric-owner" | awk 'NR%100==0' | progress_unknown
|
|
|
|
step "Configuring"
|
|
setup_chroot "${target_dir}"
|
|
echo "GENTOO_MIRRORS=\"${target_mirror}\"" >>"${target_dir}/etc/portage/make.conf"
|
|
mkdir -p "${target_dir}/etc/portage/repos.conf"
|
|
cp "${target_dir}/usr/share/portage/config/repos.conf" "${target_dir}/etc/portage/repos.conf/gentoo.conf"
|
|
LC_ALL=C chroot "${target_dir}" emerge-webrsync
|
|
}
|