Also export the proxy for https usage
[ext/instance-debootstrap.git] / examples / hooks / grub
1 #!/bin/bash
2 #
3 # This is an example script that install and configure grub after installation.
4 # To use it put it in your CUSTOMIZE_DIR and make it executable.
5 #
6 # Do not include grub in EXTRA_PKGS of
7 # $sysconfdir/default/ganeti-instance-debootstrap because it will
8 # cause error of debootstrap.
9
10 set -e
11
12 . common.sh
13
14 CLEANUP=( )
15
16 trap cleanup EXIT
17
18 if [ -z "$TARGET" -o ! -d "$TARGET" ]; then
19   echo "Missing target directory"
20   exit 1
21 fi
22
23 # install grub
24 export LANG=C
25 if [ "$PROXY" ]; then
26   export http_proxy="$PROXY"
27   export https_proxy="$PROXY"
28 fi
29 export DEBIAN_FRONTEND=noninteractive
30 chroot "$TARGET" apt-get -y --force-yes install grub grub-common
31
32 # make /dev/sda
33 mknod $TARGET/dev/sda b $(stat -L -c "0x%t 0x%T" $BLOCKDEV)
34 CLEANUP+=("rm -f $TARGET/dev/sda")
35
36 # make /dev/sda1
37 mknod $TARGET/dev/sda1 b $(stat -L -c "0x%t 0x%T" $FSYSDEV)
38 CLEANUP+=("rm -f $TARGET/dev/sda1")
39
40 # create grub directory
41 mkdir -p "$TARGET/boot/grub"
42
43 # create device.map
44 cat > "$TARGET/boot/grub/device.map" <<EOF
45 (hd0) /dev/sda
46 EOF
47
48 # execute update-grub
49 chroot "$TARGET" update-grub
50
51 # install grub to the block device
52 grub-install --no-floppy --root-directory="$TARGET" "$BLOCKDEV"
53
54 # execute cleanups
55 cleanup
56 trap - EXIT
57
58 exit 0