1de8f73287c8672ab7aa402e53b9566ac7690a06
[grml-live.git] / scripts / create-grub-dir.sh
1 #!/bin/bash
2 # Filename:      create-grub-dir.sh
3 # Purpose:       generate core.img and according files for templates/boot/grub/
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 # Latest change: Thu Mar 11 14:25:15 CET 2010 [mika]
8 ################################################################################
9 # This script is very hackish due to the way the grub directory has to be
10 # generated. :-/ The script is meant to be executed on a Debian system that
11 # matches the grub version, otherwise the execution of grub-mkimage *might* fail.
12 # So if you want to use a recent Grub version make sure you execute this script
13 # on an up2date Debian/unstable system.
14 ################################################################################
15
16 set -e
17
18 if [ -z "$1" ] ; then
19   echo "Usage: $0 <grub-version>">&2
20   echo "Usage example: $0 1.98-1">&2
21   exit 1
22 fi
23
24 if [ -d grub ] ; then
25   echo "Directory 'grub' exists in current working directory already, will not continue.">&2
26   exit 1
27 fi
28
29 GRUB="$1"
30 oldpwd=$(pwd)
31
32 ARCH=$(dpkg --print-architecture)
33
34 if ! [ -f "grub-pc_${GRUB}_${ARCH}.deb" ] || ! [ -f "grub-pc-bin_${GRUB}_${ARCH}.deb" ] || ! [ -f "grub-common_${GRUB}_${ARCH}.deb" ]  ; then
35   wget http://cdn.debian.net/debian/pool/main/g/grub2/grub-pc_"${GRUB}"_${ARCH}.deb
36   wget http://cdn.debian.net/debian/pool/main/g/grub2/grub-pc-bin_"${GRUB}"_${ARCH}.deb
37   wget http://cdn.debian.net/debian/pool/main/g/grub2/grub-common_"${GRUB}"_${ARCH}.deb
38 fi
39
40 if ! [ -f "grub-pc_${GRUB}_${ARCH}.deb" ] || ! [ -f "grub-pc-bin_${GRUB}_${ARCH}.deb" ] || ! [ -f "grub-common_${GRUB}_${ARCH}.deb" ]  ; then
41   echo "Error reading grub files version $GRUB - exiting.">&2
42   exit 1
43 fi
44
45 GRUBDIR=$(mktemp -d)
46 echo "Using temporary directory $GRUBDIR"
47 cd "$GRUBDIR"
48
49 mkdir -p grub
50
51 ar x "${oldpwd}"/"grub-pc_${GRUB}_${ARCH}.deb"
52 tar xzf data.tar.gz
53 ar x "${oldpwd}"/"grub-pc-bin_${GRUB}_${ARCH}.deb"
54 tar xzf data.tar.gz
55 ar x "${oldpwd}"/"grub-common_${GRUB}_${ARCH}.deb"
56 tar xzf data.tar.gz
57
58 if ./usr/bin/grub-mkimage --help | grep -q -- --format ; then
59   ./usr/bin/grub-mkimage -d usr/lib/grub/*-pc -o core.img biosdisk iso9660 --format=i386-pc
60 else
61   ./usr/bin/grub-mkimage -d usr/lib/grub/*-pc -o core.img biosdisk iso9660
62 fi
63
64 for a in usr/lib/grub/*-pc/{*.mod,efiemu??.o,command.lst,moddep.lst,fs.lst,handler.lst,parttool.lst}; do \
65   [[ -e $a ]] && cp $a grub/
66 done
67
68 mv core.img grub/
69
70 cd "$oldpwd"
71 mv "${GRUBDIR}"/grub .
72 rm -rf "$GRUBDIR"
73
74 echo "Generated new grub boot directory 'grub'."
75
76 ## END OF FILE #################################################################