#!/bin/bash
source /usr/share/slackdev/buildkit.sh

#####################################################################################
# Script : installers-aio.build
# Purpose: Launch the various Slackware Installer build scripts to create the "AiO"
#          Installer images. These contain the Slackware package sets, and are
#          referenced within the Installation Guides.
# Author : Stuart Winter <mozes@slackware.com>
# Date...: 03-Apr-2025
#####################################################################################
#
# Copyright 2025 Stuart Winter, Donostia, Spain.
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#####################################################################################
# Note:
# This script should be run from within ~/platform/aarch64/bootware/src
# on the master build machine for your configured version of Slackware ARM
# (as per the Slackware ARM devkit config file)

CWD=$PWD

# Slackware tree is chosen from the environment configured within the
# 'slackkit' package.

#####################################################################################
######## Build Generic ISO image ####################################################
#####################################################################################

# Note: with the 'bare' installer build script, we offer the possibility of using
# an overlay for the Kernel and Installer image.  For the AiO we *could* but don't
# because the AiO is only built from the public tree, since testing involves using
# bare metal, and I don't want to test development stuff - the "bare" Installer images
# are used for that.

# The Slackware version is appended to this directory when supplied to the ISO build
# tool:
OUTDIR_AIO=${SLACKPUBTREEDIR}/platform/$SLKPORTARCH/bootware/installer-aio/
[ ! -d "${OUTDIR_AIO}" ] && { echo "ERROR: Public Slackware tree not found" ; exit 1; }

# For testing:
#OUTDIR_AIO=/tmp/AIO-iso-tests
#rm -rf $OUTDIR_AIO
#mkdir -p $OUTDIR_AIO

# Build the 'AiO' ISO Installer:
# SLACKPUBTREEDIR=/mnt/prisroot/devel/armedslack-distrib/slackwarearm/
# '$SLACKWAREVERSION' is (e.g.) "slackwareaarch64-current", and is set within the
# Slackware ARM devkit configuration file (sourced by 'buildkit.sh').
./inst_iso.build \
   --installer-aio \
   --iso-architecture ${SLKPORTARCH} \
   --slackware-release-name ${SLACKWAREVERSION} \
   --slackware-tree ${SLACKPUBTREEDIR}/${SLACKWAREVERSION} \
   --output-dir ${OUTDIR_AIO}/${SLACKWAREVERSION} \
   --linux-kernel-image kernels/armv8/Image-armv8 \
   --slackware-installer-image installer/initrd-armv8.img \
   --grub-config-file $CWD/platform/aarch64/generic-efi-grub/assets/grub.cfg \
   --iso-file-name efi_generic.iso \
   --md5sum-iso \
   --image-app-id "Slackware Installer" || { echo "ERROR: Generic ISO build failed" ; exit 3 ;}
#   --no-cleanup \

#####################################################################################
######## Build Installer disk images ################################################
#####################################################################################
# The various settings are contained within this script. We may migrate this script
# to be called in the same way as 'inst_iso.build'. Time permitting.
# It already has some command line operators, but the naming convention is different.
# and it doesn't support all of the same options.
./inst_dskimg-aio.build
#####################################################################################
