makelni/common.d/common.fedora.sh

115 lines
3.5 KiB
Bash
Raw Normal View History

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"
2024-11-03 11:43:29 +00:00
local variant="$5"
2024-10-27 14:27:20 +00:00
[ ! -d "$rootdir" ] && {
log "Rootdir [$rootdir] does not exists" ierror
return 2
}
2024-11-03 11:43:29 +00:00
local xz_url="https://fedora.mirrorservice.org/fedora/linux/releases/$release/$edition/aarch64/images/Fedora-$variant-$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
[ -f "$xz_path" ] && rm "$xz_path"
2024-10-27 14:27:20 +00:00
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") || {
2024-10-27 14:27:20 +00:00
log "Failed to setup loop device" ierror
return 1
}
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
}
2024-11-03 12:45:17 +00:00
log "rSyncing system" internal
2024-10-27 14:27:20 +00:00
rsync -a --info=progress2 --info=name0 "$raw_mnt/root/"* "$rootdir/" || {
log "Failed to rsync system" ierror
return 1
}
2024-11-03 12:45:17 +00:00
log "Unmounting generic rootfs" internal
2024-10-27 14:27:20 +00:00
{
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"
2024-11-03 11:55:16 +00:00
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" || {
2024-10-27 14:27:20 +00:00
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
}