159 lines
4.1 KiB
Bash
159 lines
4.1 KiB
Bash
#!/usr/bin/env bash
|
|
source ./common.d/functions.sh
|
|
source ./common.d/build_functions.sh
|
|
|
|
require "wget"
|
|
require "bsdtar"
|
|
|
|
# shellcheck disable=SC2086
|
|
fetch_base_system()
|
|
{
|
|
local rootdir="$1"
|
|
local src="$2"
|
|
local filename="./cache/$(basename "${src%%\?*}")"
|
|
|
|
[ ! -d "$rootdir" ] && {
|
|
log "Rootdir [$rootdir] does not exists" ierror
|
|
return 2
|
|
}
|
|
|
|
if [ ! -f "$filename" ]; then
|
|
log "Downloading rootfs tarball" internal
|
|
wget -O "$filename" "$src" || {
|
|
log "Failed to download rootfs tarball" ierror
|
|
return 1
|
|
}
|
|
fi
|
|
|
|
log "Extracting rootfs tarball" internal
|
|
bsdtar -xpf "$filename" -C "$rootdir" || {
|
|
log "Failed to extract rootfs tarball" error
|
|
return 1
|
|
}
|
|
}
|
|
|
|
prepare_system()
|
|
{
|
|
local rootdir="$1"
|
|
[ ! -d "$rootdir" ] && {
|
|
log "Rootdir [$rootdir] does not exists" ierror
|
|
return 2
|
|
}
|
|
|
|
log "Removing default kernel and settings" internal
|
|
chroot "$rootdir" userdel -r alarm
|
|
chroot "$rootdir" pacman -R linux-aarch64 linux-firmware --noconfirm || {
|
|
log "Failed to remove default kernel"
|
|
}
|
|
|
|
log "Adding mirrorlist" internal
|
|
cp ./drop/mirrorlist "$rootdir/etc/pacman.d/mirrorlist"
|
|
|
|
log "Populating pacman key store" internal
|
|
{
|
|
chroot "$rootdir" pacman-key --init && chroot "$rootdir" pacman-key --populate archlinuxarm
|
|
} || {
|
|
log "Failed to populate pacman key store"
|
|
}
|
|
|
|
log "Enable pacman parallel downloads" internal
|
|
chroot "$rootdir" sed -i "s/#ParallelDownloads/ParallelDownloads/g" /etc/pacman.conf
|
|
|
|
log "Update pacman keyrings" internal
|
|
chroot "$rootdir" pacman -Sy archlinux-keyring archlinuxarm-keyring --noconfirm || {
|
|
log "Failed to update pacman keyrings"
|
|
}
|
|
}
|
|
|
|
setup_zram_generator()
|
|
{
|
|
local rootdir="$1"
|
|
[ ! -d "$rootdir" ] && {
|
|
log "Rootdir [$rootdir] does not exists" ierror
|
|
return 2
|
|
}
|
|
|
|
log "Installing systemd-zram-generator" install
|
|
chroot "$rootdir" pacman -S zram-generator --noconfirm || {
|
|
log "Failed to install systemd-zram-generator" ierror
|
|
return 1
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
install_nabu_packages()
|
|
{
|
|
local rootdir="$1"
|
|
[ ! -d "$rootdir" ] && {
|
|
log "Rootdir [$rootdir] does not exists" ierror
|
|
return 2
|
|
}
|
|
|
|
cp ./packages/*.zst "$rootdir/opt/"
|
|
chroot "$rootdir" bash -c "pacman -U /opt/*.zst --noconfirm" || {
|
|
log "Failed to install packages" ierror
|
|
return 1
|
|
}
|
|
chroot "$rootdir" bash -c "rm /opt/*.zst"
|
|
|
|
log "Enabling userspace services" internal
|
|
chroot "$rootdir" systemctl enable qrtr-ns pd-mapper tqftpserv rmtfs || {
|
|
log "Failed to enable services" ierror
|
|
return 1
|
|
}
|
|
}
|
|
|
|
# shellcheck disable=SC2086
|
|
install_packages()
|
|
{
|
|
local rootdir="$1"
|
|
local packages="${*:2}"
|
|
[ ! -d "$rootdir" ] && {
|
|
log "Rootdir [$rootdir] does not exists" ierror
|
|
return 2
|
|
}
|
|
|
|
chroot "$rootdir" pacman -S $packages --noconfirm || {
|
|
log "Failed to install package(s)" ierror
|
|
return 1
|
|
}
|
|
}
|
|
|
|
finish_system()
|
|
{
|
|
local rootdir="$1"
|
|
[ ! -d "$rootdir" ] && {
|
|
log "Rootdir [$rootdir] does not exists" ierror
|
|
return 2
|
|
}
|
|
|
|
log "Cleaning apt cache" internal
|
|
yes | chroot "$rootdir" pacman -Scc || {
|
|
log "Failed to clean apt cache" ierror
|
|
return 1
|
|
}
|
|
|
|
log "Updating runtime linker bindings" internal
|
|
chroot "$rootdir" ldconfig || {
|
|
log "Failed to update runtime linker bindings" ierror
|
|
return 1
|
|
}
|
|
|
|
log "Restoring resolv.conf symlink"
|
|
mv "$rootdir/etc/resolv.conf.1" "$rootdir/etc/resolv.conf"
|
|
|
|
rm "$rootdir"/.* > /dev/null 2>&1
|
|
}
|
|
|