2024-10-27 14:27:20 +00:00
|
|
|
#!/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"
|
|
|
|
[ ! -d "$rootdir" ] && {
|
|
|
|
log "Rootdir [$rootdir] does not exists" ierror
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
2024-11-03 11:34:44 +00:00
|
|
|
local xz_url="https://fedora.mirrorservice.org/fedora/linux/releases/$release/$edition/aarch64/images/Fedora-$release-$releasever.aarch64.raw.xz"
|
2024-10-27 14:27:20 +00:00
|
|
|
local xz_path="./cache/Fedora-$edition-$release-$releasever.aarch64.raw.xz"
|
|
|
|
local raw_path="./cache/Fedora-$edition-$release-$releasever.aarch64.raw"
|
|
|
|
|
|
|
|
[ ! -f "$xz_path" ] && {
|
2024-11-03 11:39:50 +00:00
|
|
|
log "Downloading generic rootfs from $xz_url" internal
|
2024-11-02 15:20:57 +00:00
|
|
|
wget -q --show-progress -O "$xz_path" "$xz_url" || {
|
2024-10-27 14:27:20 +00:00
|
|
|
log "Failed to download generic rootfs" ierror
|
|
|
|
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
|
2024-10-27 15:12:47 +00:00
|
|
|
raw_loop=$(losetup -Pf --show "$raw_path") || {
|
2024-10-27 14:27:20 +00:00
|
|
|
log "Failed to setup loop device" ierror
|
|
|
|
return 1
|
|
|
|
}
|
2024-10-27 15:12:47 +00:00
|
|
|
local raw_mnt=$(mktemp --tmpdir=./tmp -d)
|
2024-10-27 14:27:20 +00:00
|
|
|
mount "${raw_loop}p3" "$raw_mnt" || {
|
|
|
|
log "Failed to mount loop device" ierror
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
log "rSyncing system"
|
|
|
|
rsync -a --info=progress2 --info=name0 "$raw_mnt/root/"* "$rootdir/" || {
|
|
|
|
log "Failed to rsync system" ierror
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
log "Unmounting generic rootfs"
|
|
|
|
{
|
|
|
|
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 gnome-initial-setup 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
|
|
|
|
}
|