grml-cheatcodes.txt: update documentation regarding fetch= bootoption (supports DNS...
[grml-live.git] / scripts / create-grub-dir.sh
index 0f3691c..681b0c0 100755 (executable)
@@ -6,12 +6,18 @@
 # License:       This file is licensed under the GPL v2 or any later version.
 # Latest change: Thu Mar 11 14:25:15 CET 2010 [mika]
 ################################################################################
+# This script is very hackish due to the way the grub directory has to be
+# generated. :-/ The script is meant to be executed on a Debian system that
+# matches the grub version, otherwise the execution of grub-mkimage *might* fail.
+# So if you want to use a recent Grub version make sure you execute this script
+# on an up2date Debian/unstable system.
+################################################################################
 
 set -e
 
 if [ -z "$1" ] ; then
-  echo "Usage: $0 <grub_package.deb>">&2
-  echo "Usage example: $0 grub-pc_1.98-1_i386.deb">&2
+  echo "Usage: $0 <grub-version>">&2
+  echo "Usage example: $0 1.98-1">&2
   exit 1
 fi
 
@@ -23,25 +29,36 @@ fi
 GRUB="$1"
 oldpwd=$(pwd)
 
-if ! [ -f "$GRUB" ] ; then
-  wget http://ftp.de.debian.org/debian/pool/main/g/grub2/"$GRUB"
+ARCH=$(dpkg --print-architecture)
+
+if ! [ -f "grub-pc_${GRUB}_${ARCH}.deb" ] || ! [ -f "grub-common_${GRUB}_${ARCH}.deb" ]  ; then
+  wget http://cdn.debian.net/debian/pool/main/g/grub2/grub-pc_"${GRUB}"_${ARCH}.deb
+  wget http://cdn.debian.net/debian/pool/main/g/grub2/grub-common_"${GRUB}"_${ARCH}.deb
 fi
 
-if ! [ -f "$GRUB" ] ; then
-  echo "Error reading $GRUB - exiting.">&2
+if ! [ -f "grub-pc_${GRUB}_${ARCH}.deb" ] || ! [ -f "grub-common_${GRUB}_${ARCH}.deb" ]  ; then
+  echo "Error reading grub files version $GRUB - exiting.">&2
   exit 1
 fi
 
 GRUBDIR=$(mktemp -d)
+echo "Using temporary directory $GRUBDIR"
 cd "$GRUBDIR"
 
 mkdir -p grub
 
-ar x "${oldpwd}"/"$GRUB"
+ar x "${oldpwd}"/"grub-pc_${GRUB}_${ARCH}.deb"
+tar xzf data.tar.gz
+ar x "${oldpwd}"/"grub-common_${GRUB}_${ARCH}.deb"
 tar xzf data.tar.gz
-./usr/bin/grub-mkimage -d usr/lib/grub/i386-pc -o core.img biosdisk iso9660
 
-for a in usr/lib/grub/i386-pc/{*.mod,efiemu??.o,command.lst,moddep.lst,fs.lst,handler.lst,parttool.lst}; do \
+if ./usr/bin/grub-mkimage --help | grep -q -- --format ; then
+  ./usr/bin/grub-mkimage -d usr/lib/grub/*-pc -o core.img biosdisk iso9660 --format=i386-pc
+else
+  ./usr/bin/grub-mkimage -d usr/lib/grub/*-pc -o core.img biosdisk iso9660
+fi
+
+for a in usr/lib/grub/*-pc/{*.mod,efiemu??.o,command.lst,moddep.lst,fs.lst,handler.lst,parttool.lst}; do \
   [[ -e $a ]] && cp $a grub/
 done