From f40a33d0da0c3a3e58f27c02b0959b1d43bb25d1 Mon Sep 17 00:00:00 2001
From: Andreas Loibl <andreas@andreas-loibl.de>
Date: Thu, 1 Mar 2012 14:30:15 +0100
Subject: included live-build patches into local tree to make it build with
 unpatched live-build

---
 auto/functions/compat                       |  6 +--
 auto/functions/livebuild-hacks              | 76 +++++++++++++++++++++++++++++
 config/binary_local-hooks/grub2-configs     | 17 +++++++
 config/binary_local-hooks/isohybrid-acritox | 18 +++++++
 config/chroot_local-hooks/07-dkms           |  4 +-
 5 files changed, 116 insertions(+), 5 deletions(-)
 create mode 100644 auto/functions/livebuild-hacks
 create mode 100755 config/binary_local-hooks/grub2-configs
 create mode 100755 config/binary_local-hooks/isohybrid-acritox

diff --git a/auto/functions/compat b/auto/functions/compat
index 061562b..a524c28 100644
--- a/auto/functions/compat
+++ b/auto/functions/compat
@@ -22,13 +22,13 @@ Compat_arguments ()
 
 Compat_config ()
 {
-[ -e config/chroot ] && cat <<eof >> config/chroot
+[ -e config/chroot ] && [ "$LB_ARCHIVES" ] && cat <<eof >> config/chroot
 
 # Compat (Live-build 2 -> 3)
 LB_REPOSITORIES="$LB_ARCHIVES"
 LB_PACKAGES_LISTS="$LB_PACKAGE_LISTS"
 eof
-[ -e config/bootstrap ] && cat <<eof >> config/bootstrap
+[ -e config/bootstrap ] && [ "$LB_ARCHITECTURES" ] && cat <<eof >> config/bootstrap
 
 # Compat (Live-build 2 -> 3)
 LB_ARCHITECTURE="$LB_ARCHITECTURES"
@@ -116,7 +116,7 @@ case "$LB_VERSION" in
 		Compat_dir chroot_local-hooks hooks - .chroot
 		;;
 	lb_binary_hooks)
-		Compat_dir chroot_binary-hooks hooks - .binary
+		Compat_dir binary_local-hooks hooks - .binary
 		;;
 	lb_build|lb_clean)
 		trap Compat_clean EXIT
