]> git.proxmox.com Git - grub2.git/blame - util/grub-mknetdir.in
Initial integration of hints
[grub2.git] / util / grub-mknetdir.in
CommitLineData
8395034b
VS
1#! /bin/sh
2
3# Install GRUB on your drive.
4# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
5#
6# GRUB is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# GRUB is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
18
19# Initialize some variables.
20transform="@program_transform_name@"
21
22prefix=@prefix@
23exec_prefix=@exec_prefix@
24sbindir=@sbindir@
25bindir=@bindir@
26libdir=@libdir@
27PACKAGE_NAME=@PACKAGE_NAME@
28PACKAGE_TARNAME=@PACKAGE_TARNAME@
29PACKAGE_VERSION=@PACKAGE_VERSION@
8395034b 30host_os=@host_os@
8395034b 31localedir=@datadir@/locale
8395034b
VS
32pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst"
33
34self=`basename $0`
35
36grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
37rootdir=/srv/tftp
38grub_prefix=`echo /boot/grub | sed ${transform}`
39modules=
40
41install_device=
42no_floppy=
43recheck=no
44debug=no
45debug_image=
46subdir=`echo /boot/grub | sed ${transform}`
47pc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-pc
48
49# Usage: usage
50# Print the usage.
51usage () {
52 cat <<EOF
53Usage: $self [OPTION] install_device
54Install GRUB on your drive.
55
56 -h, --help print this message and exit
57 -v, --version print the version information and exit
58 --modules=MODULES pre-load specified modules MODULES
59 --net-directory=DIR root directory of TFTP server
60 --subdir=DIR relative subdirectory on network server
61 --grub-mkimage=FILE use FILE as grub-mkimage
62
6ad6223e 63$self copies GRUB images into net_directory/subdir/target_cpu-platform
8395034b
VS
64
65Report bugs to <bug-grub@gnu.org>.
66EOF
67}
68
69argument () {
70 opt=$1
71 shift
72
73 if test $# -eq 0; then
74 echo "$0: option requires an argument -- '$opt'" 1>&2
75 exit 1
76 fi
77 echo $1
78}
79
80# Check the arguments.
81while test $# -gt 0
82do
83 option=$1
84 shift
85
86 case "$option" in
87 -h | --help)
88 usage
89 exit 0 ;;
90 -v | --version)
91 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
92 exit 0 ;;
93
94 --modules)
95 modules=`argument $option "$@"`; shift;;
96 --modules=*)
97 modules=`echo "$option" | sed 's/--modules=//'` ;;
98
99 --net-directory)
100 rootdir=`argument $option "$@"`; shift;;
101 --net-directory=*)
102 rootdir=`echo "$option" | sed 's/--net-directory=//'` ;;
103
104 --subdir)
105 subdir=`argument $option "$@"`; shift;;
106 --subdir=*)
107 subdir=`echo "$option" | sed 's/--subdir=//'` ;;
108
109 --grub-mkimage)
110 grub_mkimage=`argument $option "$@"`; shift;;
111 --grub-mkimage=*)
112 grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
113
114 # This is an undocumented feature...
115 --debug)
116 debug=yes ;;
117 --debug-image)
118 debug_image=`argument $option "$@"`; shift;;
119 --debug-image=*)
120 debug_image=`echo "$option" | sed 's/--debug-image=//'` ;;
121
122 # Intentionally undocumented
123 --override-directory)
124 override_dir=`argument $option "$@"`
125 shift
126 PATH=${override_dir}:$PATH
127 export PATH
128 ;;
129 --override-directory=*)
130 override_dir=`echo "${option}/" | sed 's/--override-directory=//'`
131 PATH=${override_dir}:$PATH
132 export PATH
133 ;;
134
135 -*)
136 echo "Unrecognized option \`$option'" 1>&2
137 usage
138 exit 1
139 ;;
140 *)
141 if test "x$install_device" != x; then
142 echo "More than one install_devices?" 1>&2
143 usage
144 exit 1
145 fi
146 install_device="${option}" ;;
147 esac
148done
149
150set $grub_mkimage dummy
151if test -f "$1"; then
152 :
153else
154 echo "$1: Not found." 1>&2
155 exit 1
156fi
157
158# Create the GRUB directory if it is not present.
159mkdir -p "${rootdir}/${subdir}" || exit 1
160
161process_input_dir ()
162{
163 input_dir="$1"
164 platform="$2"
165 grubdir="${rootdir}/${subdir}/${platform}"
166 config_opt=
167 mkdir -p "$grubdir" || exit 1
168
169 for file in ${grubdir}/*.mod ${grubdir}/*.lst ${grubdir}/*.img ${grubdir}/efiemu??.o; do
170 if test -f $file && [ "`basename $file`" != menu.lst ]; then
171 rm -f $file || exit 1
172 fi
173 done
174 for file in ${input_dir}/*.mod; do
175 if test -f "$file"; then
176 cp -f "$file" "$grubdir/"
177 fi
178 done
179 for file in ${pkglib_DATA}; do
180 if test -f "${input_dir}/${file}"; then
181 cp -f "${input_dir}/${file}" "$grubdir/"
182 fi
183 done
184
185 mkdir -p "$grubdir/locale"
186 for file in ${input_dir}/po/*.mo; do
187 if test -f "$file"; then
188 cp -f "$file" "$grubdir/locale/"
189 fi
190 done
191
192 rm -f ${grubdir}/load.cfg
193
194 if [ "x${debug_image}" != x ]; then
195 echo "set debug='${debug_image}'" >> ${grubdir}/load.cfg
196 config_opt="-c ${grubdir}/load.cfg "
197 fi
198
199 case "${platform}" in
200 i386-pc) mkimage_target=i386-pc-pxe;
201 netmodules="pxe";
202 prefix="(pxe)/${subdir}/${platform}";
203 ext=0 ;;
204 *) echo Unsupported platform ${platform};
205 exit 1;;
206 esac
207
208 cat << EOF > ${grubdir}/grub.cfg
209source ${subdir}/grub.cfg
210EOF
211
212 $grub_mkimage ${config_opt} -d "${input_dir}" -O ${mkimage_target} --output=${grubdir}/core.$ext --prefix=$prefix $modules $netmodules || exit 1
213 echo "Netboot directory for ${platform} created. Configure your DHCP server to point to ${subdir}/${platform}/core.$ext"
214}
215
216if [ "${override_dir}" = "" ] ; then
217 if test -e "${pc_dir}" ; then
218 process_input_dir ${pc_dir} i386-pc
219 fi
220else
6ad6223e
VS
221 source "${override_dir}"/modinfo.sh
222 process_input_dir "${override_dir}" ${grub_modinfo_target_cpu}-${grub_modinfo_platform}
8395034b
VS
223fi
224
225
226# Bye.
227exit 0