From 24fbdd0aa2dddd72016a0608ba23b178dd995509 Mon Sep 17 00:00:00 2001
From: Andreas Loibl <andreas@andreas-loibl.de>
Date: Thu, 16 Feb 2012 09:47:01 +0100
Subject: added gfxoverlay auto script

---
 auto/kanotix                          | 10 ++++++++++
 build_gfxoverlay.sh                   |  6 +++---
 config/binary_local-hooks/gfxoverlays | 20 ++++++++++++++++++++
 config/gfxoverlays/versions           |  4 ++++
 4 files changed, 37 insertions(+), 3 deletions(-)
 create mode 100755 config/binary_local-hooks/gfxoverlays
 create mode 100644 config/gfxoverlays/versions

diff --git a/auto/kanotix b/auto/kanotix
index 8588976..aee291f 100755
--- a/auto/kanotix
+++ b/auto/kanotix
@@ -10,6 +10,7 @@ Additional Options for Kanotix:
 	    [--include-nvidia true|false]
 	    [--tmpfs true|false]
 	    [--tmpfs-options OPTIONS]
+	    [--gfxoverlays true|false]
 
 eof
 }
@@ -21,6 +22,7 @@ write_kanotix_config()
 [ -z "${LB_KANOTIX_TMPFS}" ] && LB_KANOTIX_TMPFS="false"
 [ -z "${LB_KANOTIX_TMPFS_OPTIONS}" ] && [ -f tmpfs/options ] && LB_KANOTIX_TMPFS_OPTIONS="$(<tmpfs/options)"
 [ -z "${LB_KANOTIX_TMPFS_OPTIONS}" ] && LB_KANOTIX_TMPFS_OPTIONS="defaults"
+[ -z "${LB_KANOTIX_GFXOVERLAYS}" ] && LB_KANOTIX_GFXOVERLAYS="false"
 cat >config/kanotix << EOF
 # config/kanotix - additional options for Kanotix
 
@@ -36,6 +38,10 @@ LB_KANOTIX_TMPFS="${LB_KANOTIX_TMPFS}"
 # (Default: ${LB_KANOTIX_TMPFS_OPTIONS})
 LB_KANOTIX_TMPFS_OPTIONS="${LB_KANOTIX_TMPFS_OPTIONS}"
 
+# \$LB_KANOTIX_GFXOVERLAYS: automatically build gfxoverlays and include them into binary
+# (Default: ${LB_KANOTIX_GFXOVERLAYS})
+LB_KANOTIX_GFXOVERLAYS="${LB_KANOTIX_GFXOVERLAYS}"
+
 EOF
 grep -q ". config/kanotix" config/all 2>/dev/null || echo ". config/kanotix" >> config/all
 }
@@ -57,6 +63,10 @@ do
 		LB_KANOTIX_TMPFS_OPTIONS="$2"
 		shift
 		;;
+	--gfxoverlays)
+		LB_KANOTIX_GFXOVERLAYS="$2"
+		shift
+		;;
         --help|-h)
 		lb config noauto --help
                 usage
diff --git a/build_gfxoverlay.sh b/build_gfxoverlay.sh
index 69212dd..6b8632d 100755
--- a/build_gfxoverlay.sh
+++ b/build_gfxoverlay.sh
@@ -22,8 +22,8 @@ if [ ! -x chroot/bin/bash ]; then
   exit 4
 fi
 bit="$(file chroot/bin/true | grep -q 'ELF 64-bit' && echo 64 || echo 32)"
-if [ -d "overlay$bit-$drv-$ver" -a -z "$OVERWRITE" ]; then
-  echo "Error: overlay \"overlay$bit-$drv-$ver\" already exists."
+if [ -d "${CACHE}overlay$bit-$drv-$ver" -a -z "$OVERWRITE" ]; then
+  echo "Error: overlay \"${CACHE}overlay$bit-$drv-$ver\" already exists."
   exit 5
 fi
 mkdir -p overlay root
@@ -90,5 +90,5 @@ rm -rf usr/sbin/update-initramfs etc/resolv.conf usr/src/NVIDIA-Linux* usr/src/a
 rm -f etc/X11/xorg.conf.1st
 printf 'Section "Device"\n    Identifier     "Device0"\n    Driver         "'"$drv"'"\nEndSection\n' > etc/X11/xorg.conf
 cd ..
-mv overlay "overlay$bit-$drv-$ver"
+mv overlay "${CACHE}overlay$bit-$drv-$ver"
 
diff --git a/config/binary_local-hooks/gfxoverlays b/config/binary_local-hooks/gfxoverlays
new file mode 100755
index 0000000..4341113
--- /dev/null
+++ b/config/binary_local-hooks/gfxoverlays
@@ -0,0 +1,20 @@
+#!/bin/bash
+[ -e config/gfxoverlays/versions ] || exit 0
+. config/kanotix
+[ "$LB_KANOTIX_GFXOVERLAYS" = "true" ] || exit 0
+export CACHE=cache/gfxoverlays/
+mkdir -p $CACHE
+bit="$(file chroot/bin/true | grep -q 'ELF 64-bit' && echo 64 || echo 32)"
+UPDATE=
+DIRS=
+while read drv ver
+do
+./build_gfxoverlay.sh $drv $ver && UPDATE=1
+DIRS+="${CACHE}overlay$bit-$drv-$ver "
+done < <(cut -d'#' -f1 config/gfxoverlays/versions | grep .)
+if [ ! -e "$CACHE/overlay.$bit.squashfs" -o "$UPDATE" ]; then
+        rm -f "$CACHE/overlay.$bit.squashfs"
+        mksquashfs $DIRS "$CACHE/overlay.$bit.squashfs"
+fi
+mkdir -p binary/gfxoverlay
+cp "$CACHE/overlay.$bit.squashfs" binary/gfxoverlay/
diff --git a/config/gfxoverlays/versions b/config/gfxoverlays/versions
new file mode 100644
index 0000000..90c8ea2
--- /dev/null
+++ b/config/gfxoverlays/versions
@@ -0,0 +1,4 @@
+nvidia 295.17
+nvidia 96.43.20
+nvidia 173.14.31
+fglrx 12-1
-- 
cgit v1.0