]> git.proxmox.com Git - grub2.git/blame - util/grub-mkstandalone.in
* grub-core/loader/i386/bsdXX.c (grub_openbsd_find_ramdisk): Use
[grub2.git] / util / grub-mkstandalone.in
CommitLineData
41aa28ea
VS
1#! /bin/sh
2set -e
3
4# Make GRUB rescue image
a32d5c71 5# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012 Free Software Foundation, Inc.
41aa28ea
VS
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.
48b391e9 21
48b391e9
VS
22prefix="@prefix@"
23exec_prefix="@exec_prefix@"
24datarootdir="@datarootdir@"
25bindir="@bindir@"
26libdir="@libdir@"
41aa28ea
VS
27PACKAGE_NAME=@PACKAGE_NAME@
28PACKAGE_TARNAME=@PACKAGE_TARNAME@
29PACKAGE_VERSION=@PACKAGE_VERSION@
30pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst"
a32d5c71 31datadir="@datadir@"
c8d9ead6 32if [ "x$pkgdatadir" = x ]; then
2311c5ca 33 pkgdatadir="${datadir}/@PACKAGE@"
c8d9ead6 34fi
41aa28ea
VS
35
36self=`basename $0`
37
86717cbe 38source_directory=
41aa28ea
VS
39compression=auto
40format=
fd49ceb3 41grub_mkimage="${bindir}/@grub_mkimage@"
41aa28ea
VS
42source=
43
9cc3ee5c
VS
44export TEXTDOMAIN=@PACKAGE@
45export TEXTDOMAINDIR="@localedir@"
46
c8d9ead6 47. "${pkgdatadir}/grub-mkconfig_lib"
a32d5c71 48
41aa28ea
VS
49# Usage: usage
50# Print the usage.
51usage () {
a32d5c71
VS
52 formats="i386-coreboot i386-multiboot i386-pc i386-pc-pxe i386-efi i386-ieee1275 i386-qemu x86_64-efi mipsel-yeeloong-flash mipsel-fuloong2f-flash mipsel-loongson-elf powerpc-ieee1275 sparc64-ieee1275-raw sparc64-ieee1275-aout ia64-efi mips-arc mipsel-qemu_mips-elf mips-qemu_mips-flash mipsel-qemu_mips-flash mips-qemu_mips-elf"
53 gettext_printf "Usage: %s [OPTION] SOURCE...\n" "$self"
9c4b5c13
VS
54 gettext "Generate a standalone image (containing all modules) in the selected format"
55 echo
9f9d3f69
VS
56 print_option_help "-h, --help" "$(gettext "print this message and exit")"
57 print_option_help "-v, --version" "$(gettext "print the version information and exit")"
58 print_option_help "-o, --output=$(gettext FILE)" "$(gettext "save output in FILE [required]")"
67093bc0 59 # TRANSLATORS: platform here isn't identifier. It can be translated.
2311c5ca 60 dir_msg="$(gettext_printf "use images and modules under DIR [default=%s/<platform>]" "${libdir}/@PACKAGE@")"
9f9d3f69
VS
61 print_option_help "-d, --directory=$(gettext "DIR")" "$dir_msg"
62 print_option_help "-O, --format=$(gettext "FORMAT")" "$(gettext "generate an image in FORMAT")"; echo
63 print_option_help "" "$(gettext "available formats:") $formats"
a32d5c71 64 echo
9f9d3f69
VS
65 print_option_help "-C, --compression=(xz|none|auto)" "$(gettext "choose the compression to use")"
66 print_option_help "--modules=$(gettext "MODULES")" "$(gettext "pre-load specified modules MODULES")"
67 print_option_help "--grub-mkimage=$(gettext "FILE")" "$(gettext "use FILE as grub-mkimage")"
a32d5c71 68 echo
a32d5c71 69 gettext "Report bugs to <bug-grub@gnu.org>."; echo
41aa28ea
VS
70}
71
72argument () {
73 opt=$1
74 shift
75
76 if test $# -eq 0; then
805a8dcc 77 gettext_printf "%s: option requires an argument -- \`%s'\n" "$0" "$opt" 1>&2
41aa28ea
VS
78 exit 1
79 fi
80 echo $1
81}
82
83# Check the arguments.
84while test $# -gt 0
85do
86 option=$1
87 shift
88
89 case "$option" in
90 -h | --help)
91 usage
92 exit 0 ;;
93 -v | --version)
94 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
95 exit 0 ;;
96
97 --modules)
86717cbe 98 modules=`argument $option "$@"`; shift ;;
41aa28ea
VS
99 --modules=*)
100 modules=`echo "$option" | sed 's/--modules=//'` ;;
101
102 -o | --output)
103 output_image=`argument $option "$@"`; shift ;;
104 --output=*)
105 output_image=`echo "$option" | sed 's/--output=//'` ;;
106
107 --directory | -d)
86717cbe 108 source_directory=`argument $option "$@"`; shift ;;
41aa28ea 109 --directory=*)
86717cbe 110 source_directory=`echo "$option" | sed 's/--directory=//'` ;;
41aa28ea
VS
111
112 --grub-mkimage)
113 grub_mkimage=`argument $option "$@"`; shift ;;
114 --grub-mkimage=*)
115 grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
116
117 --compression | -C)
118 compression=`argument $option "$@"`; shift ;;
119 --compression=*)
86717cbe 120 compression=`echo "${option}" | sed 's/--compression=//'` ;;
41aa28ea
VS
121
122 --format | -O)
123 format=`argument $option "$@"`; shift ;;
124 --format=*)
86717cbe 125 format=`echo "${option}" | sed 's/--format=//'` ;;
41aa28ea
VS
126
127 *)
128 source="${source} ${option} $@"; break ;;
129 esac
130done
131
132if [ "x${output_image}" = x ] ; then
a32d5c71
VS
133 gettext "output file must be specified" >&2
134 echo >&2
41aa28ea
VS
135 usage
136 exit 1
137fi
138
139if [ "x${format}" = x ] ; then
b525fd83 140 gettext "Target format not specified (use the -O option)." >&2
a32d5c71 141 echo >&2
41aa28ea
VS
142 exit 1
143fi
144
145if [ "x$source_directory" = x ] ; then
146 cpu="`echo $format | awk -F - '{ print $1; }'`"
147 platform="`echo $format | awk -F - '{ print $2; }'`"
148 case "$platform" in
14a2562c 149 yeeloong | fuloong | fuloong2f | fuloong2e)
41aa28ea
VS
150 platform=loongson ;;
151 esac
152 case "$cpu-$platform" in
153 mips-loongson)
154 cpu=mipsel ;;
155 esac
2311c5ca 156 source_directory="${libdir}/@PACKAGE@/$cpu-$platform"
41aa28ea
VS
157fi
158
571e140e
VS
159. "${source_directory}"/modinfo.sh
160
41aa28ea
VS
161set $grub_mkimage dummy
162if test -f "$1"; then
163 :
164else
165 echo "$1: Not found." 1>&2
166 exit 1
167fi
168
169memdisk_dir="`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1
571e140e 170mkdir -p "${memdisk_dir}"/boot/grub/"${grub_modinfo_target_cpu}-${grub_modinfo_platform}"
41aa28ea
VS
171
172for file in "${source_directory}/"*.mod "${source_directory}/"efiemu32.o "${source_directory}/"efiemu64.o; do
173 if test -f "$file"; then
571e140e 174 cp -f "$file" "${memdisk_dir}"/boot/grub/"${grub_modinfo_target_cpu}-${grub_modinfo_platform}"
41aa28ea
VS
175 fi
176done
86717cbe 177
41aa28ea
VS
178for file in ${pkglib_DATA}; do
179 if test -f "${source_directory}/${file}"; then
571e140e 180 cp -f "${source_directory}/${file}" "${memdisk_dir}"/boot/grub/"${grub_modinfo_target_cpu}-${grub_modinfo_platform}"
41aa28ea
VS
181 fi
182done
183
184mkdir -p "${memdisk_dir}"/boot/grub/locale
185for file in "${source_directory}"/po/*.mo; do
186 if test -f "$file"; then
187 cp -f "$file" "${memdisk_dir}"/boot/grub/locale/
188 fi
189done
190
191for file in $source; do
192 cp -f "$file" "${memdisk_dir}"/"$file";
193done
194
195memdisk_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
196
197(cd "${memdisk_dir}"; tar -cf - * $source) > "${memdisk_img}"
198rm -rf "${memdisk_dir}"
48b391e9 199"$grub_mkimage" -O "${format}" -C "$compression" -d "${source_directory}" -m "${memdisk_img}" -o "$output_image" --prefix='(memdisk)/boot/grub' memdisk tar $modules
41aa28ea
VS
200rm -rf "${memdisk_img}"
201
202exit 0