From ad5f6e356fa436574165c030f2614d9db77fe69d Mon Sep 17 00:00:00 2001
From: valentin <valentinb@fsmpi.rwth-aachen.de>
Date: Sat, 16 Oct 2021 14:15:09 +0200
Subject: [PATCH] image for LIP WS21: 2 kubuntu versions

grub template can now include multiple images
---
 assemble_image.sh | 37 +++++++++----------
 grub_config.sh    | 19 ++++++----
 grub_template.cfg | 94 +++++++++++++----------------------------------
 packages          |  6 +--
 4 files changed, 56 insertions(+), 100 deletions(-)

diff --git a/assemble_image.sh b/assemble_image.sh
index 539199c..5ab3e77 100755
--- a/assemble_image.sh
+++ b/assemble_image.sh
@@ -3,43 +3,39 @@
 set -e
 set -x
 
-# TODO update image file names
-image_size="7G"
-kubuntu="focal-desktop-amd64.iso"
-xubuntu="focal-desktop-amd64.iso"
-old_buntu="$kubuntu"
+image_size="6400M"
+img1="kubuntu-20.04.3-desktop-amd64.iso"
+img2="kubuntu-21.10-desktop-amd64.iso"
+bootimg="$img1"
 : ${workspace:="/workspace"}
 
 # mtools, ddrescure, fdisk, grub, 7z
 rm -rf "$workspace/part_files"
 mkdir -p "$workspace/part_files"
-git -C "$workspace/part_files" clone -b tardis https://git.fsmpi.rwth-aachen.de/osak/lipstick.git .
+# copy only relevant files
+git -C "$workspace/part_files" clone --depth 1 --single-branch --branch tardis https://git.fsmpi.rwth-aachen.de/osak/lipstick.git .
 rsync -av /usr/lib/grub/i386-efi "$workspace/part_files"/grub
 rsync -av /usr/lib/grub/i386-pc "$workspace/part_files"/grub
 rsync -av /usr/share/grub/themes "$workspace/part_files"/grub
 mkdir -p "$workspace/part_files"/grub/fonts/
 rsync -av /usr/share/grub/unicode.pf2 "$workspace/part_files"/grub/fonts/
 
