From 05886eaa2eeb71250ab0ff26e1143c30ddd5a778 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 21 Oct 2024 00:23:04 +0200 Subject: [PATCH] refs #905: Improves installer - Add function for deploying scripts in chroot - Install selected components in YAD dialog - Adds calamares packages module to the workflow to install vim and git - Deploy component installer to /opengnsys-installer/component-installer.sh in final system - Injects modules configs in /opengnsys-installer in the end system. - Creates ogadmin group in end system tor created user - template name changed to ogserver - --- builder.sh | 37 +++++++---- calamares/modules/packages.conf | 8 +++ calamares/modules/packages/packages.conf | 1 + calamares/modules/shell_chroot.conf | 2 +- calamares/modules/shell_nonchroot.conf | 9 +-- .../modules/shellprocess/shell_chroot.conf | 10 +-- .../modules/shellprocess/shell_nonchroot.conf | 13 +--- calamares/modules/users.conf | 16 +++-- calamares/settings.conf | 1 + component-installer.sh | 62 +++++++++++++++++-- pat.txt | 1 + root_passwd | 1 + 12 files changed, 107 insertions(+), 54 deletions(-) create mode 100644 calamares/modules/packages.conf create mode 120000 calamares/modules/packages/packages.conf mode change 100644 => 120000 calamares/modules/shellprocess/shell_chroot.conf mode change 100644 => 120000 calamares/modules/shellprocess/shell_nonchroot.conf create mode 100644 pat.txt create mode 100644 root_passwd diff --git a/builder.sh b/builder.sh index 12f7f28..e6e7648 100755 --- a/builder.sh +++ b/builder.sh @@ -13,19 +13,20 @@ CLEAN_CHROOT=${CLEAN_CHROOT:-1} OUTPUT_DIR=/media/sf_Downloads/ IMAGE_DIR=$DIR/image DEBOOT_STRAP_URL=http://mirror.raiolanetworks.com/ubuntu/ +SUDO_PASSWD=${SUDO_PASSWD:-$(cat $PASSWD_FILE)} export PASSWD_FILE ## FUNCIONES function exec_as_sudo () { - cat $PASSWD_FILE | sudo -S $@ + cat $PASSWD_FILE | sudo -S "$@" } function exec_as_sudo_in_chroot () { local CHROOT=$1 shift - exec_as_sudo chroot $CHROOT $@ + exec_as_sudo chroot $CHROOT "$@" } function umount_in_chroot() { @@ -53,6 +54,15 @@ function umount_in_host() { return 0 } +function deploy_script_in_chroot() { + local CHROOT=$1 + local SCRIPT=$2 + local DESTDIR=$3 + exec_as_sudo mkdir -p $CHROOT/$DESTDIR + exec_as_sudo cp $SCRIPT $CHROOT/$DESTDIR + exec_as_sudo chmod +x $CHROOT/$DESTDIR/$SCRIPT +} + function deploy_installer() { exec_as_sudo mkdir -p $CHROOT_DIR/usr/local/bin exec_as_sudo cp openGnsys-installer.sh $CHROOT_DIR/usr/local/bin @@ -78,7 +88,7 @@ then exec_as_sudo rm -rf $CHROOT_DIR exec_as_sudo rm -rf $UBUNTU_CHROOT_DIR fi - exec_as_sudo rm -rf image + exec_as_sudo rm -rf $DIR/image exec_as_sudo rm -f $OUTPUT_DIR/ubuntu-from-scratch.iso fi @@ -95,9 +105,10 @@ if [ $CLEAN_CHROOT -eq 1 ]; then exec_as_sudo debootstrap --arch=amd64 --variant=$VARIANT $DIST $CHROOT_DIR $DEBOOT_STRAP_URL fi -exec_as_sudo mkdir -p $CHROOT_DIR/etc/calamares/ -exec_as_sudo cp -r calamares/* $CHROOT_DIR/etc/calamares/ -deploy_installer +exec_as_sudo mkdir -p $CHROOT_DIR/etc/calamares/modules/ +exec_as_sudo cp calamares/settings.conf $CHROOT_DIR/etc/calamares/ +exec_as_sudo cp calamares/modules/*.conf $CHROOT_DIR/etc/calamares/modules/ +deploy_script_in_chroot $CHROOT_DIR openGnsys-installer.sh /usr/local/bin/ # # Create mount points exec_as_sudo mount --bind /dev/ $CHROOT_DIR/dev @@ -112,9 +123,9 @@ exec_as_sudo_in_chroot $CHROOT_DIR /chroot_setup.sh umount_in_host $CHROOT_DIR/dev umount_in_host $CHROOT_DIR/run -# Compress the chroot +# Compress the chroot deploy mkdir -p $IMAGE_DIR -exec_as_sudo mv $CHROOT_DIR/image $IMAGE_DIR/ +exec_as_sudo mv $CHROOT_DIR/image $DIR/ # Create squashfs imagesudo @@ -124,13 +135,16 @@ exec_as_sudo mksquashfs $CHROOT_DIR $IMAGE_DIR/casper/filesystem.squashfs \ -comp xz -b 1M -Xdict-size 100% \ -e "var/cache/apt/archives/*" -e "root/*" -e "root/.*" -e "tmp/*" -e "tmp/.*" -e "swapfile" -printf $(exec_as_sudo du -sx --block-size=1 chroot | cut -f1) | sudo tee image/casper/filesystem.size +printf $(exec_as_sudo du -sx --block-size=1 $CHROOT_DIR | cut -f1) | sudo tee $IMAGE_DIR/casper/filesystem.size # Deboot strap real Ubuntu image exec_as_sudo debootstrap --arch=amd64 --variant=minbase noble $UBUNTU_CHROOT_DIR $DEBOOT_STRAP_URL exec_as_sudo cp setup_chroot_ubuntu.sh $UBUNTU_CHROOT_DIR exec_as_sudo_in_chroot $UBUNTU_CHROOT_DIR chmod +x /setup_chroot_ubuntu.sh exec_as_sudo cp buildlib.sh $UBUNTU_CHROOT_DIR +deploy_script_in_chroot $UBUNTU_CHROOT_DIR component-installer.sh /opengnsys-installer/ +exec_as_sudo cp pat.txt $UBUNTU_CHROOT_DIR/opengnsys-installer/ + # Setup the chroot for ubuntu exec_as_sudo mount --bind /dev/ $UBUNTU_CHROOT_DIR/dev @@ -151,10 +165,7 @@ exec_as_sudo mksquashfs $UBUNTU_CHROOT_DIR $IMAGE_DIR/casper/filesystem.ubuntu.s -comp xz -b 1M -Xdict-size 100% \ -e "var/cache/apt/archives/*" -e "root/*" -e "root/.*" -e "tmp/*" -e "tmp/.*" -e "swapfile" - - # Create ISO image - cd $IMAGE_DIR && \ exec_as_sudo xorriso \ -as mkisofs \ @@ -190,4 +201,4 @@ exec_as_sudo xorriso \ "/isolinux/bios.img=isolinux/bios.img" \ "/isolinux/efiboot.img=isolinux/efiboot.img" \ "." -cd .. +cd - diff --git a/calamares/modules/packages.conf b/calamares/modules/packages.conf new file mode 100644 index 0000000..a1e5c65 --- /dev/null +++ b/calamares/modules/packages.conf @@ -0,0 +1,8 @@ +--- + +update_db: true +backend: apt +operations: + - install: + - vim + - git diff --git a/calamares/modules/packages/packages.conf b/calamares/modules/packages/packages.conf new file mode 120000 index 0000000..b4858d4 --- /dev/null +++ b/calamares/modules/packages/packages.conf @@ -0,0 +1 @@ +../packages.conf \ No newline at end of file diff --git a/calamares/modules/shell_chroot.conf b/calamares/modules/shell_chroot.conf index 4c0565c..cc33d48 100644 --- a/calamares/modules/shell_chroot.conf +++ b/calamares/modules/shell_chroot.conf @@ -3,7 +3,7 @@ dontChroot: false verbose: true script: - - /tmp/opengnsys-configs/component-installer.sh + - /opengnsys-installer/component-installer.sh diff --git a/calamares/modules/shell_nonchroot.conf b/calamares/modules/shell_nonchroot.conf index 7719f8d..79a656f 100644 --- a/calamares/modules/shell_nonchroot.conf +++ b/calamares/modules/shell_nonchroot.conf @@ -3,10 +3,7 @@ dontChroot: true verbose: true script: - - mkdir -p ${ROOT}/tmp/opengnsys-configs - - cp /tmp/opengnsys-installer-configs/* ${ROOT}/tmp/opengnsys-configs - - cp /home/narenas/w/remote_fs/oginstaller/component-installer.sh ${ROOT}/tmp/opengnsys-configs - - chmod 755 ${ROOT}/tmp/opengnsys-configs/component-installer.sh - - + - mkdir -p ${ROOT}/opengnsys-installer + - cp /tmp/opengnsys-installer-configs/* ${ROOT}/opengnsys-installer + diff --git a/calamares/modules/shellprocess/shell_chroot.conf b/calamares/modules/shellprocess/shell_chroot.conf deleted file mode 100644 index 4c0565c..0000000 --- a/calamares/modules/shellprocess/shell_chroot.conf +++ /dev/null @@ -1,9 +0,0 @@ ---- - -dontChroot: false -verbose: true -script: - - /tmp/opengnsys-configs/component-installer.sh - - - diff --git a/calamares/modules/shellprocess/shell_chroot.conf b/calamares/modules/shellprocess/shell_chroot.conf new file mode 120000 index 0000000..9c2cd89 --- /dev/null +++ b/calamares/modules/shellprocess/shell_chroot.conf @@ -0,0 +1 @@ +../shell_chroot.conf \ No newline at end of file diff --git a/calamares/modules/shellprocess/shell_nonchroot.conf b/calamares/modules/shellprocess/shell_nonchroot.conf deleted file mode 100644 index 7719f8d..0000000 --- a/calamares/modules/shellprocess/shell_nonchroot.conf +++ /dev/null @@ -1,12 +0,0 @@ ---- - -dontChroot: true -verbose: true -script: - - mkdir -p ${ROOT}/tmp/opengnsys-configs - - cp /tmp/opengnsys-installer-configs/* ${ROOT}/tmp/opengnsys-configs - - cp /home/narenas/w/remote_fs/oginstaller/component-installer.sh ${ROOT}/tmp/opengnsys-configs - - chmod 755 ${ROOT}/tmp/opengnsys-configs/component-installer.sh - - - diff --git a/calamares/modules/shellprocess/shell_nonchroot.conf b/calamares/modules/shellprocess/shell_nonchroot.conf new file mode 120000 index 0000000..c36ce51 --- /dev/null +++ b/calamares/modules/shellprocess/shell_nonchroot.conf @@ -0,0 +1 @@ +../shell_nonchroot.conf \ No newline at end of file diff --git a/calamares/modules/users.conf b/calamares/modules/users.conf index 612b8e9..7cac53e 100644 --- a/calamares/modules/users.conf +++ b/calamares/modules/users.conf @@ -1,21 +1,18 @@ defaultGroups: - name: users system: true - - adm: - system: true - - cdrom: - system: true - - sudo: - system: true - dip: system: true - plugdev: system: true - lxd: system: true + - ogadmin: + -sudoersGroup: sudo -setRootPassword: false +sudoersGroup: ogadmin +setRootPassword: true +doReusePassword: true passwordRequirements: minLength: -1 # Password at least this many characters maxLength: -1 # Password at most this many characters @@ -28,9 +25,10 @@ user: forbidden_names: [ root ] home_permissions: "0700" + hostname: location: EtcFile writeHostsFile: true - template: "derp-${cpu}" + template: "ogServer" forbidden_names: [ localhost ] diff --git a/calamares/settings.conf b/calamares/settings.conf index 66c58fc..cc47ec2 100644 --- a/calamares/settings.conf +++ b/calamares/settings.conf @@ -24,6 +24,7 @@ sequence: - partition - mount - unpackfs + - packages - machineid - locale - keyboard diff --git a/component-installer.sh b/component-installer.sh index 37ccd0c..f245ab1 100644 --- a/component-installer.sh +++ b/component-installer.sh @@ -3,17 +3,71 @@ # Paso 1: Seleccionar los componentes # Los componentes a instalar se encuentran en el directorio /tmp/opengnsys-installer-configs -COMPONENTS="ogCore ogGui ogDhcp ogBoot" -CONFIGS_DIR=/tmp/opengnsys-configs +# Set configuration + +COMPONENTS="ogCore ogGui ogDhcp ogBoot ogRepository" +CONFIGS_DIR=/opengnsys-installer/ +PAT_FILE=/opengnsys-installer/pat.txt +PAT=$(cat $PAT_FILE | tr -d '\n\r\t') + +OPENGNSYS_BASE_URL="https://$PAT@ognproject.evlt.uma.es/gitea/opengnsys" + +OGBOOT_REPO="$OPENGNSYS_BASE_URL/ogboot.git" +OGCORE_REPO="$OPENGNSYS_BASE_URL/ogcore.git" +OGDHCP_REPO="$OPENGNSYS_BASE_URL/ogdhcp.git" +OGGUI_REPO="$OPENGNSYS_BASE_URL/oggui.git" +OGREPOSITORY_REPO="$OPENGNSYS_BASE_URL/oggui.git" + +export GIT_SSL_NO_VERIFY=1 +echo ======================================== > /etc/issue +echo "OpenGnSys Installer" >> /etc/issue +echo "Componentes instalados:" >> /etc/issue + + for component in $COMPONENTS do config_file="config_${component}.json" if [ -f $CONFIGS_DIR/$config_file ]; then echo "Componente $component seleccionado, instalando configuración..." - mkdir -p /opt/opengnsys/$component - mkdir -p /opt/opengnsys/$component/installer + component_dir=/opt/opengnsys/$component + mkdir -p $component_dir/installer + mkdir -p $component_dir/repo cp $CONFIGS_DIR/$config_file /opt/opengnsys/$component/installer/config.json + + case $component in + ogCore) + echo "Instalando ogCore..." + git clone "$OGCORE_REPO" "$component_dir/repo" + echo - ogCore >> /etc/issue + ;; + ogGui) + echo "Instalando ogGui..." + git clone "$OGGUI_REPO" "$component_dir/repo" + echo - ogGui >> /etc/issue + ;; + ogDhcp) + echo "Instalando ogDhcp..." + git clone "$OGDHCP_REPO" "$component_dir/repo" + echo - ogDhcp >> /etc/issue + ;; + ogBoot) + echo "Instalando ogBoot..." + git clone "$OGBOOT_REPO" "$component_dir/repo" + echo - ogBoot >> /etc/issue + ;; + ogRepository) + echo "Instalando ogRepository..." + git clone "$OGREPOSITORY_REPO" "$component_dir/repo" + echo - ogRepository >> /etc/issue + ;; + *) + echo "Componente $component no reconocido" + ;; + esac continue fi done + +echo ======================================== >> /etc/issue +rm -f $PAT_FILE diff --git a/pat.txt b/pat.txt new file mode 100644 index 0000000..9f124fb --- /dev/null +++ b/pat.txt @@ -0,0 +1 @@ +62d16790e5fd693e3b1cd21a0fb4fe11ab9851bb diff --git a/root_passwd b/root_passwd new file mode 100644 index 0000000..d8649da --- /dev/null +++ b/root_passwd @@ -0,0 +1 @@ +root