2015-12-27 20:20:38 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Copyright (C) 2015
|
|
|
|
# Thomas Schmitt <scdbackup@gmx.net>, libburnia-project.org
|
|
|
|
# Provided under BSD license: Use, modify, and distribute as you like.
|
|
|
|
|
|
|
|
echo >&2
|
|
|
|
echo "frontend/grub-mkrescue-sed.sh manipulating xorriso arguments" >&2
|
|
|
|
echo >&2
|
|
|
|
|
|
|
|
# This script may be handed by its absolute path to grub-mkrescue
|
|
|
|
# via option --xorriso= . E.g.
|
|
|
|
#
|
|
|
|
# mkdir minimal
|
|
|
|
# touch minimal/empty-file.txt
|
|
|
|
# grub-mkrescue -o output.iso minimal \
|
|
|
|
# --xorriso=/home/thomas/xorriso-1.4.3./frontend/grub-mkrescue-sed.sh
|
|
|
|
#
|
2015-12-28 11:26:05 +00:00
|
|
|
# It will manipulate the xorriso arguments before they get executed by a
|
|
|
|
# xorriso program. Default is the neighboring ../../xorriso/xorriso program or,
|
|
|
|
# if that neighbor cannot be found, the system-wide installed xorriso.
|
2015-12-27 20:20:38 +00:00
|
|
|
#
|
2015-12-28 11:26:05 +00:00
|
|
|
# The mode "mjg" implements an experiment which should be accompanied by a
|
|
|
|
# GNU xorriso built by
|
2015-12-27 20:20:38 +00:00
|
|
|
# export CPPFLAGS="-DLibisofs_mjg_boot_for_grub2"
|
|
|
|
# ./configure && make clean && make
|
2015-12-28 11:26:05 +00:00
|
|
|
#
|
|
|
|
# The mode "mbr_only" implements an alternative fully UEFI compliant layout
|
|
|
|
# which does not produce GTP, HFS+, and APM.
|
|
|
|
# It is supposed to work with any unmodified xorriso >= 1.3.2
|
|
|
|
#
|
2015-12-27 20:20:38 +00:00
|
|
|
|
2015-12-28 11:26:05 +00:00
|
|
|
#
|
|
|
|
# Variation settings
|
|
|
|
#
|
|
|
|
# The environment variables MKRESCUE_SED_* override the following
|
|
|
|
# default settings:
|
2015-12-27 20:20:38 +00:00
|
|
|
|
2015-12-28 11:26:05 +00:00
|
|
|
# Manipulation mode:
|
|
|
|
# "mjg" = ESP in MBR+GPT+APM, with HFS+
|
|
|
|
# "mbr_only" = ESP in MBR, without HFS+
|
|
|
|
# "original" = pass arguments unchanged
|
|
|
|
mode="mjg"
|
|
|
|
if test -n "$MKRESCUE_SED_MODE"
|
|
|
|
then
|
|
|
|
mode="$MKRESCUE_SED_MODE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# First argument of -append_partition with mode "mjg". Values: 1 or 2.
|
2015-12-27 20:20:38 +00:00
|
|
|
partno=1
|
2015-12-28 11:26:05 +00:00
|
|
|
if test -n "$MKRESCUE_SED_PARTNO"
|
|
|
|
then
|
|
|
|
partno="$MKRESCUE_SED_PARTNO"
|
|
|
|
fi
|
2015-12-27 20:20:38 +00:00
|
|
|
|
2015-12-28 11:26:05 +00:00
|
|
|
# Replacement for option --protective-msdos-label. Either itself or empty text.
|
|
|
|
# If the environment variable contains the word "no", this means empty.
|
2015-12-27 20:20:38 +00:00
|
|
|
protective="--protective-msdos-label"
|
2015-12-28 11:26:05 +00:00
|
|
|
if test -n "$MKRESCUE_SED_PROTECTIVE"
|
|
|
|
then
|
|
|
|
if test x"$MKRESCUE_SED_PROTECTIVE" = xno
|
|
|
|
then
|
|
|
|
protective=""
|
|
|
|
elif test x"$MKRESCUE_SED_PROTECTIVE" = xyes
|
|
|
|
then
|
|
|
|
protective="--protective-msdos-label"
|
|
|
|
else
|
|
|
|
protective="$MKRESCUE_SED_PROTECTIVE"
|
|
|
|
fi
|
|
|
|
fi
|
2015-12-27 20:20:38 +00:00
|
|
|
|
2015-12-28 11:26:05 +00:00
|
|
|
# "yes" shows xorriso arguments, "extra" additionally shows all input files.
|
2015-12-27 20:20:38 +00:00
|
|
|
debug=no
|
2015-12-28 11:26:05 +00:00
|
|
|
if test -n "$MKRESCUE_SED_DEBUG"
|
|
|
|
then
|
|
|
|
debug="$MKRESCUE_SED_DEBUG"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# The path to the program that will be executed with the converted arguments.
|
|
|
|
if test -n "$MKRESCUE_SED_XORRISO"
|
|
|
|
then
|
|
|
|
xorriso="$MKRESCUE_SED_XORRISO"
|
|
|
|
else
|
|
|
|
# Prefer neighboring xorriso binary over system-wide installed one.
|
|
|
|
self_dir="$(dirname $(dirname "$0") )"
|
|
|
|
if test -x "$self_dir"/xorriso/xorriso
|
|
|
|
then
|
|
|
|
xorriso="$self_dir"/xorriso/xorriso
|
|
|
|
else
|
|
|
|
xorriso="xorriso"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# MKRESCUE_SED_XORRISO_ARGS will be used as first arguments of the xorriso run.
|
|
|
|
# (Trailing xorriso arguments may be simply added to the grub-mkrescue
|
|
|
|
# command line.)
|
|
|
|
# Each argument must be a single word. No whitespace. No quotation marks.
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Do the work
|
|
|
|
#
|
|
|
|
|
|
|
|
echo "frontend/grub-mkrescue-sed.sh mode: $mode" >&2
|
|
|
|
echo >&2
|
2015-12-27 20:20:38 +00:00
|
|
|
|
2015-12-28 11:26:05 +00:00
|
|
|
if test x"$debug" = xyes -o x"$debug" = xextra
|
2015-12-27 20:20:38 +00:00
|
|
|
then
|
|
|
|
# Show arguments
|
2015-12-28 11:26:05 +00:00
|
|
|
echo "##### Begin of received arguments" >&2
|
2015-12-27 20:20:38 +00:00
|
|
|
echo "$0" >&2
|
|
|
|
for i in "$@"
|
|
|
|
do
|
2015-12-28 11:26:05 +00:00
|
|
|
echo "$i" >&2
|
2015-12-27 20:20:38 +00:00
|
|
|
done
|
2015-12-28 11:26:05 +00:00
|
|
|
echo "##### End of recived arguments" >&2
|
|
|
|
echo >&2
|
2015-12-27 20:20:38 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Look for the name of the /tmp directory with the GRUB2 files.
|
|
|
|
# It is the next argument after -r.
|
|
|
|
next_is_dir=0
|
|
|
|
dir="."
|
|
|
|
for i in "$@"
|
|
|
|
do
|
|
|
|
if test x"$i" = x"-r"
|
|
|
|
then
|
|
|
|
next_is_dir=1
|
|
|
|
elif test $next_is_dir = 1
|
|
|
|
then
|
|
|
|
next_is_dir=0
|
|
|
|
dir="$i"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2015-12-28 11:26:05 +00:00
|
|
|
if test x"$debug" = xextra
|
2015-12-27 20:20:38 +00:00
|
|
|
then
|
|
|
|
# Show files on disk
|
|
|
|
find "$dir"
|
|
|
|
fi
|
|
|
|
|
2015-12-28 11:26:05 +00:00
|
|
|
if test x"$mode" = xmjg
|
|
|
|
then
|
|
|
|
# Exchange arguments for the experimental GRUB2 mjg layout
|
|
|
|
x=$(echo " $*" | sed \
|
2015-12-27 20:20:38 +00:00
|
|
|
-e "s/-efi-boot-part --efi-boot-image/-no-pad -append_partition $partno 0xef \/tmp\/$(basename "$dir")\/efi.img/" \
|
|
|
|
-e "s/--efi-boot efi\.img/-eltorito-alt-boot -e efi.img -no-emul-boot -isohybrid-gpt-basdat/" \
|
|
|
|
-e "s/--protective-msdos-label/$protective/" \
|
|
|
|
)
|
|
|
|
|
2015-12-28 11:26:05 +00:00
|
|
|
elif test x"$mode" = xmbr_only
|
|
|
|
then
|
|
|
|
# Exchange arguments for no-HFS MBR-only layout
|
|
|
|
x=$(echo " $*" | sed \
|
|
|
|
-e "s/-efi-boot-part --efi-boot-image/-no-pad -append_partition 2 0xef \/tmp\/$(basename "$dir")\/efi.img/" \
|
|
|
|
-e "s/-hfsplus .*CoreServices\/boot.efi//" \
|
|
|
|
-e "s/--protective-msdos-label/$protective/" \
|
|
|
|
)
|
|
|
|
|
|
|
|
elif test x"$mode" = xoriginal
|
|
|
|
then
|
|
|
|
# Pass arguments unchanged
|
|
|
|
x=" $*"
|
|
|
|
|
|
|
|
else
|
|
|
|
echo >&2
|
|
|
|
echo "$0 : FATAL : Unknown manipulation mode '$mode'." >&2
|
|
|
|
echo >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test x"$debug" = xyes -o x"$debug" = xextra
|
2015-12-27 20:20:38 +00:00
|
|
|
then
|
|
|
|
echo "+ converted xorriso arguments:" >&2
|
|
|
|
echo " $x" >&2
|
2015-12-28 11:26:05 +00:00
|
|
|
echo >&2
|
2015-12-27 20:20:38 +00:00
|
|
|
fi
|
|
|
|
|
2015-12-28 11:26:05 +00:00
|
|
|
# Run xorriso binary with the converted arguments
|
|
|
|
"$xorriso" $MKRESCUE_SED_XORRISO_ARGS $x
|
2015-12-27 20:20:38 +00:00
|
|
|
|