mklni: Add build function
This commit is contained in:
parent
aa3a7d0dd5
commit
4a5c854855
47
mklni
47
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
|
||||
|
|
Loading…
Reference in a new issue