# Template file for 'bedrock-linux' OSNAME="bedrock-linux" PRETTY="Bedrock Linux" LOGO="" ICON="bedrock-linux.svg" CATEGORY="Meta-distribution" BASEDOF="Selectable Bedrock-compatible base distro" HOMEPAGE="https://bedrocklinux.org" DESCRIPTION="Choose a Bedrock-compatible base distro, release, and edition, or reuse a prepared Linux VM config. DistroHopper downloads the selected installer or copies the prepared VM disk, then creates a Bedrock VM for the Bedrock hijack." CREDENTIALS="Set during base installation" GPG="" RSS="" DW="" GUEST="linux" function releases_() { web_pipe "https://raw.githubusercontent.com/bedrocklinux/bedrocklinux-userland/0.7/releases" \ | sed '/^# Past releases/,$d' \ | grep -oE 'bedrock-linux-[0-9]+\.[0-9]+\.[0-9]+-x86_64\.sh' \ | head -n 1 \ | cut -d- -f3 } function editions_() { case "${ARCH}" in amd64) echo alpine-linux arch-linux artix-linux centos-stream debian devuan-gnu-linux gentoo-linux ubuntu-server void-linux;; arm64) echo alpine-linux centos-stream debian raspberry-pi-os void-linux;; esac } function arch_() { echo amd64 arm64 } function _base_template_() { case "${1}" in alpine|alpine-linux) echo alpine-linux;; arch|arch-linux) echo arch-linux;; devuan|devuan-gnu-linux) echo devuan-gnu-linux;; gentoo|gentoo-linux) echo gentoo-linux;; void|void-linux) echo void-linux;; ubuntu-server) echo ubuntu-server;; *) echo "${1}";; esac } function _base_releases_() { local BASE_OS="${1}" if [ "${BASE_OS}" == "artix-linux" ]; then local BASE_ISOS="" local attempt for attempt in 1 2 3; do BASE_ISOS=$(web_pipe "https://mirror3.artixlinux.org/iso/" \ | grep -oE 'artix-[A-Za-z0-9-]+-[0-9]{8}-x86_64[.]iso') [ -n "${BASE_ISOS}" ] && break sleep 2 done echo "${BASE_ISOS}" \ | sed -E 's/^artix-.*-([0-9]{8})-x86_64[.]iso$/\1/' \ | sort -Vu | tail -n 1 return fi if [ "${BASE_OS}" == "ubuntu-server" ]; then web_pipe "http://releases.ubuntu.com/streams/v1/com.ubuntu.releases:ubuntu-server.json" \ | jq -r '.products[] | select(.arch=="amd64" and .image_type=="live-server" and (.version | endswith(".04"))) | .version' \ | sort -Vr return fi local BASE_TEMPLATE="$(_base_template_ "${BASE_OS}")" ( unset -f releases_ editions_ arch_ get_ config_ extract_ OS="${BASE_TEMPLATE}" . "${TEMPLATES_DIR}/${BASE_TEMPLATE}" releases_ ) } function _base_editions_() { local BASE_OS="${1}" local SELECTED_RELEASE="${2:-$(_base_releases_ "${BASE_OS}" | awk 'NR == 1 {print $1; exit}')}" if [ "${BASE_OS}" == "artix-linux" ]; then local RELEASE="" local BASE_ISOS="" RELEASE=$(_base_releases_ artix-linux) local attempt for attempt in 1 2 3; do BASE_ISOS=$(web_pipe "https://mirror3.artixlinux.org/iso/" \ | grep -oE "artix-[A-Za-z0-9-]+-${RELEASE}-x86_64[.]iso") [ -n "${BASE_ISOS}" ] && break sleep 2 done echo "${BASE_ISOS}" | sed -E "s/^artix-(.*)-${RELEASE}-x86_64[.]iso$/\\1/" | sort -u return fi local BASE_TEMPLATE="$(_base_template_ "${BASE_OS}")" if [ "${BASE_TEMPLATE}" == "debian" ] && [ "${ARCH}" == "arm64" ]; then echo netinst return fi ( unset -f releases_ editions_ arch_ get_ config_ extract_ OS="${BASE_TEMPLATE}" . "${TEMPLATES_DIR}/${BASE_TEMPLATE}" if declare -F editions_ >/dev/null; then RELEASE="${SELECTED_RELEASE}" editions_ fi ) } function get_() { local BASE_OS="${EDITION}" local BASE_TEMPLATE="$(_base_template_ "${BASE_OS}")" local SELECTED_RELEASE="${BASE_RELEASE:-$(_base_releases_ "${BASE_OS}" | awk 'NR == 1 {print $1; exit}')}" local SELECTED_EDITION="${BASE_EDITION:-$(_base_editions_ "${BASE_OS}" "${SELECTED_RELEASE}" | awk 'NR == 1 {print $1; exit}')}" local URL="" local ISO="" local HASH="" case "${BASE_TEMPLATE}" in artix-linux) if [ -z "${SELECTED_RELEASE}" ] || [ -z "${SELECTED_EDITION}" ]; then # Mirror temporarily unavailable: skip instead of emitting a broken URL. return 0 fi URL="https://mirror3.artixlinux.org/iso" ISO="artix-${SELECTED_EDITION}-${SELECTED_RELEASE}-x86_64.iso" HASH=$(web_pipe "${URL}/sha256sums" | awk -v iso="${ISO}" '$2 == iso {print $1; exit}') echo "${URL}/${ISO} ${HASH}" ;; gentoo-linux) URL="https://distfiles.gentoo.org/releases/amd64/autobuilds" local ISO_PATH="" ISO_PATH=$(web_pipe "${URL}/${SELECTED_RELEASE}-iso.txt" \ | awk -v edition="${SELECTED_EDITION}" '((edition == "minimal") && $1 ~ /install-amd64-minimal-/) || ((edition == "livegui") && $1 ~ /livegui-amd64-/) {print $1; exit}') ISO="${ISO_PATH##*/}" HASH=$(web_pipe "${URL}/${ISO_PATH}.DIGESTS" \ | awk -v iso="${ISO}" '$0 == "# SHA512 HASH" {sha=1; next} /^#/ {sha=0} sha && $2 == iso {print $1; exit}') echo "${URL}/${ISO_PATH} ${HASH}" ;; ubuntu-server) local NAME="live-server" if [[ "${SELECTED_RELEASE}" == daily* ]]; then URL="https://cdimage.ubuntu.com/${BASE_TEMPLATE}/${SELECTED_RELEASE}/current" else URL="https://releases.ubuntu.com/${SELECTED_RELEASE}" fi case "${SELECTED_RELEASE}" in 14*|16*) NAME="server";; esac if web_check "${URL}/SHA256SUMS"; then local IMAGE_DATA="" IMAGE_DATA=$(web_pipe "${URL}/SHA256SUMS" | grep "${NAME}" | grep amd64 | grep iso | head -n 1) ISO=$(cut -d'*' -f2 <<<"${IMAGE_DATA}") HASH=$(cut -d' ' -f1 <<<"${IMAGE_DATA}") else local IMAGE_DATA="" IMAGE_DATA=$(web_pipe "${URL}/MD5SUMS" | grep "${NAME}" | grep amd64 | grep iso | head -n 1) ISO=$(cut -d' ' -f3 <<<"${IMAGE_DATA}") HASH=$(cut -d' ' -f1 <<<"${IMAGE_DATA}") fi echo "${URL}/${ISO} ${HASH}" ;; raspberry-pi-os) # Raspberry Pi OS is published as a pre-flashed disk image, not # as an installer ISO. The image becomes the system disk of the # VM, so it is attached as img= instead of iso=. URL="https://downloads.raspberrypi.com/raspios_lite_arm64/images/raspios_lite_arm64-${SELECTED_RELEASE}" ISO=$(web_pipe "${URL}/" | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}-raspios-[a-z]+-arm64-lite\.img\.xz' | head -n 1) HASH=$(web_pipe "${URL}/${ISO}.sha256" | head -n 1 | cut -d' ' -f1) # The image is the disk itself, not a boot medium. IMAGE_TYPE="none" echo "${URL}/${ISO} ${HASH}" ;; *) ( unset -f releases_ editions_ arch_ get_ config_ extract_ OS="${BASE_TEMPLATE}" . "${TEMPLATES_DIR}/${BASE_TEMPLATE}" RELEASE="${SELECTED_RELEASE}" EDITION="${SELECTED_EDITION}" get_ ) ;; esac } function extract_() { local INSTALLER_ARCH="x86_64" [ "${ARCH}" == "arm64" ] && INSTALLER_ARCH="aarch64" local INSTALLER="bedrock-linux-${RELEASE}-${INSTALLER_ARCH}.sh" local INSTALLER_URL="https://github.com/bedrocklinux/bedrocklinux-userland/releases/download/${RELEASE}/${INSTALLER}" local BASE_DESCRIPTION="${BASE_OS} ${BASE_RELEASE} ${BASE_EDITION}" # A Raspberry Pi OS base is a pre-flashed disk image: it is decompressed # and becomes the disk of the VM. There is no installer to run, so the # Bedrock hijack is applied to the running system directly. if [ "${BASE_OS}" == "raspberry-pi-os" ] && [[ "${ISO}" == *.img.xz ]]; then echo "Decompressing ${ISO}..." xz -dkf "${VM_PATH}/${ISO}" || { echo "ERROR! Could not decompress ${ISO}." >&2 return 1 } local RAW="${ISO%.xz}" rm -f "${VM_PATH}/${ISO}" QEMU_IMG=$(command -v qemu-img) if [ ! -x "${QEMU_IMG}" ]; then echo "ERROR! qemu-img not found. Please make sure qemu-img is installed." >&2 return 1 fi echo "Converting ${RAW} to qcow2..." qemu-img convert -f raw -O qcow2 "${VM_PATH}/${RAW}" "${VM_PATH}/disk.qcow2" || { echo "ERROR! Could not convert ${RAW}." >&2 return 1 } rm -f "${VM_PATH}/${RAW}" ISO="" fi echo if [ "${BASE_OS}" == "prepared" ]; then echo "After booting the copied ${BASE_RELEASE} VM, run the Bedrock hijack as root:" elif [ "${BASE_OS}" == "raspberry-pi-os" ]; then echo "After booting into the Raspberry Pi OS VM, run the Bedrock hijack as root:" else echo "After installing ${BASE_DESCRIPTION} and booting into the new system, run the Bedrock hijack as root:" fi echo " wget '${INSTALLER_URL}'" echo " su -c 'sh ./${INSTALLER} --hijack'" echo " reboot" } function config_() { echo 'disk_size="32G"' >> "${CONF_FILE}" }