127 lines
4.3 KiB
Plaintext
127 lines
4.3 KiB
Plaintext
#!/bedrock/libexec/busybox sh
|
|
#
|
|
# Clear 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) 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() {
|
|
false
|
|
}
|
|
|
|
speed_test_url() {
|
|
echo "1/Manifest.MoM.tar"
|
|
}
|
|
|
|
list_mirrors() {
|
|
echo "https://cdn.download.clearlinux.org/"
|
|
}
|
|
|
|
brl_arch_to_distro() {
|
|
case "${1}" in
|
|
"x86_64") echo "x86_64" ;;
|
|
*) abort "brl does not know how to translate arch \"${1}\" to ${distro} format" ;;
|
|
esac
|
|
}
|
|
|
|
list_architectures() {
|
|
echo "x86_64"
|
|
}
|
|
|
|
default_release() {
|
|
echo "rolling"
|
|
}
|
|
|
|
list_releases() {
|
|
echo "rolling"
|
|
}
|
|
|
|
fetch() {
|
|
step "Calculating required bootstrap packages"
|
|
clear_update="$(download "${target_mirror}/current/latest" -)"
|
|
notice "Using update ${clear_update}"
|
|
download -q "${target_mirror}/update/${clear_update}/Manifest.MoM" "${bootstrap_dir}/Manifest.MoM"
|
|
loop=true
|
|
NL="
|
|
"
|
|
required_bundles="os-core-update"
|
|
while "${loop}"; do
|
|
loop=false
|
|
for bundle in ${required_bundles}; do
|
|
if [ -e "${bootstrap_dir}/Manifest.${bundle}" ]; then
|
|
continue
|
|
fi
|
|
loop=true
|
|
update="$(awk -v"bundle=${bundle}" '$0 ~ /^M/ && $4 == bundle {print $3; exit}' "${bootstrap_dir}/Manifest.MoM")"
|
|
download -q "${target_mirror}/update/${update}/Manifest.${bundle}" "${bootstrap_dir}/Manifest.${bundle}"
|
|
required_bundles="${required_bundles}${NL}$(awk '$1 == "includes:" {print $2}' "${bootstrap_dir}/Manifest.${bundle}")"
|
|
echo "${required_bundles}" | sort | uniq | grep "." >"${bootstrap_dir}/required_bundles"
|
|
echo "x"
|
|
done
|
|
done | progress_unknown
|
|
required_bundles="$(cat "${bootstrap_dir}/required_bundles")"
|
|
notice "Bundles required to bootstrap swupd: $(echo "${required_bundles}" | tr '\n' ' ')"
|
|
|
|
# Packs themselves aren't checksumed; their contents are. There isn't
|
|
# a clean way to invalidate cached packs here, so just download them
|
|
# every time.
|
|
step "Downloading bootstrap software"
|
|
total="$(echo "${required_bundles}" | wc -w)"
|
|
for bundle in ${required_bundles}; do
|
|
update="$(awk -v"bundle=${bundle}" '$0 ~ /^M/ && $4 == bundle {print $3; exit}' "${bootstrap_dir}/Manifest.MoM")"
|
|
download -q "${target_mirror}/update/${update}/pack-${bundle}-from-0.tar" "${bootstrap_dir}/pack-${bundle}-from-0.tar"
|
|
echo "x"
|
|
done | progress_bar "${total}"
|
|
|
|
step "Extracting bootstrap packages (1/2)"
|
|
for tarball in "${bootstrap_dir}/pack"*.tar; do
|
|
tar xf "${tarball}" -C "${bootstrap_dir}"
|
|
echo "x"
|
|
done | progress_bar "${total}"
|
|
|
|
step "Extracting bootstrap packages (2/2)"
|
|
rm "${bootstrap_dir}/Manifest.MoM"
|
|
total="$(awk 'NF==4' "${bootstrap_dir}/Manifest."* | wc -l)"
|
|
awk 'NF==4' "${bootstrap_dir}/Manifest."* | while read -r line; do
|
|
type="$(echo "${line}" | cut -d" " -f1)"
|
|
if echo "${type}" | grep -q '^[DFL]'; then
|
|
hash="$(echo "${line}" | cut -d" " -f2)"
|
|
path="$(echo "${line}" | cut -d" " -f4-)"
|
|
dest="${bootstrap_dir}/${path}"
|
|
mkdir -p "$(dirname "${dest}")"
|
|
cp -a "${bootstrap_dir}/staged/${hash}" "${dest}"
|
|
fi
|
|
echo "x"
|
|
done | progress_bar "${total}"
|
|
|
|
step "Running bootstrap software"
|
|
setup_chroot "${bootstrap_dir}"
|
|
setup_ssl "${bootstrap_dir}"
|
|
# system passwd/group confuses os-install's hash check
|
|
rm -f "${bootstrap_dir}/etc/passwd" "${bootstrap_dir}/etc/group"
|
|
# swupd appears to remove packs after use such that we can't cache them between runs.
|
|
LC_ALL=en_US.UTF-8 chroot "${bootstrap_dir}" swupd os-install --url "${target_mirror}/update" --no-boot-update --version "${clear_update}" -B os-core-update /target-root
|
|
|
|
step "Configuring"
|
|
# Setup certs
|
|
LC_ALL=C chroot "${target_dir}" clrtrust generate
|
|
mkdir -p "${target_dir}/etc/ssl"
|
|
ln -s /var/cache/ca-certs/anchors "${target_dir}/etc/ssl/certs"
|
|
# Clear Linux does not populate various /etc files on which Bedrock
|
|
# depends, even if their corresponding package is installed. Create
|
|
# them.
|
|
echo "# File created by Bedrock Linux during stratum fetch" >"${target_dir}/etc/profile"
|
|
if ! [ -e "${target_dir}/etc/zshenv" ]; then
|
|
mkdir -p "${target_dir}/etc/zsh/"
|
|
echo "# File created by Bedrock Linux during stratum fetch" >"${target_dir}/etc/zshenv"
|
|
fi
|
|
}
|