From 6ef4d5dcbc3e884e55c47fbe81c8a11d292caf79 Mon Sep 17 00:00:00 2001 From: timoxa0 Date: Sat, 2 Nov 2024 23:12:05 +0500 Subject: [PATCH] mklni: Add build function --- mklni | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/mklni b/mklni index 6b85222..2ce550e 100755 --- a/mklni +++ b/mklni @@ -62,6 +62,10 @@ arguments() { remove_chroot break 2 ;; +build) + build "$1" + break 2 ;; + chroot) chroot_into break 2 ;; @@ -89,6 +93,9 @@ usage() { # Remove build chroot $0 uninstall + # Make image + $0 build path/to/lnibuild + # Chroot into $0 chroot EOF @@ -281,6 +288,46 @@ chroot_into() } } +build() +{ + [ ! -d "$CHROOTDIR" ] && { + log "Chroot not installed" error + exit 1 + } + + local lni="$1" + [ ! -f "$lni" ] && { + log "$lni no such file" error + exit 2 + } + + cp "$lni" "$CHROOTDIR/tmp/lnibuild" + + prepare_chroot || { + log "Failed to setup chroot" error + exit 1 + } + + chroot "$CHROOTDIR" /bin/bash -c "cd /makelni && ./makelni /tmp/lnibuild" + local exitcode=$? + rm "$CHROOTDIR/tmp/lnibuild" + + detach_chroot || { + log "Failed to detach chroot" error + exit 1 + } + + [ "$exitcode" -eq "0" ] || { + log "Failed to build image" error + exit 1 + } + + source <( grep name "$lni" ) + mv "$CHROOTDIR/makelni/out/${name}.lni" "./${name}.lni" + chown "$(stat -c '%U:%G' mklni)" "./${name}.lni" + exit 0 +} + if [ "$(id -u)" != "0" ]; then log "$0 must be run as root" exit 3