From: xf0r3m Date: Tue, 5 Sep 2023 15:24:50 +0000 (+0200) Subject: Utworznie skryptu budującego obraz płyty: X-Git-Url: https://gitweb.morketsmerke.org/?a=commitdiff_plain;h=a7d93eb2e45b0375c6553188660cc8d00619a0aa;p=greenOS.git Utworznie skryptu budującego obraz płyty: --- diff --git a/greenOS-build b/greenOS-build new file mode 100755 index 0000000..50fd60d --- /dev/null +++ b/greenOS-build @@ -0,0 +1,150 @@ +#!/bin/bash + +GREEN="\e[32m"; +ENDCOLOR="\e[0m"; + +set -e + +echo "-== Starting greenOS_build: $(date) ==-" >> greenOS_build.log; + +function help() { + echo "-== Help printed: $(date) ==-" >> greenOS_build.log; + echo "greenOS-build - script for building greenOS LiveCD."; + echo "@ 2023 morketsmerke.org"; + echo "Usage:"; + echo " ./greenOS-build -- "; +} + +function create_enviroment() { + echo -n "Installation of packages needed to build greenOS..."; + sudo apt update >> greenOS_build.log 2>&1; + sudo apt install -y debootstrap squashfs-tools xorriso isolinux syslinux-efi grub-pc-bin grub-efi-amd64-bin mtools dosfstools >> greenOS_build.log 2>&1; + if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi +} + +#Distributing greenOS 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 [ "$2" ]; then + version=$2 +else + help; + exit 1; +fi + +if [ ! -f /sbin/debootstrap ]; then + create_enviroment +fi + +#Creating root directory sturcture for greenOS build: +if [ ! -d ${HOME}/build/greenOS/${arch} ]; then + echo -n "Creating root directory structure for greenOS build..."; + mkdir -pv ${HOME}/build/greenOS/${arch} >> greenOS_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') stable ${HOME}/build/greenOS/${arch}/chroot http://deb.debian.org/debian >> greenOS_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 ${HOME}/greenOS/versions/base.sh ${HOME}/build/greenOS/${arch}/chroot >> greenOS_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Executing chroot script, at least i trying: +sudo chroot ${HOME}/build/greenOS/${arch}/chroot /bin/bash /base.sh $arch; + +#Removing chroot script. +echo -n "Remove chroot script..."; +sudo rm -vf ${HOME}/build/greenOS/${arch}/chroot/base.sh >> greenOS_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 ${HOME}/build/greenOS/${arch}/{staging/{EFI/boot,boot/grub/x86_64-efi,isolinux,live},tmp} >> greenOS_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Creating squasfs archive: +echo -n "Creating squashfs archive..."; +sudo mksquashfs ${HOME}/build/greenOS/${arch}/chroot ${HOME}/build/greenOS/${arch}/staging/live/filesystem.squashfs -e boot >> greenOS_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 ${HOME}/build/greenOS/${arch}/chroot/boot/vmlinuz-* | tail -1) ${HOME}/build/greenOS/${arch}/staging/live/vmlinuz >> greenOS_build.log 2>&1; +cp -v $(ls -v ${HOME}/build/greenOS/${arch}/chroot/boot/initrd.img-* | tail -1) ${HOME}/build/greenOS/${arch}/staging/live/initrd >> greenOS_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Setting version for this image: +echo "-==Setting version for greenOS image: $(date)==-" >> greenOS_build.log; +echo -n "Setting version for this greenOS image..."; +echo $version | tee {HOME}/build/greenOS/${arch}/staging/live/version >> greenOS_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 ${HOME}/greenOS/isolinux/${arch2}/* ${HOME}/build/greenOS/${arch}/staging/isolinux >> greenOS_build.log 2>&1; +cp -v ${HOME}/greenOS/grub/${arch2}/* ${HOME}/build/greenOS/${arch}/staging/boot/grub >> greenOS_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Create grubstandalone config: +echo "-==Create grub-standalone config: $(date)==-" >> greenOS_build.log; +echo -n "Create grub-standalone config..."; +cat >> ${HOME}/build/greenOS/${arch}/tmp/grub-standalone.cfg <> greenOS_build.log; +echo -n "Create empty file for GRUB..."; +touch ${HOME}/build/greenOS/${arch}/staging/GREENOS; +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 ${HOME}/build/greenOS/${arch}/staging/isolinux >> greenOS_build.log 2>&1; +cp -v /usr/lib/syslinux/modules/bios/* ${HOME}/build/greenOS/${arch}/staging/isolinux >> greenOS_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/* ${HOME}/build/greenOS/${arch}/staging/boot/grub/x86_64-efi >> greenOS_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)==-" >> greenOS_build.log; +echo -n "Creating grub-efi bootloader file..."; +grub-mkstandalone --format=x86_64-efi --output=${HOME}/build/greenOS/${arch}/staging/EFI/boot/bootx64.efi --locales="" --fonts="" "boot/grub/grub.cfg=${HOME}/build/greenOS/${arch}/tmp/grub-standalone.cfg"; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Creating additional EFI partition: +oldcwd=$(pwd); +cd ${HOME}/build/greenOS/${arch}/staging/boot/grub; +echo -n "Creating addtitional EFI partition..."; +dd if=/dev/zero bs=1M of=efiboot.img count=20 >> ${oldcwd}/greenOS_build.log 2>&1; +sudo mkfs.vfat efiboot.img >> greenOS_build.log 2>&1; +echo "-==Creating MS-DOS directory: $(date)==-" >> ${oldcwd}/greenOS_build.log; +sudo mmd -i efiboot.img efi efi/boot >> ${oldcwd}/greenOS_build.log 2>&1; +sudo mcopy -vi efiboot.img ${HOME}/build/greenOS/${arch}/staging/EFI/boot/bootx64.efi ::efi/boot >> ${oldcwd}/greenOS_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi + +#Create iso image: +cd $oldcwd; +echo -n "Creating iso image..."; +xorriso as mkisofs -iso-level 3 -o "greenOS_${versionShort}_${arch2}.iso" -full-iso9660-filenames -volid "gOS${version}${arch2}" -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 ${HOME}/build/greenOS/${arch}/staging/boot/grub/efiboot.img ${HOME}/build/greenOS/${arch}/staging >> greenOS_build.log 2>&1; +if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi