loongbedrocklinux-userlandd/src/slash-bedrock/share/brl-fetch/distros/arch-32

130 lines
4.5 KiB
Plaintext

#!/bedrock/libexec/busybox sh
#
# Arch Linux 32 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-2019 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 "${distro_arch}/core/core.db.tar.gz"
}
list_mirrors() {
mirror_list_url='https://www.archlinux32.org/mirrorlist/?country=all'
download -q "${mirror_list_url}" - |
sed 's/^# *//' |
awk -F "[ $]" '/^Server/{print$3}'
}
brl_arch_to_distro() {
# Arch Linux 32 also supports Pentium 4 / Netburst / i786. However,
# they are the only distro to do so, and at the time of writing it is
# not deemed worthwhile to support an architecture only utilized by one
# distro, especially since it is compatible with i686.
case "${1}" in
"i486") echo "i486" ;;
"i686") echo "i686" ;;
*) abort "brl does not know how to translate arch \"${1}\" to ${distro} format" ;;
esac
}
list_architectures() {
cat <<EOF
i486
i686
EOF
}
default_release() {
echo "rolling"
}
list_releases() {
echo "rolling"
}
setup_pacman() {
sed 's/^Architecture[ \t]*=.*$//' "${1}/etc/pacman.conf" |
awk -v"a=${distro_arch}" '{print} $0 == "[options]" {print "Architecture = "a}' |
sed 's/^[ \t]*CheckSpace/# &/' \
>"${1}/etc/pacman.conf-new"
mv "${1}/etc/pacman.conf-new" "${1}/etc/pacman.conf"
LC_ALL=C chroot "${1}" /usr/bin/update-ca-trust
LC_ALL=C chroot "${1}" /usr/bin/pacman-key --init
LC_ALL=C chroot "${1}" /usr/bin/pacman-key --populate archlinux32
if ! grep -q "^Server" "${1}/etc/pacman.d/mirrorlist"; then
echo "### Set by Bedrock Linux when acquiring this stratum" >>"${1}/etc/pacman.d/mirrorlist"
echo "Server = ${target_mirror}/\$arch/\$repo" >>"$1/etc/pacman.d/mirrorlist"
fi
}
fetch() {
bootstrap_deps="arch-install-scripts"
step "Downloading package information database"
download "${target_mirror}/${distro_arch}/core/core.db.tar.gz" "${bootstrap_dir}/core.db.tar.gz"
download "${target_mirror}/${distro_arch}/extra/extra.db.tar.gz" "${bootstrap_dir}/extra.db.tar.gz"
download "${target_mirror}/${distro_arch}/community/community.db.tar.gz" "${bootstrap_dir}/community.db.tar.gz"
step "Decompressing package information database"
mkdir -p "${bootstrap_dir}/pacmandb/core" "${bootstrap_dir}/pacmandb/extra" "${bootstrap_dir}/pacmandb/community"
(
tar -xv -f "${bootstrap_dir}/core.db.tar.gz" -C "${bootstrap_dir}/pacmandb/core/"
tar -xv -f "${bootstrap_dir}/extra.db.tar.gz" -C "${bootstrap_dir}/pacmandb/extra/"
tar -xv -f "${bootstrap_dir}/community.db.tar.gz" -C "${bootstrap_dir}/pacmandb/community/"
) | awk 'NR%100==0' | progress_unknown
step "Converting distro package information database to brl format"
pacmandb_to_brldb "${bootstrap_dir}/pacmandb" "${bootstrap_dir}/brldb"
step "Calculating required bootstrap packages"
brldb_calculate_required_packages "${bootstrap_dir}/brldb" "${bootstrap_dir}/required_packages" "${bootstrap_deps}"
step "Downloading bootstrap packages"
# brldb contains repo/filename
# files are at mirror/arch/repo/filename
checksum_downloads "${cache}/packages/" "$(awk -v"a=${distro_arch}" -v"m=${target_mirror}" '{print m"/"a"/"$0}' "${bootstrap_dir}/required_packages")"
step "Extracting bootstrap packages"
bootstrap_packages="$(awk -v"d=${cache}/packages/" '{sub(/^.*\//,d);print $1}' "${bootstrap_dir}/required_packages")"
# shellcheck disable=SC2086
extract_pacman_pkgs "${bootstrap_dir}" ${bootstrap_packages}
step "Running bootstrap software"
# pacstrap mounts devtmpfs (which is shared with the host system) and
# chowns files in it based on /etc/passwd and /etc/group. Ensure
# system copies of files are used to avoid problematic file ownership
# change in /dev.
mkdir -p "${target_dir}/etc"
cp -a "/etc/passwd" "${target_dir}/etc/passwd"
cp -a "/etc/group" "${target_dir}/etc/group"
setup_chroot "${bootstrap_dir}"
setup_ssl "${bootstrap_dir}"
setup_pacman "${bootstrap_dir}"
share_cache "packages" "${bootstrap_dir}/target-root/var/cache/pacman/pkg/"
LC_ALL=C chroot "${bootstrap_dir}" pacstrap "/target-root" base
step "Configuring"
setup_chroot "${target_dir}"
setup_pacman "${target_dir}"
cp "${cache}/packages/"* "${target_dir}/var/cache/pacman/"
if LC_ALL=C chroot "${target_dir}" pacman -Q linux >/dev/null 2>&1; then
LC_ALL=C chroot "${target_dir}" pacman --noconfirm -R linux
fi
}