Created
August 25, 2020 09:57
-
-
Save SolitudeSF/2634b2dfd22f32ecbe33bbffb1d88137 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bedrock/libexec/busybox sh | |
| # | |
| # Obarun 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-2019 Daniel Thau <[email protected]> | |
| # | |
| # 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 "obcore/obcore.db.tar.gz" | |
| } | |
| list_mirrors(){ | |
| echo "https://repo.obarun.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" | |
| } | |
| setup_pacman() { | |
| # Remove auto architecture detection, as it will confuse things like | |
| # i686 on an x86_64 box and armv7hl on a aarch64 box. | |
| # | |
| # Also remove CheckSpace, which sometimes gets confused by Bedrock's | |
| # mount setup. | |
| 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 obarun archlinux | |
| 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}/\$repo/os/\$arch" >>"$1/etc/pacman.d/mirrorlist" | |
| fi | |
| } | |
| fetch_repo() { | |
| wget -O "${bootstrap_dir}/${1}.db.tar.gz" "${target_mirror}/${1}/${1}.db.tar.gz" | |
| mkdir -p "${bootstrap_dir}/pacmandb/${1}" | |
| } | |
| fetch_arch_repo() { | |
| wget -O "${bootstrap_dir}/${1}.db.tar.gz" "https://mirror.osbeck.com/archlinux/${1}/os/${distro_arch}/${1}.db.tar.gz" | |
| mkdir -p "${bootstrap_dir}/pacmandb/${1}" | |
| } | |
| unpack_repo() { | |
| tar -xv -f "${bootstrap_dir}/${1}.db.tar.gz" -C "${bootstrap_dir}/pacmandb/${1}/" | |
| } | |
| fetch() { | |
| bootstrap_deps="pacman" | |
| step "Downloading package information database" | |
| fetch_arch_repo core | |
| fetch_arch_repo extra | |
| fetch_arch_repo community | |
| fetch_repo obcore | |
| fetch_repo observice | |
| fetch_repo obextra | |
| fetch_repo obcommunity | |
| fetch_repo obmultilib | |
| step "Decompressing package information database" | |
| ( | |
| unpack_repo core | |
| unpack_repo extra | |
| unpack_repo community | |
| unpack_repo obcore | |
| unpack_repo observice | |
| unpack_repo obextra | |
| unpack_repo obcommunity | |
| unpack_repo obmultilib | |
| ) | 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/repo/os/arch/filename | |
| checksum_downloads "${cache}/packages/" "$(awk -v"a=${distro_arch}" -v"m=${target_mirror}" '{sub("/", "/os/"a"/"); print m"/"$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_pacman "${bootstrap_dir}" | |
| share_cache "packages" "${bootstrap_dir}/target-root/var/cache/pacman/pkg/" | |
| # sed is not included in base, but is needed to basestrap. | |
| LC_ALL=C chroot "${bootstrap_dir}" basestrap "/target-root" base sed | |
| 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 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment