From 624a2ea3e364819e0bf6470f76db9b0e84fbc794 Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Thu, 24 Oct 2024 04:31:39 -0300 Subject: [PATCH 01/10] 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 3effbef..6faedb1 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 41e16284043f434d207f092bab6af6c842f7c72c Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Thu, 24 Oct 2024 05:32:01 -0300 Subject: [PATCH 02/10] 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 8040bebe586e42868a5c314a0b924096139c4637 Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Thu, 24 Oct 2024 06:23:30 -0300 Subject: [PATCH 03/10] 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 e6636f76d5e8b831842044ee9a695df5bfabd5b2 Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Thu, 24 Oct 2024 06:37:01 -0300 Subject: [PATCH 04/10] 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 c4a6f78d2922dcc4334648045cca2bf06be981c7 Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Sat, 26 Oct 2024 01:31:10 -0300 Subject: [PATCH 05/10] 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 da4830326c6be23cc013ee6841e4bc9180e64fae Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 11 Dec 2024 19:49:33 +0100 Subject: [PATCH 06/10] 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 e1f7345..ae00ba0 100755 --- a/install-dependencies.sh +++ b/install-dependencies.sh @@ -9,7 +9,18 @@ set -u set -x main() { - sudo apt install qrencode smartmontools lshw hwinfo dmidecode inxi + 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 42c48af14d6acda83e9d26ff590e174edccd37c9 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 12 Dec 2024 01:33:12 +0100 Subject: [PATCH 07/10] 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 6faedb1..bf02317 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 inxi < /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 c3ca89f734ace940bad8d6e16d9883a20cee0953 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 12 Dec 2024 01:37:44 +0100 Subject: [PATCH 08/10] 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 From fd7e39d91bb9fe5aaaf19e047fc13ebfb6073f78 Mon Sep 17 00:00:00 2001 From: pedro Date: Mon, 16 Dec 2024 18:28:55 +0100 Subject: [PATCH 09/10] fix copyright headers --- pxe/install-pxe.sh | 2 +- workbench-script.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pxe/install-pxe.sh b/pxe/install-pxe.sh index 4f08826..695ba9a 100755 --- a/pxe/install-pxe.sh +++ b/pxe/install-pxe.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 diff --git a/workbench-script.py b/workbench-script.py index a839ff8..81c72ef 100644 --- a/workbench-script.py +++ b/workbench-script.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- +# Copyright (c) 2024 pangea.org Associació Pangea - Coordinadora Comunicació per a la Cooperació +# SPDX-License-Identifier: AGPL-3.0-or-later + import os import json import uuid -- 2.30.2 From 43c76017ef9573d2675ffb88855c16751d9d5533 Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 4 Feb 2025 17:48:11 +0100 Subject: [PATCH 10/10] add qrencode as client dep --- install-dependencies.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install-dependencies.sh b/install-dependencies.sh index b081021..828c40c 100755 --- a/install-dependencies.sh +++ b/install-dependencies.sh @@ -47,7 +47,8 @@ main() { dmidecode inxi python3 - pipenv' + pipenv + qrencode' # install all sudo apt install --no-install-recommends -y \ -- 2.30.2