From 2ce744ffb1d7a4e587b45302deba1003ad765997 Mon Sep 17 00:00:00 2001 From: xf0r3m Date: Wed, 16 Aug 2023 16:31:52 +0200 Subject: [PATCH] Dostosowanie immudex-build do nowego sposobu publikacji --- immudex-build | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100755 immudex-build diff --git a/immudex-build b/immudex-build new file mode 100755 index 0000000..602e088 --- /dev/null +++ b/immudex-build @@ -0,0 +1,151 @@ +#!/bin/bash + +GREEN="\e[32m"; +ENDCOLOR="\e[0m"; + +set -e + +echo "-== Starting immudex_build: $(date) ==-" >> immudex_build.log; + +function help() { + echo "-== Help printed: $(date) ==-" >> immudex_build.log; + echo "immudex-build - script for building immudex LiveCD."; + echo "@ 2023 morketsmerke.org"; + echo "Usage:"; + echo " ./immudex_build --"; +} + +function create_enviroment() { + echo -n "Installation of packages needed to build immudex..."; + sudo apt update >> ~/immudex_build.log 2>&1; + sudo apt install -y debootstrap squashfs-tools xorriso isolinux syslinux-efi grub-pc-bin grub-efi-amd64-bin mtools dosfstools >> immudex_build.log 2>&1; + if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi +} + +#Distributing immudex-testing as meta-distribution there is no such thing like +#updates. For every new commit in Git service you build new iso image. + +#Determing requested architecture and +if [ "$1" ] && [ "$1" = "--amd64" ]; then arch="64"; +elif [ "$1" ] && [ "$1" = "--i386" ]; then arch="32"; +else + help; + exit 1; +fi + +if [ ! -f /sbin/debootstrap ]; then + create_enviroment +fi + +#Creating root directory sturcture for immudex build: +if [ ! -d ~/immudex-testing/${arch} ]; then + echo -n "Creating root directory structure for immudex build..."; + mkdir -pv ~/immudex-testing/${arch} >> immudex_build.log 2>&1; + if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi +fi + +#Fetching testing vanilla Debian base system files: +echo -n "Fetching testing vanilla Debian base system files..."; +sudo /sbin/debootstrap --arch=$(echo $1 | sed 's/-//g') trixie ~/immudex-testing/${arch}/chroot http://deb.debian.org/debian >> ~/immudex_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Getting project files: +echo -n "Getting project files..."; +mkdir -v ~/Pobrane >> ~/immudex_build.log 2>&1; +cd ~/Pobrane; +git clone https://git.morketsmerke.org/git/immudex-testing.git >> ~/immudex_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + + +#Copying chroot script to chroot directory: +echo -n "Copying chroot script to chroot directory..."; +sudo cp -vv ~/Pobrane/immudex-testing/versions/base.sh ~/immudex-testing/${arch}/chroot >> ~/immudex_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Executing chroot script, at least i trying: +sudo chroot ~/immudex-testing/${arch}/chroot /bin/bash /base.sh $arch; + +#Removing chroot script. +echo -n "Remove chroot script..."; +sudo rm -vf ~/immudex-testing/${arch}/chroot/base.sh >> immudex_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Creating LiveCD directory structure: +echo -n "Creating LiveCD directory structure..."; +mkdir -pv ~/immudex-testing/${arch}/{staging/{EFI/boot,boot/grub/x86_64-efi,isolinux,live},tmp} >> immudex_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Creating squasfs archive: +echo -n "Creating squashfs archive..."; +sudo mksquashfs ~/immudex-testing/${arch}/chroot ~/immudex-testing/${arch}/staging/live/filesystem.squashfs -e boot >> immudex_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Copying kernel and initrd (core files) from chroot: +echo -n "Copying kernel and initrd (core files) from chroot..."; +cp -v $(ls -v ~/immudex-testing/${arch}/chroot/boot/vmlinuz-* | tail -1) ~/immudex-testing/${arch}/staging/live/vmlinuz >> immudex_build.log 2>&1; +cp -v $(ls -v ~/immudex-testing/${arch}/chroot/boot/initrd.img-* | tail -1) ~/immudex-testing/${arch}/staging/live/initrd >> immudex_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Getting and copying bootloader files +echo -n "Copying bootloader files..."; +arch2=$(echo $1 | sed 's/-//g'); +cp -v immudex-testing/isolinux/${arch2}/* ~/immudex-testing/${arch}/staging/isolinux >> ~/immudex_build.log 2>&1; +cp -v immudex-testing/grub/${arch2}/* ~/immudex-testing/${arch}/staging/boot/grub >> ~/immudex_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Removing Pobrane dir +echo -n "Removing Pobrane directory..."; +cd ~; +rm -rvf ~/Pobrane >> ~/immudex_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Create grubstandalone config: +echo "-==Create grub-standalone config: $(date)==-" >> ~/immudex_build.log; +echo -n "Create grub-standalone config..."; +cat >> ~/immudex-testing/${arch}/tmp/grub-standalone.cfg <> ~/immudex_build.log; +echo -n "Create empty file for GRUB..."; +touch ~/immudex-testing/${arch}/staging/DEBIAN; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Copying isolinux files: +echo -n "Copiying isolinux files..."; +cp -v /usr/lib/ISOLINUX/isolinux.bin ~/immudex-testing/${arch}/staging/isolinux >> immudex_build.log 2>&1; +cp -v /usr/lib/syslinux/modules/bios/* ~/immudex-testing/${arch}/staging/isolinux >> immudex_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Copying grub files: +echo -n "Copying isolinux files..."; +cp -rv /usr/lib/grub/x86_64-efi/* ~/immudex-testing/${arch}/staging/boot/grub/x86_64-efi >> immudex_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Creating grub-efi bootloader file: +echo "-==Creating grub-efi bootloader file: $(date)==-" >> immudex_build.log; +echo -n "Creating grub-efi bootloader file..."; +myHOME=$(pwd); +grub-mkstandalone --format=x86_64-efi --output=${myHOME}/immudex-testing/${arch}/staging/EFI/boot/bootx64.efi --locales="" --fonts="" "boot/grub/grub.cfg=${myHOME}/immudex-testing/${arch}/tmp/grub-standalone.cfg"; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Creating additional EFI partition: +cd ~/immudex-testing/${arch}/staging/boot/grub; +echo -n "Creating addtitional EFI partition..."; +dd if=/dev/zero bs=1M of=efiboot.img count=20 >> ~/immudex_build.log 2>&1; +sudo mkfs.vfat efiboot.img >> ~/immudex_build.log 2>&1; +echo "-==Creating MS-DOS directory: $(date)==-" >> ~/immudex_build.log; +sudo mmd -i efiboot.img efi efi/boot >> ~/immudex_build.log 2>&1; +sudo mcopy -vi efiboot.img ~/immudex-testing/${arch}/staging/EFI/boot/bootx64.efi ::efi/boot >> ~/immudex_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Create iso image: +echo -n "Creating iso image..."; +cd ~/immudex-testing/${arch}; +xorriso as mkisofs -iso-level 3 -o "immudex-testing${arch}.iso" -full-iso9660-filenames -volid "immudex-testing${arch}" -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin -eltorito-boot isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table --eltorito-catalog isolinux/isolinux.cat -eltorito-alt-boot -e /boot/grub/efiboot.img -no-emul-boot -isohybrid-gpt-basdat -append_partition 2 0xef ~/immudex-testing/${arch}/staging/boot/grub/efiboot.img ~/immudex-testing/${arch}/staging >> ~/immudex_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi -- 2.39.5