diff --git a/auto/functions/livebuild-hacks b/auto/functions/livebuild-hacks
new file mode 100644
index 0000000..7df44df
--- /dev/null
+++ b/auto/functions/livebuild-hacks
@@ -0,0 +1,76 @@
+#!/bin/sh
+# Hacks to inject code into various live-build functions
+
+# ISO sorting
+if [ "$(basename "$0")" = "lb_binary_iso" ]; then
+	echo "HOOK: livebuild-hacks@binary_iso"
+	In_list ()
+	{
+		. "${LB_BASE}"/functions/aliases.sh
+		In_list "$@"
+		RC=$?
+		if [ -f config/binary_iso/isoimage.sort ]
+		then
+			GENISOIMAGE_OPTIONS="${GENISOIMAGE_OPTIONS} -sort isoimage.sort"
+
+			case "${LB_BUILD_WITH_CHROOT}" in
+				true)
+					cp config/binary_iso/isoimage.sort chroot
+					;;
+
+				false)
+					cp config/binary_iso/isoimage.sort .
+					;;
+			esac
+		fi
+		case "$LB_BOOTLOADER" in
+		grub2|burg)
+			LB_BINARY_IMAGES=iso
+			;;
+		esac
+		return $rc
+	}
+fi
+
+# Grub2: Do not number the default kernel / initrd files.
+if [ "$(basename "$0")" = "lb_binary_grub2" ]; then
+	echo "HOOK: livebuild-hacks@binary_grub2"
+	Grub_live_entry ()
+	{
+		LABEL="${1}"
+		KERNEL="${2}"
+		INITRD="${3}"
+		APPEND="${4}"
+
+		case "${LB_BINARY_IMAGES}" in
+			iso*|usb*)
+				if [ "${LABEL}" = "live" ]
+				then
+					# Do not number the default kernel / initrd files.
+					_NUMBER=""
+				else
+					# Use order of flavours in LB_LINUX_FLAVOURS for numbering.
+					_NUMBER="$(echo ${LB_LINUX_FLAVOURS} | awk -v FLAVOUR="${FLAVOUR}" 'BEGIN{RS=" "} {if($1 == FLAVOUR) print NR}')"
+				fi
+
+				if [ -e binary/${KERNEL} ]
+				then
+					mv binary/${KERNEL} "binary/$(dirname ${KERNEL})/vmlinuz${_NUMBER}" | :
+					KERNEL="$(dirname ${KERNEL})/vmlinuz${_NUMBER}"
+				fi
+
+				if [ -e binary/${INITRD} ]
+				then
+					mv binary/${INITRD} "binary/$(dirname ${INITRD})/initrd${_NUMBER}.img" | :
+					INITRD="$(dirname ${INITRD})/initrd${_NUMBER}.img"
+				fi
+			;;
+		esac
+
+		LINUX_LIVE="${LINUX_LIVE}\nmenuentry \"Debian GNU/Linux - ${LABEL}\" {"
+		LINUX_LIVE="${LINUX_LIVE}\nlinux\t\t/${KERNEL} boot=${INITFS} config LB_BOOTAPPEND_LIVE ${APPEND}"
+		LINUX_LIVE="${LINUX_LIVE}\ninitrd\t\t/${INITRD}"
+		LINUX_LIVE="${LINUX_LIVE}\n}"
+	}
+fi
+
diff --git a/config/binary_local-hooks/grub2-configs b/config/binary_local-hooks/grub2-configs
new file mode 100755
index 0000000..7cd30ef
--- /dev/null
+++ b/config/binary_local-hooks/grub2-configs
@@ -0,0 +1,17 @@
+#!/bin/sh
+# Copying local grub2 configuration files
+
+case "$LB_BOOTLOADER" in
+grub2|burg)
+	;;
+*)
+	exit 0
+	;;
+esac
+
+if [ -f config/binary_grub/grub.cfg ]
+then
+	mkdir -p binary/boot/grub
+        cp config/binary_grub/grub*.cfg binary/boot/grub/
+fi
+
diff --git a/config/binary_local-hooks/isohybrid-acritox b/config/binary_local-hooks/isohybrid-acritox
new file mode 100755
index 0000000..e7c2931
--- /dev/null
+++ b/config/binary_local-hooks/isohybrid-acritox
@@ -0,0 +1,18 @@
+#!/bin/bash
+# generate binary/boot.isohybrid for isohybrid-acritox
+
+[ "${LB_BINARY_IMAGES}" = "iso-hybrid" ] || exit 0
+
+case "$LB_BOOTLOADER" in
+grub2|burg)
+	;;
+*)
+	exit 0
+	;;
+esac
+
+chroot chroot grub-mkimage -d /usr/lib/grub/i386-pc -o "/boot.isohybrid" -O i386-pc biosdisk iso9660
+for i in $(seq 64); do echo -n "ACRITOX!"; done > binary/boot.isohybrid
+cat chroot/boot.isohybrid >> binary/boot.isohybrid
+rm -f chroot/boot.isohybrid
+
diff --git a/config/chroot_local-hooks/07-dkms b/config/chroot_local-hooks/07-dkms
index a0ed316..8f57d16 100755
--- a/config/chroot_local-hooks/07-dkms
+++ b/config/chroot_local-hooks/07-dkms
@@ -1,2 +1,2 @@
-#!/bin/sh
-for x in $(ls /boot/vmlinuz-*|sed s@/boot/vmlinuz-@@);do /usr/lib/dkms/dkms_autoinstaller start $x; done
+#!/bin/bash
+for x in /boot/vmlinuz-*;do KVERS=$x /usr/lib/dkms/dkms_autoinstaller start ${x#/boot/vmlinuz-}; done
-- 
cgit v1.0