From c15cd9627a39a99ae774ebf9df2e124ecb751a29 Mon Sep 17 00:00:00 2001 From: timoxa0 Date: Sun, 27 Oct 2024 16:12:52 +0500 Subject: [PATCH] profiles: Add deb-based profile --- common.d/common.deb.sh | 132 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 common.d/common.deb.sh diff --git a/common.d/common.deb.sh b/common.d/common.deb.sh new file mode 100644 index 0000000..992baea --- /dev/null +++ b/common.d/common.deb.sh @@ -0,0 +1,132 @@ +#!/usr/bin/env bash +source ./common.d/functions.sh +source ./common.d/build_functions.sh + +require "debootstarp" + +export DEBIAN_FRONTEND=noninteractive + +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 + } + log "Fetching base system" internal + debootstarp --arch arm64 --components "$components" "$branch" "$rootdir" "$repo" || { + log "Failed to fetch base system" ierror + } +} + +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" { + 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 + } +} + +install_packages() +{ + local rootdir="$1" + local packages="${@:2}" + [ ! -d "$rootdir" ] && { + log "Rootdir [$rootdir] does not exists" ierror + return 2 + } + + chroot "$rootdir" apt install ${packages[*]} -y || { + 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 linked bindings" internal + chroot "$rootdir" ldconfig || { + log "Failed to update runtime linker bindings" ierror + return 1 + } +} +