#!/usr/bin/env bash source ./common.d/functions.sh source ./common.d/build_functions.sh source ./common.d/common.rpm.sh require "wget" require "pixz" require "losetup" require "rsync" require "pv" # shellcheck disable=SC2155 fetch_base_system() { local rootdir="$1" local release="$2" local releasever="$3" local edition="$4" local variant="$5" [ ! -d "$rootdir" ] && { log "Rootdir [$rootdir] does not exists" ierror return 2 } local xz_url="https://fedora.mirrorservice.org/fedora/linux/releases/$release/$edition/aarch64/images/Fedora-$variant-$release-$releasever.aarch64.raw.xz" local xz_path="./cache/Fedora-$edition-$release-$releasever.aarch64.raw.xz" local raw_path="./cache/Fedora-$edition-$release-$releasever.aarch64.raw" [ ! -f "$xz_path" ] && { log "Downloading generic rootfs from $xz_url" internal wget -q --show-progress -O "$xz_path" "$xz_url" || { log "Failed to download generic rootfs" ierror [ -f "$xz_path" ] && rm "$xz_path" return 1 } } [ ! -f "${raw_path}" ] && { log "Extracting generic rootfs" internal { pv "$xz_path" | pixz -d > "$raw_path"; } || { log "Failed to extract generic rootfs" ierror return 1 } } log "Mounting generic rootfs" internal local raw_loop raw_loop=$(losetup -Pf --show "$raw_path") || { log "Failed to setup loop device" ierror return 1 } local raw_mnt=$(mktemp --tmpdir=./tmp -d) mount "${raw_loop}p3" "$raw_mnt" || { log "Failed to mount loop device" ierror return 1 } log "rSyncing system" internal rsync -a --info=progress2 --info=name0 "$raw_mnt/root/"* "$rootdir/" || { log "Failed to rsync system" ierror return 1 } log "Unmounting generic rootfs" internal { umount "$raw_mnt" && rm -d "$raw_mnt" && losetup -d "$raw_loop" } || { log "Failed to umount generic rootfs" ierror return 1 } return 0 } prepare_system() { local rootdir="$1" [ ! -d "$rootdir" ] && { log "Rootdir [$rootdir] does not exists" ierror return 2 } log "Removing generic kernel and firmware" internal rm -rf "$rootdir/usr/lib/kernel/install.d/10-devicetree.instal" chroot "$rootdir" /usr/bin/bash -c "rpm --noscripts -e qcom-firmware atheros-firmware brcmfmac-firmware amd-ucode-firmware kernel-core nvidia-gpu-firmware kernel kernel-modules kernel-modules-core intel-audio-firmware cirrus-audio-firmware nvidia-gpu-firmware linux-firmware linux-firmware-whence intel-gpu-firmware amd-gpu-firmware libertas-firmware mt7xxx-firmware nxpwireless-firmware realtek-firmware tiwilink-firmware" || { log "Failed to remove generic kernel and firmware" ierror return 1 } chroot "$rootdir" rm -rf "/boot/*" return 0 } setup_zram_generator() { local rootdir="$1" [ ! -d "$rootdir" ] && { log "Rootdir [$rootdir] does not exists" ierror return 2 } log "Configuring zram-generator" internal cp ./drop/zram-generator.conf "$rootdir/etc/systemd/zram-generator.conf" || { log "Failed to confugire zram-generator" ierror return 1 } log "Enabling zram-generator" internal chroot "$rootdir" systemctl enable systemd-zram-setup@zram0.service || { log "Failed to enable zram-generator" ierror return 1 } return 0 }