From b8832b75cfa394f344ab15b420a88551b9815770 Mon Sep 17 00:00:00 2001 From: dappnodedev Date: Thu, 23 May 2024 10:56:03 +0200 Subject: [PATCH] First approach --- docker-compose.yml | 5 +- iso/scripts/generate_ISO.sh | 6 +- iso/scripts/generate_dappnode_iso_debian.sh | 9 +- iso/scripts/generate_dappnode_iso_ubuntu.sh | 108 ++++++++++++++++++++ 4 files changed, 121 insertions(+), 7 deletions(-) create mode 100755 iso/scripts/generate_dappnode_iso_ubuntu.sh diff --git a/docker-compose.yml b/docker-compose.yml index 7eddc984..90d69a50 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,8 +6,9 @@ services: privileged: true environment: - BUILD=false # In case you want to re-generate a all the images, not recommended - - CLEAN=true # it remove the images directory - - UNATTENDED=false # UNATTENDED version + - CLEAN=false # it remove the images directory + - UNATTENDED=true # UNATTENDED version + - BASE_OS=debian # Base OS version (debian or ubuntu) volumes: - ./images:/images - "/var/run/docker.sock:/var/run/docker.sock" diff --git a/iso/scripts/generate_ISO.sh b/iso/scripts/generate_ISO.sh index 024e5397..bf241775 100755 --- a/iso/scripts/generate_ISO.sh +++ b/iso/scripts/generate_ISO.sh @@ -22,4 +22,8 @@ fi mkdir -p /usr/src/app/dappnode touch /usr/src/app/dappnode/iso_install.log -/usr/src/app/iso/scripts/generate_dappnode_iso_debian.sh +if [ "$BASE_OS" = "ubuntu" ]; then + /usr/src/app/iso/scripts/generate_dappnode_iso_ubuntu.sh +else + /usr/src/app/iso/scripts/generate_dappnode_iso_debian.sh +fi diff --git a/iso/scripts/generate_dappnode_iso_debian.sh b/iso/scripts/generate_dappnode_iso_debian.sh index 3f02fb73..3b655176 100755 --- a/iso/scripts/generate_dappnode_iso_debian.sh +++ b/iso/scripts/generate_dappnode_iso_debian.sh @@ -25,12 +25,13 @@ rm -rf dappnode-isoº rm -rf DappNode-debian-* echo "Extracting the iso..." -xorriso -osirrox on -indev /images/${ISO_NAME} \ - -extract / dappnode-iso +osirrox -indev /images/${ISO_NAME} -extract / dappnode-iso +# Using a 512-byte block size to ensure the entire Master Boot Record (MBR) is captured. +# The MBR contains boot code, the partition table, and a boot signature, all essential for creating bootable media. +# This ensures that the new ISO being created is bootable under different system setups echo "Obtaining the isohdpfx.bin for hybrid ISO..." -dd if=/images/${ISO_NAME} bs=432 count=1 \ - of=dappnode-iso/isolinux/isohdpfx.bin +dd if=/images/${ISO_NAME} bs=512 count=1 of=dappnode-iso/isolinux/isohdpfx.bin cd /usr/src/app/dappnode-iso # /usr/src/app/dappnode-iso diff --git a/iso/scripts/generate_dappnode_iso_ubuntu.sh b/iso/scripts/generate_dappnode_iso_ubuntu.sh new file mode 100755 index 00000000..86778346 --- /dev/null +++ b/iso/scripts/generate_dappnode_iso_ubuntu.sh @@ -0,0 +1,108 @@ +#!/bin/bash +set -e + +ISO_BUILD_PATH="/usr/src/app/dappnode-iso" +DAPPNODE_SCRIPTS_PATH="/usr/src/app/scripts" +VARS_FILE="/tmp/vars.sh" +TMP_INITRD="/tmp/makeinitrd" + +# Source = https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.5.0-amd64-netinst.iso +BASE_ISO_NAME=ubuntu-24.04-live-server-amd64.iso +BASE_ISO_PATH="/images/${BASE_ISO_NAME}" +DAPPNODE_ISO_PATH="/images/DAppNode-${BASE_ISO_NAME}" +ISO_URL=https://labs.eif.urjc.es/mirror/ubuntu-releases/24.04/ +SHASUM="8762f7e74e4d64d72fceb5f70682e6b069932deedb4949c6975d0f0fe0a91be3 ${BASE_ISO_PATH}" + +echo "Downloading Ubuntu ISO image: ${BASE_ISO_NAME}..." +if [ ! -f ${BASE_ISO_PATH} ]; then + wget ${ISO_URL}/${BASE_ISO_NAME} \ + -O ${BASE_ISO_PATH} +fi +echo "Done!" + +echo "Verifying download..." +[[ "$(shasum -a 256 ${BASE_ISO_PATH})" != "$SHASUM" ]] && { + echo "ERROR: wrong shasum" + exit 1 +} + +echo "Clean old files..." +rm -rf dappnode-isoº +rm -rf DappNode-ubuntu-* + +echo "Extracting the iso..." +osirrox -indev ${BASE_ISO_PATH} -extract / dappnode-iso + +# Using a 512-byte block size to ensure the entire Master Boot Record (MBR) is captured. +# The MBR contains boot code, the partition table, and a boot signature, all essential for creating bootable media. +echo "Obtaining the isohdpfx.bin for hybrid ISO..." +dd if=/images/${BASE_ISO_NAME} bs=512 count=1 of=${ISO_BUILD_PATH}/boot/grub/isohdpfx.bin + +echo "Creating the new Ubuntu ISO..." +mkisofs -isohybrid-mbr ${ISO_BUILD_PATH}/boot/grub/isohdpfx.bin \ + -eltorito-catalog ${ISO_BUILD_PATH}/boot.catalog \ + -eltorito-boot ${ISO_BUILD_PATH}/boot/grub/i386-pc/eltorito.img -no-emul-boot -boot-load-size 4 \ + -boot-info-table -eltorito-alt-boot --efi-boot ${ISO_BUILD_PATH}/EFI/boot/bootx64.efi -no-emul-boot \ + -isohybrid-gpt-basdat -o ${DAPPNODE_ISO_NAME} . + +exit 0 + +echo "Downloading third-party packages..." +sed '1,/^\#\!ISOBUILD/!d' ${DAPPNODE_SCRIPTS_PATH}/dappnode_install_pre.sh >${VARS_FILE} +# shellcheck disable=SC1091 +source ${VARS_FILE} + +echo "Creating necessary directories and copying files..." +mkdir -p ${ISO_BUILD_PATH}/dappnode +cp -r ${DAPPNODE_SCRIPTS_PATH} ${ISO_BUILD_PATH}/dappnode +cp -r /usr/src/app/dappnode/* ${ISO_BUILD_PATH}/dappnode + +echo "Customizing preseed..." +mkdir -p ${TMP_INITRD} +cp ${ISO_BUILD_PATH}/casper/initrd ${TMP_INITRD}/ +if [[ $UNATTENDED == *"true"* ]]; then + # TODO: Check if this is the correct preseed file for Ubuntu + cp /usr/src/app/iso/preseeds/preseed_unattended.cfg ${TMP_INITRD}/preseed.cfg +else + cp /usr/src/app/iso/preseeds/preseed.cfg ${TMP_INITRD}/preseed.cfg +fi + +cpio -id -H newc <${TMP_INITRD}/initrd +# shellcheck disable=SC2002 +cat ${TMP_INITRD}/initrd | cpio -t >/tmp/list +echo "preseed.cfg" >>/tmp/list +rm ${TMP_INITRD}/initrd +cpio -o -H newc initrd +#gzip initrd +cd - +mv ${TMP_INITRD}/initrd ${ISO_BUILD_PATH}/casper/initrd +cd .. + +#mkdir -p boot/grub/theme + +echo "Configuring the boot menu for DappNode..." +cp /usr/src/app/iso/boot/grub.cfg boot/grub/grub.cfg +#cp /usr/src/app/iso/boot/theme_1 boot/grub/theme/1 +#cp /usr/src/app/iso/boot/isolinux.cfg isolinux/isolinux.cfg +#cp /usr/src/app/iso/boot/menu.cfg isolinux/menu.cfg +#cp /usr/src/app/iso/boot/txt.cfg isolinux/txt.cfg +#cp /usr/src/app/iso/boot/splash.png isolinux/splash.png + +echo "Fix md5 sum..." +# shellcheck disable=SC2046 +md5sum $(find . ! -name "md5sum.txt" -type f) >md5sum.txt + +echo "Generating new iso..." +# Adjust paths as necessary based on actual directory contents +xorriso -as mkisofs \ + -isohybrid-mbr boot/grub/isohdpfx.bin \ + -b EFI/boot/grubx64.efi \ + -no-emul-boot \ + -boot-load-size 4 \ + -boot-info-table \ + -eltorito-alt-boot \ + -e boot/grub/i386-pc/eltorito.img \ + -no-emul-boot \ + -isohybrid-gpt-basdat \ + -o /images/DAppNode-${ISO_NAME} \ + . # -c boot/grub/boot.cat \