makelni: add pre/post install hook error messages, add lon-tool

This commit is contained in:
timoxa0 2024-11-02 21:15:04 +05:00
parent c370fe1672
commit 16fb7c36ae

23
makelni
View file

@ -2,6 +2,8 @@
source ./common.d/functions.sh source ./common.d/functions.sh
source ./common.d/variables.sh source ./common.d/variables.sh
require "lon-tool"
if [ "$(id -u)" != "0" ]; then if [ "$(id -u)" != "0" ]; then
log "$0 must be run as root" log "$0 must be run as root"
exit 3 exit 3
@ -26,6 +28,11 @@ lnib_has_errors="n"
lnib_has_errors="y" lnib_has_errors="y"
} }
[ -z ${imgver+x} ] && {
log "LNIBUILD: missing imgver" ierror
lnib_has_errors="y"
}
[ -z ${image_type+x} ] && { [ -z ${image_type+x} ] && {
log "LNIBUILD: missing image_type" ierror log "LNIBUILD: missing image_type" ierror
lnib_has_errors="y" lnib_has_errors="y"
@ -50,7 +57,8 @@ source "./common.d/common.${image_type}.sh"
log "Making image: $name" log "Making image: $name"
log "Image type: $image_type" log "Image type: $image_type"
log "Creating image: $(get_image_path "$name")" IMAGE_PATH="$(get_image_path "$name")"
log "Creating image: $IMAGE_PATH"
create_image "$name" || _shutdown 1 create_image "$name" || _shutdown 1
imageroot="$(mount_image "$name")" imageroot="$(mount_image "$name")"
@ -62,7 +70,10 @@ prepare_chroot "$imageroot" || _shutdown 1
[[ $(type -t pre_install) == function ]] && { [[ $(type -t pre_install) == function ]] && {
log "Running pre install hook" log "Running pre install hook"
pre_install || _shutdown 1 pre_install || {
log "Failed to execute pre install hook"
_shutdown 1
}
} }
log "Setting up inet" log "Setting up inet"
@ -92,7 +103,10 @@ gen_fstab "$imageroot" || _shutdown 1
[[ $(type -t post_install) == function ]] && { [[ $(type -t post_install) == function ]] && {
log "Running post install hook" log "Running post install hook"
post_install || _shutdown 1 post_install || {
log "Failed to execute post install hook"
_shutdown 1
}
} }
log "Detaching chroot" log "Detaching chroot"
@ -104,4 +118,7 @@ umount_image "$imageroot" || _shutdown 1
log "Trimming image" log "Trimming image"
trim_image "$name" || _shutdown 1 trim_image "$name" || _shutdown 1
log "Creating lni image"
lon-tool image create "$IMAGE_PATH "./out/${name}.lni" --name "$name" -v "$imgver"
log "Image build finished" log "Image build finished"