]> git.proxmox.com Git - grub2.git/blame - tests/util/grub-shell.in
* tests/util/grub-shell.in: Set pkgdatadir when calling grub-mkrescue
[grub2.git] / tests / util / grub-shell.in
CommitLineData
5626056f
CW
1#! /bin/sh
2set -e
6fc804ff
BC
3
4# Run GRUB script in a Qemu instance
547e494f 5# Copyright (C) 2009,2010 Free Software Foundation, Inc.
6fc804ff
BC
6#
7# GRUB is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# GRUB is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19
20# Initialize some variables.
21transform="@program_transform_name@"
22
48b391e9
VS
23prefix="@prefix@"
24exec_prefix="@exec_prefix@"
25datarootdir="@datarootdir@"
26builddir="@builddir@"
6fc804ff
BC
27PACKAGE_NAME=@PACKAGE_NAME@
28PACKAGE_TARNAME=@PACKAGE_TARNAME@
29PACKAGE_VERSION=@PACKAGE_VERSION@
6fc804ff
BC
30
31# Force build directory components
48b391e9 32PATH="${builddir}:$PATH"
6fc804ff
BC
33export PATH
34
35# Usage: usage
36# Print the usage.
37usage () {
38 cat <<EOF
39Usage: $0 [OPTION] [SOURCE]
40Run GRUB script in a Qemu instance.
41
42 -h, --help print this message and exit
43 -v, --version print the version information and exit
8395034b 44 --boot=[fd|hd|cd|net] boot method for Qemu instance
6fc804ff 45 --modules=MODULES pre-load specified modules MODULES
ad8e99ec 46 --qemu=FILE Name of qemu binary
6fc804ff 47 --qemu-opts=OPTIONS extra options to pass to Qemu instance
ad8e99ec 48 --files=FILES add files to the image
6fc804ff
BC
49
50$0 runs input GRUB script or SOURCE file in a Qemu instance and prints
51its output.
52
53Report bugs to <bug-grub@gnu.org>.
54EOF
55}
56
7fec686e 57boot=hd
ad8e99ec
VS
58qemu=qemu-system-i386
59
6fc804ff
BC
60# Check the arguments.
61for option in "$@"; do
62 case "$option" in
63 -h | --help)
64 usage
65 exit 0 ;;
66 -v | --version)
67 echo "$0 (GNU GRUB ${PACKAGE_VERSION})"
68 exit 0 ;;
69 --modules=*)
70 ms=`echo "$option" | sed -e 's/--modules=//' -e 's/,/ /g'`
71 modules="$modules $ms" ;;
ad8e99ec
VS
72 --files=*)
73 fls=`echo "$option" | sed -e 's/--files=//' -e 's/,/ /g'`
74 files="$files $fls" ;;
75 --qemu=*)
76 qemu=`echo "$option" | sed -e 's/--qemu=//' -e 's/,/ /g'`;;
6fc804ff
BC
77 --qemu-opts=*)
78 qs=`echo "$option" | sed -e 's/--qemu-opts=//'`
79 qemuopts="$qemuopts $qs" ;;
afafb37e
BC
80 --boot=*)
81 dev=`echo "$option" | sed -e 's/--boot=//'`
7fec686e
VS
82 if [ "$dev" = "fd" ] ; then boot=fd;
83 elif [ "$dev" = "hd" ] ; then boot=hd;
84 elif [ "$dev" = "cd" ] ; then boot=cd;
8395034b 85 elif [ "$dev" = "net" ] ; then boot=net;
aa8d7b26
VS
86 elif [ "$dev" = "qemu" ] ; then boot=qemu;
87 elif [ "$dev" = "coreboot" ] ; then boot=coreboot;
afafb37e
BC
88 else
89 echo "Unrecognized boot method \`$dev'" 1>&2
90 usage
91 exit 1
92 fi ;;
6fc804ff
BC
93 -*)
94 echo "Unrecognized option \`$option'" 1>&2
95 usage
afafb37e 96 exit 1 ;;
6fc804ff
BC
97 *)
98 if [ "x${source}" != x ] ; then
99 echo "too many parameters at the end" 1>&2
100 usage
101 exit 1
102 fi
103 source="${option}" ;;
104 esac
105done
106
107if [ "x${source}" = x ] ; then
b65ea155 108 tmpfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
becce1b1 109 while read REPLY; do
64550500 110 echo "$REPLY" >> ${tmpfile}
afafb37e
BC
111 done
112 source=${tmpfile}
113fi
114
b65ea155 115cfgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
6fc804ff
BC
116cat <<EOF >${cfgfile}
117grubshell=yes
118insmod serial
119serial
415502c2 120terminfo serial dumb
6fc804ff
BC
121terminal_input serial
122terminal_output serial
123EOF
124
b65ea155 125rom_directory=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
aa8d7b26 126
6fc804ff
BC
127for mod in ${modules}
128do
afafb37e 129 echo "insmod ${mod}" >> ${cfgfile}
6fc804ff
BC
130done
131
132cat <<EOF >>${cfgfile}
133source /boot/grub/testcase.cfg
ab66c69f
JU
134# Stop serial output to suppress "ACPI shutdown failed" error.
135terminal_output console
6fc804ff
BC
136halt
137EOF
138
b65ea155 139isofile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
8395034b 140if [ x$boot != xnet ]; then
16fc9293 141 pkgdatadir="@builddir@" sh "@builddir@/grub-mkrescue" "--grub-mkimage=${builddir}/grub-mkimage" "--output=${isofile}" "--override-directory=${builddir}/grub-core" \
8395034b 142 --rom-directory="${rom_directory}" \
48b391e9 143 "/boot/grub/grub.cfg=${cfgfile}" "/boot/grub/testcase.cfg=${source}" \
8395034b
VS
144 ${files} >/dev/null 2>&1
145fi
7fec686e
VS
146if [ x$boot = xhd ]; then
147 device=hda
aa8d7b26 148 bootdev="-boot c"
ad8e99ec 149fi
7fec686e
VS
150if [ x$boot = xcd ]; then
151 device=cdrom
aa8d7b26 152 bootdev="-boot d"
7fec686e
VS
153fi
154if [ x$boot = xfd ]; then
155 device=fda
aa8d7b26
VS
156 bootdev="-boot a"
157fi
afafb37e 158
aa8d7b26
VS
159if [ x$boot = xqemu ]; then
160 bootdev="-bios ${rom_directory}/qemu.img"
161 device=cdrom
7fec686e 162fi
afafb37e 163
aa8d7b26 164if [ x$boot = xcoreboot ]; then
b65ea155 165 imgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
aa8d7b26
VS
166 cp "${GRUB_COREBOOT_ROM}" "${imgfile}"
167 "${GRUB_CBFSTOOL}" "${imgfile}" add-payload "${rom_directory}/coreboot.elf" fallback/payload
168 bootdev="-bios ${imgfile}"
169 device=cdrom
170fi
6fc804ff 171
8395034b 172if [ x$boot = xnet ]; then
b65ea155 173 netdir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
16fc9293 174 pkgdatadir="@builddir@" sh "@builddir@/grub-mknetdir" "--grub-mkimage=${builddir}/grub-mkimage" "--override-directory=${builddir}/grub-core" "--net-directory=$netdir"
48b391e9
VS
175 cp "${cfgfile}" "$netdir/boot/grub/grub.cfg"
176 cp "${source}" "$netdir/boot/grub/testcase.cfg"
53f13848
VS
177 . "${builddir}/grub-core/modinfo.sh"
178 "${qemu}" ${qemuopts} -nographic -serial file:/dev/stdout -monitor file:/dev/null -boot n -net "user,tftp=$netdir,bootfile=/boot/grub/${grub_modinfo_target_cpu}-${grub_modinfo_platform}/core.0" -net nic | cat | tr -d "\r"
8395034b 179else
48b391e9 180 "${qemu}" ${qemuopts} -nographic -serial file:/dev/stdout -monitor file:/dev/null -${device} ${isofile} ${bootdev} | cat | tr -d "\r"
8395034b 181fi
aa8d7b26
VS
182rm -f "${isofile}" "${imgfile}"
183rm -rf "${rom_directory}"
184if [ x$boot = xcoreboot ]; then
185 rm -f "${imgfile}"
186fi
6fc804ff 187
aa8d7b26 188rm -f "${tmpfile}" "${cfgfile}"
6fc804ff
BC
189exit 0
190
191