makelni/common.d/common.deb.sh

135 lines
3.2 KiB
Bash
Raw Normal View History

2024-10-27 11:12:52 +00:00
#!/usr/bin/env bash
source ./common.d/functions.sh
source ./common.d/build_functions.sh
require "debootstrap"
2024-10-27 11:12:52 +00:00
export DEBIAN_FRONTEND=noninteractive
# shellcheck disable=SC2086
2024-10-27 11:12:52 +00:00
fetch_base_system()
{
local rootdir="$1"
local branch="$2"
local components="$3"
local repo="$4"
local debootstrap_flags="$5"
[ ! -d "$rootdir" ] && {
log "Rootdir [$rootdir] does not exists" ierror
return 2
}
debootstrap --arch arm64 --components="$components" $debootstrap_flags "$branch" "$rootdir" "$repo" || {
2024-10-27 11:12:52 +00:00
log "Failed to fetch base system" ierror
return 1
2024-10-27 11:12:52 +00:00
}
}
prepare_system()
{
local rootdir="$1"
[ ! -d "$rootdir" ] && {
log "Rootdir [$rootdir] does not exists" ierror
return 2
}
log "Refrashing apt repos" internal
chroot "$rootdir" apt update || {
log "Failed to refresh apt repos" ierror
return 1
}
log "Updating system" internal
chroot "$rootdir" apt upgrade -y || {
log "Failed to update system" ierror
return 1
}
}
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" apt install systemd-zram-generator -y || {
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/*.deb "$rootdir/opt/"
chroot "$rootdir" bash -c "dpkg -i /opt/*.deb" || {
2024-10-27 11:12:52 +00:00
log "Failed to install packages" ierror
return 1
}
chroot "$rootdir" bash -c "rm /opt/*.deb"
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
2024-10-27 11:12:52 +00:00
install_packages()
{
local rootdir="$1"
local packages="${*:2}"
2024-10-27 11:12:52 +00:00
[ ! -d "$rootdir" ] && {
log "Rootdir [$rootdir] does not exists" ierror
return 2
}
chroot "$rootdir" apt install $packages -y || {
2024-10-27 11:12:52 +00:00
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
chroot "$rootdir" apt clean || {
log "Failed to clean apt cache" ierror
return 1
}
log "Updating runtime linker bindings" internal
2024-10-27 11:12:52 +00:00
chroot "$rootdir" ldconfig || {
log "Failed to update runtime linker bindings" ierror
return 1
}
}