Skip to content

Commit

Permalink
First approach
Browse files Browse the repository at this point in the history
  • Loading branch information
dappnodedev committed May 23, 2024
1 parent 7557f15 commit b8832b7
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 7 deletions.
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 5 additions & 1 deletion iso/scripts/generate_ISO.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 5 additions & 4 deletions iso/scripts/generate_dappnode_iso_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
108 changes: 108 additions & 0 deletions iso/scripts/generate_dappnode_iso_ubuntu.sh
Original file line number Diff line number Diff line change
@@ -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 </tmp/list >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 \

0 comments on commit b8832b7

Please sign in to comment.