Hello!
I have tried grub-install and it's behaviour is quite confusing even on
Linux.
The attached patch deals with some issues that I have found so far, but it
doesn't yet make grub-install user-friendly and fully portable, neither
does it add support for *BSD.
Changelog:
* util/grub-install.in: Don't use `!' in `test' for more
portability.
Don't use `for' without `in' for compatability with ash.
Check install_device before running grub if possible. Added
error messages if install_device is not set or not unique.
Exit if mkdir fails
Add a message about successful installation
Remove unneeded backslash in the final message
(convert): use `test -b' instead of `test -e' because ash doesn't
understand the later. Correct error message accordingly.
Notes outside Changelog:
I understand that eliminating "test !" makes the code longer. However,
grub-install kept running when `test' from `ash' failed to understand
`-e', which is bad IMO. It's better to be on the safe side and follow
Autoconf practice as long as it makes sence.
It was very confusing to see a message that asked me to review device.map.
I reviewed it, re-ran grub-install - no effect. I touched device.map and
re-ran grub-install - no effect either. Then I realized that grub-install
hadn't inform me that it (probably) had succeeded.
OpenBSD has a regular file /boot. I think we should use /grub in this
case.
Regards,
Pavel Roskin
====== cut here ======
--- util/grub-install.in Sat Apr 15 11:31:05 2000
+++ util/grub-install.in Sun Apr 16 23:17:51 2000
@@ -60,8 +60,10 @@
# This part is OS-specific.
convert () {
# First, check if the device file exists.
- if test ! -e "$1"; then
- echo "$1: Not found." 1>&2
+ if test -b "$1"; then
+ :
+ else
+ echo "$1: Not found or not a block device." 1>&2
exit 1
fi
@@ -113,7 +115,7 @@
}
# Check the arguments.
-for option; do
+for option in "$@"; do
case "$option" in
-h | --help)
usage
@@ -130,6 +132,7 @@
debug=yes ;;
*)
if test "x$install_device" != x; then
+ echo "More than one install_device?" 1>&2
usage
exit 1
fi
@@ -137,6 +140,12 @@
esac
done
+if test "x$install_device" = x; then
+ echo "install_device not specified" 1>&2
+ usage
+ exit 1
+fi
+
# If the debugging feature is enabled, print commands.
if test $debug = yes; then
set -x
@@ -148,17 +157,23 @@
device_map=${grubdir}/device.map
# Check if GRUB is installed
-if test ! -f "$grub_shell"; then
+if test -f "$grub_shell"; then
+ :
+else
echo "${grub_shell}: Not found." 1>&2
exit 1
fi
-if test ! -f "$pkgdatadir/stage1"; then
+if test -f "$pkgdatadir/stage1"; then
+ :
+else
echo "${pkgdatadir}/stage1: Not found." 1>&2
exit 1
fi
-if test ! -f "$pkgdatadir/stage2"; then
+if test -f "$pkgdatadir/stage2"; then
+ :
+else
echo "${pkgdatadir}/stage2: Not found." 1>&2
exit 1
fi
@@ -167,11 +182,13 @@
# Stage 1.5 does not exist.
# Create the GRUB directory if it is not present.
-test -d "$bootdir" || mkdir "$bootdir"
-test -d "$grubdir" || mkdir "$grubdir"
+test -d "$bootdir" || mkdir "$bootdir" || exit 1
+test -d "$grubdir" || mkdir "$grubdir" || exit 1
# Create the device map file if it is not present.
-if test ! -f "$device_map"; then
+if test -f "$device_map"; then
+ :
+else
# Create a safe temporary file.
test -x /bin/tempfile && log_file=`tempfile --prefix=grub`
@@ -187,25 +204,21 @@
fi
# Check for INSTALL_DEVICE.
-if test "x$install_device" = x; then
+case "$install_device" in
+/dev/*)
+ install_drive=`convert "$install_device"`
+ # I don't know why, but some shells wouldn't die if exit is
+ # called in a function.
+ if test "x$install_drive" = x; then
+ exit 1
+ fi ;;
+\([hf]d[0-9]*\))
+ install_drive="$install_device" ;;
+*)
+ echo "Format of install_device not recognized" 1>&2
usage
- exit 1
-else
- case "$install_device" in
- /dev/*)
- install_drive=`convert "$install_device"`
- # I don't know why, but some shells wouldn't die if exit is
- # called in a function.
- if test "x$install_drive" = x; then
- exit 1
- fi ;;
- \([hf]d[0-9]*\))
- install_drive="$install_device" ;;
- *)
- usage
- exit 1 ;;
- esac
-fi
+ exit 1 ;;
+esac
# Get the root drive.
# For now, this uses the program `df' to get the device name, but is
@@ -251,9 +264,10 @@
rm -f $log_file
# Prompt the user to check if the device map is correct.
+echo "Installation finished. No errors reported."
echo "This is the contents of the device map $device_map."
echo "Check if this is correct or not. If any of the lines is incorrect,"
-echo "fix it and re-run the script \`grub-install\'."
+echo "fix it and re-run the script \`grub-install'."
echo
cat $device_map
====== cut here ======