0f3691c8b2ea4d8dad54d2d08d4f28bd586b1382
[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
10 set -e
11
12 if [ -z "$1" ] ; then
13   echo "Usage: $0 <grub_package.deb>">&2
14   echo "Usage example: $0 grub-pc_1.98-1_i386.deb">&2
15   exit 1
16 fi
17
18 if [ -d grub ] ; then
19   echo "Directory 'grub' exists in current working directory already, will not continue.">&2
20   exit 1
21 fi
22
23 GRUB="$1"
24 oldpwd=$(pwd)
25
26 if ! [ -f "$GRUB" ] ; then
27   wget http://ftp.de.debian.org/debian/pool/main/g/grub2/"$GRUB"
28 fi
29
30 if ! [ -f "$GRUB" ] ; then
31   echo "Error reading $GRUB - exiting.">&2
32   exit 1
33 fi
34
35 GRUBDIR=$(mktemp -d)
36 cd "$GRUBDIR"
37
38 mkdir -p grub
39
40 ar x "${oldpwd}"/"$GRUB"
41 tar xzf data.tar.gz
42 ./usr/bin/grub-mkimage -d usr/lib/grub/i386-pc -o core.img biosdisk iso9660
43
44 for a in usr/lib/grub/i386-pc/{*.mod,efiemu??.o,command.lst,moddep.lst,fs.lst,handler.lst,parttool.lst}; do \
45   [[ -e $a ]] && cp $a grub/
46 done
47
48 mv core.img grub/
49
50 cd "$oldpwd"
51 mv "${GRUBDIR}"/grub .
52 rm -rf "$GRUBDIR"
53
54 echo "Generated new grub boot directory 'grub'."
55
56 ## END OF FILE #################################################################