docs: add generation of the base tar.gz to the FAQ
[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-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-common_"${GRUB}"_${ARCH}.deb
37 fi
38
39 if ! [ -f "grub-pc_${GRUB}_${ARCH}.deb" ] || ! [ -f "grub-common_${GRUB}_${ARCH}.deb" ]  ; then
40   echo "Error reading grub files version $GRUB - exiting.">&2
41   exit 1
42 fi
43
44 GRUBDIR=$(mktemp -d)
45 echo "Using temporary directory $GRUBDIR"
46 cd "$GRUBDIR"
47
48 mkdir -p grub
49
50 ar x "${oldpwd}"/"grub-pc_${GRUB}_${ARCH}.deb"
51 tar xzf data.tar.gz
52 ar x "${oldpwd}"/"grub-common_${GRUB}_${ARCH}.deb"
53 tar xzf data.tar.gz
54
55 if ./usr/bin/grub-mkimage --help | grep -q -- --format ; then
56   ./usr/bin/grub-mkimage -d usr/lib/grub/*-pc -o core.img biosdisk iso9660 --format=i386-pc
57 else
58   ./usr/bin/grub-mkimage -d usr/lib/grub/*-pc -o core.img biosdisk iso9660
59 fi
60
61 for a in usr/lib/grub/*-pc/{*.mod,efiemu??.o,command.lst,moddep.lst,fs.lst,handler.lst,parttool.lst}; do \
62   [[ -e $a ]] && cp $a grub/
63 done
64
65 mv core.img grub/
66
67 cd "$oldpwd"
68 mv "${GRUBDIR}"/grub .
69 rm -rf "$GRUBDIR"
70
71 echo "Generated new grub boot directory 'grub'."
72
73 ## END OF FILE #################################################################