grub_config.sh 1.38 KB
Newer Older
OSAK Buildhauer's avatar
OSAK Buildhauer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!/bin/bash

function extract_kernel() {
	iso_file="$1"
	loopback="$(mktemp)"
	7z e -so "$iso_file" boot/grub/loopback.cfg > "$loopback"
	grep -m 1 -o "linux.*vmlinuz" "$loopback" | awk '{ print $2 }'
	rm "$loopback"
}

function extract_initrd() {
	iso_file="$1"
	loopback="$(mktemp)"
	7z e -so "$iso_file" boot/grub/loopback.cfg > "$loopback"
	grep -m 1 -o "initrd.*initrd\S*" "$loopback" | awk '{ print $2 }'
	rm "$loopback"
}

function extract_release() {
	iso_file="$1"
	flavor="$(echo "$iso_file" | cut -d "-" -f 1)"
	number="$(echo "$iso_file" | cut -d "-" -f 2)"
	echo "${flavor^} $number" # ^ capitalizes 1st letter
}

OSAK Buildhauer's avatar
OSAK Buildhauer committed
26
function fill_grub_config_template() {
OSAK Buildhauer's avatar
OSAK Buildhauer committed
27 28 29 30 31 32 33 34 35
	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"
}

OSAK Buildhauer's avatar
OSAK Buildhauer committed
36 37 38 39 40
# 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"