115 lines
2.4 KiB
Bash
Executable file
115 lines
2.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
source ./common.d/functions.sh
|
|
source ./common.d/variables.sh
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
log "$0 must be run as root"
|
|
exit 3
|
|
fi
|
|
|
|
arguments "$@"
|
|
|
|
[[ -z $LNIBUILD ]] && {
|
|
log "No LNIBUILD specified" error
|
|
exit 1
|
|
}
|
|
|
|
prepare_env
|
|
|
|
lni_path=$(realpath "$LNIBUILD")
|
|
|
|
source "$lni_path"
|
|
|
|
lnib_has_errors="n"
|
|
[ -z ${name+x} ] && {
|
|
log "LNIBUILD: missing name" ierror
|
|
lnib_has_errors="y"
|
|
}
|
|
|
|
[ -z ${image_type+x} ] && {
|
|
log "LNIBUILD: missing image_type" ierror
|
|
lnib_has_errors="y"
|
|
}
|
|
|
|
[ -z ${zram+x} ] && {
|
|
log "LNIBUILD: missing zram" ierror
|
|
lnib_has_errors="y"
|
|
}
|
|
|
|
[ -z ${packages+x} ] && {
|
|
log "LNIBUILD: missing packages" ierror
|
|
lnib_has_errors="y"
|
|
}
|
|
|
|
[ ! -f "./common.d/common.${image_type}.sh" ] && {
|
|
log "LNIBUILD: unsupported image type" ierror
|
|
lnib_has_errors="y"
|
|
}
|
|
|
|
[ "$lnib_has_errors" == "y" ] && {
|
|
log "Incorrect LNIBUILD" error
|
|
exit 2
|
|
}
|
|
|
|
source "./common.d/common.${image_type}.sh"
|
|
log "Making image: $name"
|
|
log "Image type: $image_type"
|
|
|
|
log "Creating image: $(get_image_path "$name")"
|
|
create_image "$name" || _shutdown 1
|
|
imageroot="$(mount_image "$name")"
|
|
|
|
log "Fetching base system"
|
|
base_system || _shutdown 1
|
|
|
|
log "Preparing chroot"
|
|
prepare_chroot "$imageroot" || _shutdown 1
|
|
|
|
[[ $(type -t pre_install) == function ]] && {
|
|
log "Running pre install hook"
|
|
pre_install || _shutdown 1
|
|
}
|
|
|
|
log "Setting up inet"
|
|
setup_inet "$imageroot" || _shutdown 1
|
|
|
|
log "Prepare system"
|
|
prepare_system "$imageroot" || _shutdown 1
|
|
|
|
if (( ${#packages[@]} )); then
|
|
log "Installing packages: ${packages[*]}"
|
|
install_packages "$imageroot" "${packages[@]}" || _shutdown 1
|
|
fi
|
|
|
|
log "Installing kernel and firmwares"
|
|
log "Configuring dynamic linker run-time bindings"
|
|
log "Enabling userspace daemons"
|
|
install_nabu_packages "$imageroot" || _shutdown 1
|
|
|
|
if [ "$zram" == "y" ]; then
|
|
log "Setting up zram"
|
|
setup_zram_generator "$imageroot" || _shutdown 1
|
|
fi
|
|
|
|
log "Finishing system image"
|
|
finish_system "$imageroot" || _shutdown 1
|
|
|
|
log "Generating fstab"
|
|
gen_fstab "$imageroot" || _shutdown 1
|
|
|
|
[[ $(type -t post_install) == function ]] && {
|
|
log "Running post install hook"
|
|
post_install || _shutdown 1
|
|
}
|
|
|
|
log "Detaching chroot"
|
|
detach_chroot "$imageroot" || _shutdown 1
|
|
|
|
log "Unmounting image"
|
|
umount_image "$imageroot" || _shutdown 1
|
|
|
|
log "Trimming image"
|
|
trim_image "$name" || _shutdown 1
|
|
|
|
log "Image build finished"
|