From db63a9a747246f5343b433ac3e68eebc801c455b Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 11 Dec 2024 19:41:19 +0100 Subject: [PATCH 1/9] pxe: change server_ip in .env.example --- pxe/.env.example | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pxe/.env.example b/pxe/.env.example index 8f80779..b235adf 100644 --- a/pxe/.env.example +++ b/pxe/.env.example @@ -1,4 +1,5 @@ -server_ip=192.168.1.2 -nfs_allowed_lan=192.168.1.0/24 +# assuming server_ip using qemu +server_ip=10.0.2.1 +nfs_allowed_lan=10.0.2.0/24 tftp_path='/srv/pxe-tftp' nfs_path='/srv/pxe-nfs' -- 2.30.2 From 6fb8ed0d14b96d3778b0e5480ef42c19708b35c1 Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Thu, 24 Oct 2024 04:31:39 -0300 Subject: [PATCH 2/9] edge case: bootloader dependency added --- deploy-workbench.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/deploy-workbench.sh b/deploy-workbench.sh index d0884bc..7996c09 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -493,6 +493,7 @@ install_requirements() { grub-pc-bin grub-efi-amd64-bin ovmf + shim-signed grub-efi-amd64-signed' ${SUDO} apt-get install -y \ ${image_deps} \ -- 2.30.2 From 449209cf3af1a4e7be4d412e351e45d19a9eb6d8 Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Thu, 24 Oct 2024 05:32:01 -0300 Subject: [PATCH 3/9] added clean pxe method to makefile --- pxe/Makefile | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pxe/Makefile b/pxe/Makefile index e325751..b8689a3 100644 --- a/pxe/Makefile +++ b/pxe/Makefile @@ -1,2 +1,40 @@ +include .env +export $(shell sed 's/=.*//' .env) + +.PHONY: test_pxe + +clean: + @if [ ! -f .env ]; then \ + echo ".env file not found!."; \ + exit 1; \ + fi + + @echo "Purging PXE files & packages -- THIS DOES NOT DELETE /SNAPSHOTS" + + @echo "Deleting NFS directory: $(nfs_path)" + @rm -rf $(nfs_path) + + @echo "Deleting TFTP directory: $(tftp_path)" + @rm -rf $(tftp_path) + + #TODO: all pxe packages on one same place + @echo "Deleting NFS directory: $(nfs_path)" + @echo "purging PXE packages: " + @if [ -n "$(PACKAGES)" ]; then sudo apt-get remove --purge -y $(PACKAGES); fi + + @sudo apt-get remove --purge dnsmasq nfs-kernel-server syslinux + @echo "Cleaning up package leftovers..." + @sudo apt-get autoremove -y + @sudo apt-get clean + + @echo "clean done" + + test_pxe: qemu-system-x86_64 -m 1G -boot n -netdev user,id=mynet0,tftp=/srv/pxe-tftp,bootfile=pxelinux.0 -device virtio-net,netdev=mynet0 + +install_qemu: + sudo apt-get install qemu-system + +install_pxe_debug: + DEBUG=true ./install-pxe.sh -- 2.30.2 From 51efdeb7cae8a9bf7c47df54f02c32cdf41c22b9 Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Thu, 24 Oct 2024 06:23:30 -0300 Subject: [PATCH 4/9] deleted obsolet line --- pxe/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pxe/Makefile b/pxe/Makefile index b8689a3..febfecb 100644 --- a/pxe/Makefile +++ b/pxe/Makefile @@ -17,10 +17,10 @@ clean: @echo "Deleting TFTP directory: $(tftp_path)" @rm -rf $(tftp_path) - #TODO: all pxe packages on one same place @echo "Deleting NFS directory: $(nfs_path)" + + #TODO: all pxe packages on one same place @echo "purging PXE packages: " - @if [ -n "$(PACKAGES)" ]; then sudo apt-get remove --purge -y $(PACKAGES); fi @sudo apt-get remove --purge dnsmasq nfs-kernel-server syslinux @echo "Cleaning up package leftovers..." -- 2.30.2 From f69082dbc8529351e6455a6ed79478978a90cd85 Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Thu, 24 Oct 2024 06:37:01 -0300 Subject: [PATCH 5/9] cabj colors to boot menu --- pxe/pxe-menu.cfg.example | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pxe/pxe-menu.cfg.example b/pxe/pxe-menu.cfg.example index f702f1f..c93a512 100644 --- a/pxe/pxe-menu.cfg.example +++ b/pxe/pxe-menu.cfg.example @@ -4,6 +4,13 @@ TIMEOUT 50 ONTIMEOUT wb MENU TITLE PXE Boot Menu +MENU BACKGROUND 0000FF +MENU COLOR BORDER 37;44 +MENU COLOR TITLE 37;44 +MENU COLOR SEL 0;43 +MENU COLOR UNSEL 37;44 +MENU COLOR HELP 37;44 + LABEL wb MENU LABEL Boot Workbench -- 2.30.2 From 58ee9237c862feb7d00017d0c601ea18940f723f Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Sat, 26 Oct 2024 01:31:10 -0300 Subject: [PATCH 6/9] docker support for iso build added --- docker-compose.yaml | 17 +++++++++++++++++ docker/Dockerfile.build | 28 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 docker-compose.yaml create mode 100644 docker/Dockerfile.build diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..e4cb34a --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,17 @@ + +services: + build-iso: + build: + context: . + dockerfile: docker/Dockerfile.build + #this is needed for mount + privileged: true + volumes: + - type: bind + source: . + target: /var/opt + read_only: true + - type: bind + source: ./iso + target: /var/opt/iso + read_only: false diff --git a/docker/Dockerfile.build b/docker/Dockerfile.build new file mode 100644 index 0000000..921e31e --- /dev/null +++ b/docker/Dockerfile.build @@ -0,0 +1,28 @@ +FROM debian:bookworm-slim + +# Install dependencies +RUN apt-get update && apt-get install -y \ + smartmontools \ + lshw \ + hwinfo \ + dmidecode \ + python3 \ + pipenv \ + sudo \ + debootstrap \ + && rm -rf /var/lib/apt/lists/* + + +WORKDIR /var/opt + +#allow sudo so that deploy-workbench.sh runs +RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo +RUN echo "docker ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers + +RUN chown -R docker /var/opt/iso + +ENV USER=docker +USER docker + +COPY ./deploy-workbench.sh ./ +ENTRYPOINT sh deploy-workbench.sh -- 2.30.2 From fde7173ea5064965b41dd166971000971f6b4a3a Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 11 Dec 2024 19:49:33 +0100 Subject: [PATCH 7/9] pxe/Makefile: avoid the clean method move qemu-system to install dependencies --- install-dependencies.sh | 13 ++++++++++++- pxe/Makefile | 36 ++---------------------------------- 2 files changed, 14 insertions(+), 35 deletions(-) diff --git a/install-dependencies.sh b/install-dependencies.sh index bb97b97..ae00ba0 100755 --- a/install-dependencies.sh +++ b/install-dependencies.sh @@ -9,7 +9,18 @@ set -u set -x main() { - sudo apt install smartmontools lshw hwinfo dmidecode + sudo apt update && \ + apt install -y \ + smartmontools \ + lshw \ + hwinfo \ + dmidecode \ + inxi \ + python3 \ + pipenv \ + sudo \ + debootstrap \ + qemu-system } main "${@}" diff --git a/pxe/Makefile b/pxe/Makefile index febfecb..a650e01 100644 --- a/pxe/Makefile +++ b/pxe/Makefile @@ -1,40 +1,8 @@ -include .env -export $(shell sed 's/=.*//' .env) - .PHONY: test_pxe - -clean: - @if [ ! -f .env ]; then \ - echo ".env file not found!."; \ - exit 1; \ - fi - - @echo "Purging PXE files & packages -- THIS DOES NOT DELETE /SNAPSHOTS" - - @echo "Deleting NFS directory: $(nfs_path)" - @rm -rf $(nfs_path) - - @echo "Deleting TFTP directory: $(tftp_path)" - @rm -rf $(tftp_path) - - @echo "Deleting NFS directory: $(nfs_path)" - - #TODO: all pxe packages on one same place - @echo "purging PXE packages: " - - @sudo apt-get remove --purge dnsmasq nfs-kernel-server syslinux - @echo "Cleaning up package leftovers..." - @sudo apt-get autoremove -y - @sudo apt-get clean - - @echo "clean done" - - test_pxe: qemu-system-x86_64 -m 1G -boot n -netdev user,id=mynet0,tftp=/srv/pxe-tftp,bootfile=pxelinux.0 -device virtio-net,netdev=mynet0 -install_qemu: - sudo apt-get install qemu-system - +# TODO not very convinced on having this, but ok right now +.PHONY: install_pxe_debug install_pxe_debug: DEBUG=true ./install-pxe.sh -- 2.30.2 From 6e709bc9ed53b8af9029b49fabe6908c6f316301 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 12 Dec 2024 01:33:12 +0100 Subject: [PATCH 8/9] refactor docker remove install deps in deploy script, centralize them --- Dockerfile | 16 +++++++++++ deploy-workbench.sh | 52 ++++++++++++----------------------- docker-compose.yaml | 20 ++++++-------- docker/Dockerfile.build | 28 ------------------- install-dependencies.sh | 60 ++++++++++++++++++++++++++++++++--------- 5 files changed, 88 insertions(+), 88 deletions(-) create mode 100644 Dockerfile delete mode 100644 docker/Dockerfile.build diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..55cc14d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM debian:bookworm-slim + +# detect DOCKER_BUILD condition/situation in install script +ENV DOCKER_BUILD true + +# pre install sudo +RUN apt update && apt install sudo && rm -rf /var/lib/apt/lists/* + +# Install dependencies +COPY ./install-dependencies.sh / +RUN /install-dependencies.sh \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /opt/workbench-script + +ENTRYPOINT sh ./deploy-workbench.sh diff --git a/deploy-workbench.sh b/deploy-workbench.sh index 7996c09..113230c 100755 --- a/deploy-workbench.sh +++ b/deploy-workbench.sh @@ -197,7 +197,15 @@ create_persistence_partition() { tmp_rw_mount="/tmp/${rw_img_name}" ${SUDO} umount -f -l "${tmp_rw_mount}" >/dev/null 2>&1 || true mkdir -p "${tmp_rw_mount}" - ${SUDO} mount "$(pwd)/${rw_img_path}" "${tmp_rw_mount}" + # detect relative path, else absolute path + # TODO solve this situation better + # thanks https://unix.stackexchange.com/questions/256434/check-if-shell-variable-contains-an-absolute-path + if [ "${rw_img_path}" = "${rw_img_path#/}" ]; then + mount_rw_img_path="$(pwd)/${rw_img_path}" + else + mount_rw_img_path="${rw_img_path}" + fi + ${SUDO} mount "${mount_rw_img_path}" "${tmp_rw_mount}" ${SUDO} mkdir -p "${tmp_rw_mount}" if [ ! -f "settings.ini" ]; then ${SUDO} cp -v settings.ini.example settings.ini @@ -324,14 +332,12 @@ END echo 'Install requirements' # Install debian requirements +# TODO converge more here with install-dependencies.sh apt-get install -y --no-install-recommends \ sudo locales keyboard-configuration console-setup qrencode \ python-is-python3 python3 python3-dev python3-pip pipenv \ dmidecode smartmontools hwinfo pciutils lshw nfs-common < /dev/null -# Install lshw B02.19 utility using backports (DEPRECATED in Debian 12) -#apt install -y -t ${VERSION_CODENAME}-backports lshw < /dev/null - echo 'Install sanitize requirements' # Install sanitize debian requirements @@ -432,8 +438,10 @@ if [ -z "${DEBUG:-}" ]; then fi # cleanup bash history -history -c - +# https://stackoverflow.com/questions/3199893/howto-detect-bash-from-shell-script +if [ "\${BASH_VERSION}" ]; then + history -c +fi CHROOT } @@ -474,32 +482,6 @@ prepare_chroot_env() { prepare_app } - -# thanks https://willhaley.com/blog/custom-debian-live-environment/ -install_requirements() { - # Install requirements - eval "${decide_if_update_str}" && decide_if_update - image_deps='debootstrap - squashfs-tools - xorriso - mtools - dosfstools' - # secureboot: - # -> extra src https://wiki.debian.org/SecureBoot/ - # -> extra src https://wiki.debian.org/SecureBoot/VirtualMachine - # -> extra src https://wiki.debian.org/GrubEFIReinstall - bootloader_deps='isolinux - syslinux-efi - grub-pc-bin - grub-efi-amd64-bin - ovmf - shim-signed - grub-efi-amd64-signed' - ${SUDO} apt-get install -y \ - ${image_deps} \ - ${bootloader_deps} -} - # thanks https://willhaley.com/blog/custom-debian-live-environment/ create_base_dirs() { mkdir -p "${ISO_PATH}" @@ -524,7 +506,7 @@ detect_user() { echo "ERROR: this script needs root or sudo permissions (current user is not part of sudo group)" exit 1 # detect user with sudo or already on sudo src https://serverfault.com/questions/568627/can-a-program-tell-it-is-being-run-under-sudo/568628#568628 - elif [ ! "\${userid}" = 0 ] || [ -n "\${SUDO_USER}" ]; then + elif [ ! "\${userid}" = 0 ] || [ -n "\${SUDO_USER:-}" ]; then SUDO='sudo' # jump to current dir where the script is so relative links work cd "\$(dirname "\${0}")" @@ -533,7 +515,7 @@ detect_user() { # detect pure root elif [ "\${userid}" = 0 ]; then SUDO='' - ISO_PATH="/opt/workbench" + ISO_PATH="/opt/workbench-script/iso" fi } END @@ -554,7 +536,7 @@ main() { create_base_dirs - install_requirements + echo 'Assuming that you already executed ./install-dependencies.sh' prepare_chroot_env diff --git a/docker-compose.yaml b/docker-compose.yaml index e4cb34a..2fac0b3 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,17 +1,13 @@ services: build-iso: - build: - context: . - dockerfile: docker/Dockerfile.build - #this is needed for mount + init: true + build: . + # this is needed to mount inside docker privileged: true + # uncomment next two lines to test this + environment: + - DEBUG=true volumes: - - type: bind - source: . - target: /var/opt - read_only: true - - type: bind - source: ./iso - target: /var/opt/iso - read_only: false + - .:/opt/workbench-script:ro + - ./iso:/opt/workbench-script/iso:rw diff --git a/docker/Dockerfile.build b/docker/Dockerfile.build deleted file mode 100644 index 921e31e..0000000 --- a/docker/Dockerfile.build +++ /dev/null @@ -1,28 +0,0 @@ -FROM debian:bookworm-slim - -# Install dependencies -RUN apt-get update && apt-get install -y \ - smartmontools \ - lshw \ - hwinfo \ - dmidecode \ - python3 \ - pipenv \ - sudo \ - debootstrap \ - && rm -rf /var/lib/apt/lists/* - - -WORKDIR /var/opt - -#allow sudo so that deploy-workbench.sh runs -RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo -RUN echo "docker ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers - -RUN chown -R docker /var/opt/iso - -ENV USER=docker -USER docker - -COPY ./deploy-workbench.sh ./ -ENTRYPOINT sh deploy-workbench.sh diff --git a/install-dependencies.sh b/install-dependencies.sh index ae00ba0..b081021 100755 --- a/install-dependencies.sh +++ b/install-dependencies.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (c) 2024 Pedro +# Copyright (c) 2024 pangea.org AssociaciĆ³ Pangea - Coordinadora ComunicaciĆ³ per a la CooperaciĆ³ # SPDX-License-Identifier: AGPL-3.0-or-later set -e @@ -9,18 +9,52 @@ set -u set -x main() { - sudo apt update && \ - apt install -y \ - smartmontools \ - lshw \ - hwinfo \ - dmidecode \ - inxi \ - python3 \ - pipenv \ - sudo \ - debootstrap \ - qemu-system + sudo apt update + + # system dependencies + host_deps='sudo' + # thanks https://stackoverflow.com/questions/23513045/how-to-check-if-a-process-is-running-inside-docker-container + if [ ! "${DOCKER_BUILD}" ]; then + host_deps="${host_deps} qemu-system" + fi + + # workbench deploy/builder image dependencies + image_deps='debootstrap + squashfs-tools + xorriso + mtools + dosfstools' + + # workbench deploy/builder bootloader dependencies + # thanks https://willhaley.com/blog/custom-debian-live-environment/ + # secureboot: + # -> extra src https://wiki.debian.org/SecureBoot/ + # -> extra src https://wiki.debian.org/SecureBoot/VirtualMachine + # -> extra src https://wiki.debian.org/GrubEFIReinstall + bootloader_deps='isolinux + syslinux-efi + syslinux-common + grub-pc-bin + grub-efi-amd64-bin + ovmf + shim-signed + grub-efi-amd64-signed' + + # workbench-script client dependencies + client_deps='smartmontools + lshw + hwinfo + dmidecode + inxi + python3 + pipenv' + + # install all + sudo apt install --no-install-recommends -y \ + ${host_deps} \ + ${image_deps} \ + ${bootloader_deps} \ + ${client_deps} } main "${@}" -- 2.30.2 From 490a8a2e47fb9f6c2deaf8d749fc7ebe35b6e3dd Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 12 Dec 2024 01:37:44 +0100 Subject: [PATCH 9/9] postpone color customization to indefinite future --- pxe/pxe-menu.cfg.example | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pxe/pxe-menu.cfg.example b/pxe/pxe-menu.cfg.example index c93a512..f702f1f 100644 --- a/pxe/pxe-menu.cfg.example +++ b/pxe/pxe-menu.cfg.example @@ -4,13 +4,6 @@ TIMEOUT 50 ONTIMEOUT wb MENU TITLE PXE Boot Menu -MENU BACKGROUND 0000FF -MENU COLOR BORDER 37;44 -MENU COLOR TITLE 37;44 -MENU COLOR SEL 0;43 -MENU COLOR UNSEL 37;44 -MENU COLOR HELP 37;44 - LABEL wb MENU LABEL Boot Workbench -- 2.30.2