~ubuntu-on-ec2/vmbuilder/automated-ec2-builds-fginther

« back to all changes in this revision

Viewing changes to live-config/cloud_local-hooks/04grub-probe

  • Committer: Ben Howard
  • Date: 2011-07-27 23:17:10 UTC
  • Revision ID: ben.howard@canonical.com-20110727231710-iv7naynricd0x5jk
Code-review for new build-lb-ec2-image changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
rootd="${1}"
 
3
set -x
 
4
GPROBE="/usr/sbin/grub-probe"
 
5
NEW_GPROBE="${GPROBE}.new"
 
6
OLD_GPROBE="${GPROBE}.old"
 
7
 
 
8
cat <<"PSUEDO_GRUB_PROBE" > ${NEW_GPROBE}
 
9
#!/bin/sh
 
10
Usage() {
 
11
   cat <<EOF
 
12
Usage: euca-psuedo-grub-probe
 
13
   this is a wrapper around grub-probe to provide the answers for an ec2 guest
 
14
EOF
 
15
}
 
16
bad_Usage() { Usage 1>&2; fail "$@"; }
 
17
 
 
18
short_opts=""
 
19
long_opts="device-map:,target:,device"
 
20
getopt_out=$(getopt --name "${0##*/}" \
 
21
   --options "${short_opts}" --long "${long_opts}" -- "$@") &&
 
22
   eval set -- "${getopt_out}" ||
 
23
   bad_Usage
 
24
 
 
25
device_map=""
 
26
target=""
 
27
device=0
 
28
arg=""
 
29
 
 
30
while [ $# -ne 0 ]; do
 
31
   cur=${1}; next=${2};
 
32
   case "$cur" in
 
33
      --device-map) device_map=${next}; shift;;
 
34
      --device) device=1;;
 
35
      --target) target=${next}; shift;;
 
36
      --) shift; break;;
 
37
   esac
 
38
   shift;
 
39
done
 
40
arg=${1}
 
41
 
 
42
case "${target}:${device}:${arg}" in
 
43
   device:*:/*) echo "/dev/sda1"; exit 0;;
 
44
   fs:*:*) echo "ext2"; exit 0;;
 
45
   partmap:*:*)
 
46
      # older versions of grub (lucid) want 'part_msdos' written
 
47
      # rather than 'msdos'
 
48
      legacy_pre=""
 
49
      grubver=$(dpkg-query --show --showformat '${Version}\n' grub-pc 2>/dev/null) &&
 
50
         dpkg --compare-versions "${grubver}" lt 1.98+20100804-5ubuntu3 &&
 
51
         legacy_pre="part_"
 
52
      echo "${legacy_pre}msdos";
 
53
      exit 0;;
 
54
   abstraction:*:*) echo ""; exit 0;;
 
55
   abstraction:*:*) echo ""; exit 0;;
 
56
   drive:*:/dev/sda) echo "(hd0)";;
 
57
   drive:*:/dev/sda*) echo "(hd0,1)";;
 
58
   fs_uuid:*:*) exit 1;;
 
59
esac
 
60
PSUEDO_GRUB_PROBE
 
61
 
 
62
set -x
 
63
 
 
64
mv ${GPROBE} ${OLD_GPROBE}
 
65
mv ${NEW_GPROBE} ${GPROBE}
 
66
chmod 755 "${GPROBE}"
 
67
 
 
68
# modify default linux command line for serial console output
 
69
# change GRUB_CMDLINE_LINUX_DEFAULT="quite splash"
 
70
# to GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0"
 
71
opt="GRUB_CMDLINE_LINUX_DEFAULT"
 
72
defstr="console=ttyS0"
 
73
sed -i "s/\(${opt}=\".*\"\)$/${opt}=\"${defstr}\"/" \
 
74
    "${rootd}/etc/default/grub"
 
75
 
 
76
# make the debconf values match those stored in /etc/default/grub
 
77
# above.  This means that the user isn't prompted for a merge on
 
78
# a dpkg-reconfigure grub-pc
 
79
printf "%s\t%s\t%s\t%s\n%s\t%s\t%s\t%s\n" \
 
80
    grub-pc grub2/linux_cmdline_default string "${defstr}" \
 
81
        grub-pc grub2/linux_cmdline string " " |
 
82
        sudo debconf-set-selections
 
83
 
 
84
 
 
85
sudo grub-install --grub-setup=/bin/true /dev/sda && /usr/sbin/update-grub
 
86
 
 
87
mv ${OLD_GPROBE} ${GPROBE}
 
88
 
 
89
set +x