mklni: Add build function

This commit is contained in:
timoxa0 2024-11-02 23:12:05 +05:00
parent 23bd454bd4
commit 6ef4d5dcbc

47
mklni
View file

@ -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