-7z x "$old_buntu" -o"$workspace/part_files" EFI/
-7z x "$old_buntu" -o"$workspace/part_files" boot/grub/x86_64-efi
+7z x "$bootimg" -o"$workspace/part_files" EFI/
+7z x "$bootimg" -o"$workspace/part_files" boot/grub/x86_64-efi
 
 mv "$workspace/part_files"/grub/* "$workspace/part_files"/boot/grub/
 rm -rf "$workspace/part_files"/grub
 
-rsync --size-only --checksum "$kubuntu" "$workspace/part_files/"
-rsync --size-only --checksum "$xubuntu" "$workspace/part_files/"
+rsync --copy-links --size-only --checksum "$img1" "$workspace/part_files/"
+rsync --copy-links --size-only --checksum "$img2" "$workspace/part_files/"
 
 source ./grub_config.sh # functions to fill grub_template.cfg
 cp grub_template.cfg "$workspace/part_files/boot/grub/grub.cfg"
-fill_grub_config_template "$kubuntu" "KDE" "$workspace/part_files/boot/grub/grub.cfg"
-fill_grub_config_template "$xubuntu" "XFCE" "$workspace/part_files/boot/grub/grub.cfg"
-
-# TODO update kernel urls
-wget -nc -P "$workspace/part_files/" "https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.6-rc4/linux-headers-5.6.0-050600rc4-generic_5.6.0-050600rc4.202003012332_amd64.deb"
-wget -nc -P "$workspace/part_files/" "https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.6-rc4/linux-image-unsigned-5.6.0-050600rc4-generic_5.6.0-050600rc4.202003012332_amd64.deb"
-wget -nc -P "$workspace/part_files/" "https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.6-rc4/linux-modules-5.6.0-050600rc4-generic_5.6.0-050600rc4.202003012332_amd64.deb"
-./create_offlinerepo.sh "$workspace/part_files/archives" "$kubuntu" $(grep '^[^#]' packages | cut -d'|' -f 2)
-./create_offlinerepo.sh "$workspace/part_files/archives" "$xubuntu" $(grep '^[^#]' packages | cut -d'|' -f 2)
+fill_grub_config_template "$img1" "$workspace/part_files/boot/grub/grub.cfg"
+fill_grub_config_template "$img2" "$workspace/part_files/boot/grub/grub.cfg"
+
+#./create_offlinerepo.sh "$workspace/part_files/archives" "$img1" $(grep '^[^#]' packages | cut -d'|' -f 2)
+#./create_offlinerepo.sh "$workspace/part_files/archives" "$img2" $(grep '^[^#]' packages | cut -d'|' -f 2)
 cp packages "$workspace/part_files/packages"
 echo "ubiquity ubiquity/keep-installed string $(grep '^[^#]' packages | cut -d'|' -f 2 | tr '\n' ' ')" >> "$workspace/part_files/preseed/lip.seed"
 
@@ -47,9 +43,10 @@ rm -f "$workspace/part.img"
 truncate -s "$image_size" "$workspace/part.img"
 mkfs.vfat -n "LIPSTICK" "$workspace/part.img"
 MTOOLS_SKIP_CHECK=1 mcopy -i "$workspace/part.img" -b -s -v "$workspace/part_files"/* "$workspace/part_files"/.git ::
+rm -rf "$workspace/part_files"
 grub-mkimage --prefix "(hd0,msdos1)/boot/grub" --output "$workspace/grub.i386-pc.img" --format "i386-pc" part_msdos fat ext2 biosdisk
 dd if=/usr/lib/grub/i386-pc/boot.img of="$workspace/output.img" bs=446 count=1
 dd if="$workspace/grub.i386-pc.img" of="$workspace/output.img" bs=512 seek=1
 ddrescue --output-position=2048s --sparse "$workspace/part.img" "$workspace/output.img"
 printf "label: dos\nunit: sectors\n2048,+,b,*\n" | sfdisk "$workspace/output.img"
-echo "Used $(du -s -h "$workspace/part_files" | cut -f1) of ${image_size}"
+echo "Used $(du -s -h "$workspace/output.img" | cut -f1) of ${image_size}"
diff --git a/grub_config.sh b/grub_config.sh
index fdfce67..dffaa47 100755
--- a/grub_config.sh
+++ b/grub_config.sh
@@ -25,16 +25,19 @@ function extract_release() {
 
 function fill_grub_config_template() {
 	iso_file="$1"
-	distribution_grep="$2" # KDE / XFCE
-	sed_target="$3"
-	sed "s|__${distribution_grep}_KERNEL__|$(extract_kernel "$iso_file")|g" -i "$sed_target"
-	sed "s|__${distribution_grep}_INITRD__|$(extract_initrd "$iso_file")|g" -i "$sed_target"
-	sed "s|__${distribution_grep}_RELEASE__|$(extract_release "$iso_file")|g" -i "$sed_target"
-	sed "s|__${distribution_grep}_ISONAME__|$iso_file|g" -i "$sed_target"
+	sed_target="$2"
+	# copy template line and remove #TEMPLATE\s* in copied line
+	sed 's|^#TEMPLATE\s*\(.*\)|\1\n&|g' -i "$sed_target"
+	# replace only matches in lines which are not commented out
+	sed "/^#/!s|__KERNEL__|$(extract_kernel "$iso_file")|g" -i "$sed_target"
+	sed "/^#/!s|__INITRD__|$(extract_initrd "$iso_file")|g" -i "$sed_target"
+	sed "/^#/!s|__RELEASE__|$(extract_release "$iso_file")|g" -i "$sed_target"
+	sed "/^#/!s|__ISONAME__|$iso_file|g" -i "$sed_target"
 }
 
 # image flavors to put in the grub config
 # usage after sourcing (modifies grub_template_copy.cfg)
 # cp grub_template.cfg grub_template_copy.cfg
-# fill_grub_config_template "kubuntu-18.04.1-desktop-amd64.iso" "KDE" "grub_template_copy.cfg"
-# fill_grub_config_template "xubuntu-18.04.1-desktop-amd64.iso" "XFCE" "grub_template_copy.cfg"
+# fill_grub_config_template "kubuntu-18.04.1-desktop-amd64.iso" "grub_template_copy.cfg"
+# fill_grub_config_template "xubuntu-18.04.1-desktop-amd64.iso" "grub_template_copy.cfg"
+# Boot entries for images appear in the same order as they are generated.
diff --git a/grub_template.cfg b/grub_template.cfg
index b7745b0..15235c4 100644
--- a/grub_template.cfg
+++ b/grub_template.cfg
@@ -13,97 +13,55 @@ color yellow/black white/red
 set pager=1
 set gfxpayload=keep
 
-function kde_LoadCasper {
-    loopback loop ($root)/${kde_isoname}
+function loadCasper {
+    loopback loop ($root)/${isoname}
     echo    "Loading kernel"
-    linux   (loop)__KDE_KERNEL__ boot=casper file=/isodevice/preseed/lip.seed ${cmdline} iso-scan/filename=/__KDE_ISONAME__ sysrq_always_enabled pstore.pstore_disable nosplash verbose --
+    linux   (loop)${kernel} boot=casper file=/isodevice/preseed/lip.seed ${cmdline} iso-scan/filename=/${isoname} sysrq_always_enabled pstore.pstore_disable nosplash verbose --
     echo    "Loading initrd"
-    initrd  (loop)__KDE_INITRD__
+    initrd  (loop)${initrd}
     echo    "Starting kernel"
 }
 
-function kde_menu {
-    menuentry "Empfohlen: ${kde_release} (deutsch)" {
+# Arguments: RELEASE ISONAME KERNEL INITRD
+function img_menu {
+    set release="$1"
+    set isoname="$2"
+    set kernel="$3"
+    set initrd="$4"
+    menuentry "Empfohlen: ${release} (deutsch)" {
         set cmdline="debian-installer/language=de keyboard-configuration/layoutcode?=de"
-        kde_LoadCasper
+        loadCasper
     }
 
-    menuentry "Recommended: ${kde_release} (english)" {
+    menuentry "Recommended: ${release} (english)" {
         set cmdline=""
-        kde_LoadCasper
+        loadCasper
     }
 
-    menuentry "${kde_release} (deutsch, failsafe)" {
+    menuentry "${release} (deutsch, failsafe)" {
         set cmdline="debian-installer/locale=de_DE console-setup/layoutcode=de nomodeset noplymouth nosplash verbose text noacpi"
-        kde_LoadCasper
+        loadCasper
     }
 
-    menuentry "${kde_release} (english, failsafe)" {
+    menuentry "${release} (english, failsafe)" {
         set cmdline="nomodeset noplymouth nosplash verbose text noacpi"
-        kde_LoadCasper
+        loadCasper
     }
 
-    menuentry "${kde_release} (deutsch, ohne LIPNSA)" {
-            set cmdline="debian-installer/locale=de_DE console-setup/layoutcode=de fnord"
-            kde_LoadCasper
+    menuentry "${release} (deutsch, ohne LIPNSA)" {
+        set cmdline="debian-installer/locale=de_DE console-setup/layoutcode=de fnord"
+        loadCasper
     }
 
-    menuentry "${kde_release} (english, without LIPNSA)" {
-            set cmdline="fnord"
-            kde_LoadCasper
+    menuentry "${release} (english, without LIPNSA)" {
+        set cmdline="fnord"
+        loadCasper
     }
 }
 
-function xfce_LoadCasper {
-    loopback loop ($root)/${xfce_isoname}
-    echo    "Loading kernel"
-    linux   (loop)__XFCE_KERNEL__ boot=casper file=/isodevice/preseed/lip.seed ${cmdline} iso-scan/filename=/__XFCE_ISONAME__ sysrq_always_enabled pstore.pstore_disable nosplash verbose --
-    echo    "Loading initrd"
-    initrd  (loop)__XFCE_INITRD__
-    echo    "Starting kernel"
-}
-
-function xfce_menu {
-    menuentry "Empfohlen: ${xfce_release} (deutsch)" {
-        set cmdline="debian-installer/language=de keyboard-configuration/layoutcode?=de"
-        xfce_LoadCasper
-    }
-
-    menuentry "Recommended: ${xfce_release} (english)" {
-        set cmdline=""
-        xfce_LoadCasper
-    }
-
-    menuentry "${xfce_release} (deutsch, failsafe)" {
-        set cmdline="debian-installer/locale=de_DE console-setup/layoutcode=de nomodeset noplymouth nosplash verbose text noacpi"
-        xfce_LoadCasper
-    }
-
-    menuentry "${xfce_release} (english, failsafe)" {
-        set cmdline="nomodeset noplymouth nosplash verbose text noacpi"
-        xfce_LoadCasper
-    }
-
-    menuentry "${xfce_release} (deutsch, ohne LIPNSA)" {
-            set cmdline="debian-installer/locale=de_DE console-setup/layoutcode=de fnord"
-            xfce_LoadCasper
-    }
-
-    menuentry "${xfce_release} (english, without LIPNSA)" {
-            set cmdline="fnord"
-            xfce_LoadCasper
-    }
-}
-
-set kde_release="__KDE_RELEASE__"
-set kde_isoname="__KDE_ISONAME__"
-kde_menu
-
-set xfce_release="__XFCE_RELEASE__"
-set xfce_isoname="__XFCE_ISONAME__"
-xfce_menu
+#TEMPLATE img_menu "__RELEASE__" "__ISONAME__" "__KERNEL__" "__INITRD__"
 
 menuentry "Show bootflags" {
     cat "/bootflags.txt"
     read
-}
\ No newline at end of file
+}
diff --git a/packages b/packages
index d3794d2..4c82aaf 100644
--- a/packages
+++ b/packages
@@ -43,8 +43,8 @@ L    |ubiquity|
 
 #Desktop stuff for Kubuntu
  C   |thunderbird|Thunderbird: E-Mail-Client
- c   |kile|kile: Graphischer LaTeX-Editor
- C   |texstudio|texstudio: Schlankerer graphischer LaTeX-Editor
+ C   |texstudio|texstudio: Graphischer LaTeX-Editor
+ c   |kile|kile: Alternativer graphischer LaTeX-Editor
  D   |ffmpeg|
  D   |hunspell|
  D   |vlc|
@@ -73,8 +73,6 @@ LD   |vim|
 LD   |htop|
 LD   |git|
 LD   |gparted|
-# libcurl4 is not installed in Xubuntu in the installed system.
- D   |libcurl4|
 
 #texlive
  C   |texlive-lang-english texlive-bibtex-extra tipa texlive-latex-extra texlive-xetex texlive-latex-base chktex texlive-latex-recommended texlive-lang-german texlive-fonts-recommended psutils texlive-extra-utils texlive-font-utils latexmk texlive-pstricks feynmf texlive-science texlive-pictures texlive-metapost latexdiff tex-gyre texlive-publishers texlive-base lmodern texlive-luatex texlive-binaries|LaTeX mit vielen Paketen für wissenschaftliche Arbeiten
-- 
GitLab