2010-09-02 15:15:53 +00:00
|
|
|
#! /bin/sh
|
|
|
|
|
|
|
|
# Install GRUB on your drive.
|
|
|
|
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
|
|
|
|
#
|
|
|
|
# GRUB is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# GRUB is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# Initialize some variables.
|
|
|
|
transform="@program_transform_name@"
|
|
|
|
|
2012-01-24 12:17:36 +00:00
|
|
|
prefix="@prefix@"
|
|
|
|
exec_prefix="@exec_prefix@"
|
|
|
|
datarootdir="@datarootdir@"
|
|
|
|
bindir="@bindir@"
|
|
|
|
libdir="@libdir@"
|
2010-09-02 15:15:53 +00:00
|
|
|
PACKAGE_NAME=@PACKAGE_NAME@
|
|
|
|
PACKAGE_TARNAME=@PACKAGE_TARNAME@
|
|
|
|
PACKAGE_VERSION=@PACKAGE_VERSION@
|
|
|
|
host_os=@host_os@
|
|
|
|
pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst"
|
2012-02-03 10:42:22 +00:00
|
|
|
datadir="@datadir@"
|
2012-02-10 17:16:27 +00:00
|
|
|
if [ "x$pkgdatadir" = x ]; then
|
|
|
|
pkgdatadir="${datadir}/`echo @PACKAGE_TARNAME@ | sed "${transform}"`"
|
|
|
|
fi
|
2010-09-02 15:15:53 +00:00
|
|
|
|
|
|
|
self=`basename $0`
|
|
|
|
|
2012-01-24 12:17:36 +00:00
|
|
|
grub_mkimage="${bindir}/`echo grub-mkimage | sed ${transform}`"
|
2010-09-02 15:15:53 +00:00
|
|
|
rootdir=/srv/tftp
|
|
|
|
grub_prefix=`echo /boot/grub | sed ${transform}`
|
|
|
|
modules=
|
|
|
|
|
|
|
|
install_device=
|
|
|
|
no_floppy=
|
|
|
|
recheck=no
|
|
|
|
debug=no
|
|
|
|
debug_image=
|
|
|
|
subdir=`echo /boot/grub | sed ${transform}`
|
2012-01-24 12:17:36 +00:00
|
|
|
pc_dir="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-pc"
|
|
|
|
ppc_dir="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/powerpc-ieee1275"
|
|
|
|
sparc_dir="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/sparc64-ieee1275"
|
|
|
|
i386_ieee1275_dir="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-ieee1275"
|
|
|
|
efi32_dir="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-efi"
|
|
|
|
efi64_dir="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/x86_64-efi"
|
|
|
|
itanium_dir="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/ia64-efi"
|
2010-09-02 15:15:53 +00:00
|
|
|
|
2012-02-10 17:16:27 +00:00
|
|
|
. "${pkgdatadir}/grub-mkconfig_lib"
|
2012-02-03 10:42:22 +00:00
|
|
|
|
2010-09-02 15:15:53 +00:00
|
|
|
# Usage: usage
|
|
|
|
# Print the usage.
|
|
|
|
usage () {
|
2012-02-03 10:42:22 +00:00
|
|
|
gettext_printf "Usage: %s [OPTION] install_device\n" "$self"
|
|
|
|
gettext; echo "Install GRUB on your drive."; echo
|
|
|
|
echo
|
|
|
|
printf " -h, --help %s\n" "$(gettext "print this message and exit")"
|
|
|
|
printf " -v, --version %s\n" "$(gettext "print the version information and exit")"
|
|
|
|
printf " --modules=%-14s%s\n" "$(gettext "MODULES")" "$(gettext "pre-load specified modules MODULES")"
|
|
|
|
printf " --net-directory=%-8s%s\n" "$(gettext "DIR")" "$(gettext "root directory of TFTP server")"
|
|
|
|
printf " --subdir=%-15s%s\n" "$(gettext "DIR")" "$(gettext "relative subdirectory on network server")"
|
|
|
|
printf " --grub-mkimage=%-9s%s" "$(gettext "FILE")" "$(gettext "use FILE as grub-mkimage")"
|
|
|
|
echo
|
|
|
|
gettext_printf "%s copies GRUB images into net_directory/subdir/target_cpu-platform\n" "$self"
|
|
|
|
echo
|
|
|
|
gettext "Report bugs to <bug-grub@gnu.org>."; echo
|
2010-09-02 15:15:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
argument () {
|
|
|
|
opt=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
if test $# -eq 0; then
|
2012-02-03 10:42:22 +00:00
|
|
|
gettext_printf "%s: option requires an argument -- '%s'\n" "$0" "$opt" 1>&2
|
2010-09-02 15:15:53 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo $1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check the arguments.
|
|
|
|
while test $# -gt 0
|
|
|
|
do
|
|
|
|
option=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
case "$option" in
|
|
|
|
-h | --help)
|
|
|
|
usage
|
|
|
|
exit 0 ;;
|
|
|
|
-v | --version)
|
|
|
|
echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
|
|
|
|
exit 0 ;;
|
|
|
|
|
|
|
|
--modules)
|
|
|
|
modules=`argument $option "$@"`; shift;;
|
|
|
|
--modules=*)
|
|
|
|
modules=`echo "$option" | sed 's/--modules=//'` ;;
|
|
|
|
|
|
|
|
--net-directory)
|
|
|
|
rootdir=`argument $option "$@"`; shift;;
|
|
|
|
--net-directory=*)
|
|
|
|
rootdir=`echo "$option" | sed 's/--net-directory=//'` ;;
|
|
|
|
|
|
|
|
--subdir)
|
|
|
|
subdir=`argument $option "$@"`; shift;;
|
|
|
|
--subdir=*)
|
|
|
|
subdir=`echo "$option" | sed 's/--subdir=//'` ;;
|
|
|
|
|
|
|
|
--grub-mkimage)
|
|
|
|
grub_mkimage=`argument $option "$@"`; shift;;
|
|
|
|
--grub-mkimage=*)
|
|
|
|
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
|
|
|
|
|
|
|
|
# This is an undocumented feature...
|
|
|
|
--debug)
|
|
|
|
debug=yes ;;
|
|
|
|
--debug-image)
|
|
|
|
debug_image=`argument $option "$@"`; shift;;
|
|
|
|
--debug-image=*)
|
|
|
|
debug_image=`echo "$option" | sed 's/--debug-image=//'` ;;
|
|
|
|
|
|
|
|
# Intentionally undocumented
|
|
|
|
--override-directory)
|
|
|
|
override_dir=`argument $option "$@"`
|
|
|
|
shift
|
|
|
|
PATH=${override_dir}:$PATH
|
|
|
|
export PATH
|
|
|
|
;;
|
|
|
|
--override-directory=*)
|
|
|
|
override_dir=`echo "${option}/" | sed 's/--override-directory=//'`
|
|
|
|
PATH=${override_dir}:$PATH
|
|
|
|
export PATH
|
|
|
|
;;
|
|
|
|
|
|
|
|
-*)
|
2012-02-03 10:42:22 +00:00
|
|
|
gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
|
2010-09-02 15:15:53 +00:00
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if test "x$install_device" != x; then
|
|
|
|
echo "More than one install_devices?" 1>&2
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
install_device="${option}" ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
set $grub_mkimage dummy
|
|
|
|
if test -f "$1"; then
|
|
|
|
:
|
|
|
|
else
|
2012-02-03 10:42:22 +00:00
|
|
|
gettext_printf "%s: Not found.\n" "$1" 1>&2
|
2010-09-02 15:15:53 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create the GRUB directory if it is not present.
|
|
|
|
mkdir -p "${rootdir}/${subdir}" || exit 1
|
|
|
|
|
|
|
|
process_input_dir ()
|
|
|
|
{
|
|
|
|
input_dir="$1"
|
|
|
|
platform="$2"
|
|
|
|
grubdir="${rootdir}/${subdir}/${platform}"
|
|
|
|
config_opt=
|
|
|
|
mkdir -p "$grubdir" || exit 1
|
|
|
|
|
2012-01-24 12:17:36 +00:00
|
|
|
for file in "${grubdir}"/*.mod "${grubdir}"/*.lst "${grubdir}"/*.img "${grubdir}"/efiemu??.o; do
|
|
|
|
if test -f "$file" && [ "`basename $file`" != menu.lst ]; then
|
|
|
|
rm -f "$file" || exit 1
|
2010-09-02 15:15:53 +00:00
|
|
|
fi
|
|
|
|
done
|
2012-01-24 12:17:36 +00:00
|
|
|
for file in "${input_dir}"/*.mod; do
|
2010-09-02 15:15:53 +00:00
|
|
|
if test -f "$file"; then
|
|
|
|
cp -f "$file" "$grubdir/"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
for file in ${pkglib_DATA}; do
|
|
|
|
if test -f "${input_dir}/${file}"; then
|
|
|
|
cp -f "${input_dir}/${file}" "$grubdir/"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
mkdir -p "$grubdir/locale"
|
|
|
|
for file in ${input_dir}/po/*.mo; do
|
|
|
|
if test -f "$file"; then
|
|
|
|
cp -f "$file" "$grubdir/locale/"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
rm -f ${grubdir}/load.cfg
|
|
|
|
|
|
|
|
if [ "x${debug_image}" != x ]; then
|
|
|
|
echo "set debug='${debug_image}'" >> ${grubdir}/load.cfg
|
|
|
|
config_opt="-c ${grubdir}/load.cfg "
|
|
|
|
fi
|
|
|
|
|
2012-02-04 20:47:29 +00:00
|
|
|
prefix="/${subdir}";
|
2010-09-02 15:15:53 +00:00
|
|
|
case "${platform}" in
|
|
|
|
i386-pc) mkimage_target=i386-pc-pxe;
|
|
|
|
netmodules="pxe";
|
|
|
|
ext=0 ;;
|
2011-06-26 15:28:19 +00:00
|
|
|
sparc64-ieee1275) mkimage_target=sparc64-ieee1275-aout;
|
2011-06-26 17:52:50 +00:00
|
|
|
netmodules="ofnet";
|
2011-06-26 15:28:19 +00:00
|
|
|
ext=img ;;
|
|
|
|
*-ieee1275) mkimage_target="${platform}";
|
2011-06-26 17:52:50 +00:00
|
|
|
netmodules="ofnet";
|
2011-06-26 15:28:19 +00:00
|
|
|
ext=elf ;;
|
2011-06-26 20:47:05 +00:00
|
|
|
*-efi) mkimage_target="${platform}";
|
|
|
|
netmodules="efinet";
|
|
|
|
ext=efi ;;
|
2012-02-03 10:42:22 +00:00
|
|
|
*) gettext_printf "Unsupported platform %s\n" ${platform};
|
2010-09-02 15:15:53 +00:00
|
|
|
exit 1;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
cat << EOF > ${grubdir}/grub.cfg
|
|
|
|
source ${subdir}/grub.cfg
|
|
|
|
EOF
|
|
|
|
|
2012-01-24 12:17:36 +00:00
|
|
|
"$grub_mkimage" ${config_opt} -d "${input_dir}" -O ${mkimage_target} "--output=${grubdir}/core.$ext" "--prefix=$prefix" $modules $netmodules tftp || exit 1
|
2012-02-03 10:42:22 +00:00
|
|
|
gettext_printf "Netboot directory for %s created. Configure your DHCP server to point to %s\n" "${platform}" "${subdir}/${platform}/core.$ext"
|
2010-09-02 15:15:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ "${override_dir}" = "" ] ; then
|
|
|
|
if test -e "${pc_dir}" ; then
|
2011-06-26 16:23:12 +00:00
|
|
|
process_input_dir "${pc_dir}" i386-pc
|
2010-09-02 15:15:53 +00:00
|
|
|
fi
|
2011-06-26 15:51:46 +00:00
|
|
|
if test -e "${ppc_dir}" ; then
|
2011-06-26 16:23:12 +00:00
|
|
|
process_input_dir "${ppc_dir}" powerpc-ieee1275
|
2011-06-26 15:51:46 +00:00
|
|
|
fi
|
|
|
|
if test -e "${sparc_dir}" ; then
|
|
|
|
process_input_dir ${sparc_dir} sparc64-ieee1275
|
|
|
|
fi
|
|
|
|
if test -e "${i386_ieee1275_dir}" ; then
|
2011-06-26 16:23:12 +00:00
|
|
|
process_input_dir "${i386_ieee1275_dir}" i386-ieee1275
|
2011-06-26 15:51:46 +00:00
|
|
|
fi
|
2011-06-26 20:47:05 +00:00
|
|
|
if test -e "${efi32_dir}" ; then
|
|
|
|
process_input_dir "${efi32_dir}" i386-efi
|
|
|
|
fi
|
|
|
|
if test -e "${efi64_dir}" ; then
|
|
|
|
process_input_dir "${efi64_dir}" x86_64-efi
|
|
|
|
fi
|
|
|
|
if test -e "${itanium_dir}" ; then
|
|
|
|
process_input_dir "${itanium_dir}" ia64-efi
|
|
|
|
fi
|
2010-09-02 15:15:53 +00:00
|
|
|
else
|
2012-02-08 19:27:46 +00:00
|
|
|
. "${override_dir}"/modinfo.sh
|
2011-05-17 23:38:01 +00:00
|
|
|
process_input_dir "${override_dir}" ${grub_modinfo_target_cpu}-${grub_modinfo_platform}
|
2010-09-02 15:15:53 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Bye.
|
|
|
|
exit 0
|