diff --git a/ChangeLog b/ChangeLog index 6e7b0e215..dc17959e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +1999-11-19 OKUJI Yoshinori + + * util/grub-install.in (debug): New variable. + (convert): If the device file does not exist, then emit an + error. Get the GRUB drive instead of the OS device. + If --debug is specified, then set $debug to yes. + If $debug is yes, run "set -x". + Make sure that stage1 and stage2 exist. + When checking for INSTALL_DEVICE, use "case" instead of "elif"s. + Make sure that $install_drive is not empty. + Likewise, make sure that $root_drive is not empty. + Any error message is redirected to the standard error. + +1999-11-19 Pavel Roskin + + * stage2/Makefile.am (noinst_DATA): Renamed to ... + (nodist_noinst_DATA): ... this. + * util/Makefile.am: sbin_SCRIPS -> sbin_SCRIPTS. + * util/grub-install.in: grub_dir -> grubdir. + Check if $grub_shell exists before running it. + (convert): Added a missing "test" after "if". + 1999-11-18 OKUJI Yoshinori * configure.in: Output grub-install. diff --git a/NEWS b/NEWS index ca3b9b027..f4c306f34 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,7 @@ New in 0.5.94: * OpenBSD support in the grub shell is improved. * The command "install" can now patch a Stage 2 with a different filename from "/boot/grub/menu.lst" even if a Stage 1.5 is used. +* New program, ``grub-install''. New in 0.5.93 - 1999-10-30: * ELF format of FreeBSD kernel is supported. diff --git a/stage2/Makefile.am b/stage2/Makefile.am index d6ab99354..863e874fd 100644 --- a/stage2/Makefile.am +++ b/stage2/Makefile.am @@ -24,7 +24,7 @@ pkgdatadir = $(datadir)/$(PACKAGE)/$(host_cpu)-$(host_vendor) nodist_pkgdata_DATA = stage2 e2fs_stage1_5 fat_stage1_5 ffs_stage1_5 \ minix_stage1_5 CLEANFILES = $(nodist_pkgdata_DATA) -noinst_DATA = pre_stage2 start +nodist_noinst_DATA = pre_stage2 start noinst_PROGRAMS = pre_stage2.exec start.exec \ e2fs_stage1_5.exec fat_stage1_5.exec \ ffs_stage1_5.exec minix_stage1_5.exec diff --git a/stage2/Makefile.in b/stage2/Makefile.in index b55f5380d..a2ebd6879 100644 --- a/stage2/Makefile.in +++ b/stage2/Makefile.in @@ -111,7 +111,7 @@ nodist_pkgdata_DATA = stage2 e2fs_stage1_5 fat_stage1_5 ffs_stage1_5 \ minix_stage1_5 CLEANFILES = $(nodist_pkgdata_DATA) $(noinst_DATA) $(BUILT_SOURCES) -noinst_DATA = pre_stage2 start +nodist_noinst_DATA = pre_stage2 start noinst_PROGRAMS = pre_stage2.exec start.exec \ e2fs_stage1_5.exec fat_stage1_5.exec \ ffs_stage1_5.exec minix_stage1_5.exec @@ -254,12 +254,11 @@ DIST_SOURCES = $(libgrub_a_SOURCES) $(e2fs_stage1_5_exec_SOURCES) \ $(fat_stage1_5_exec_SOURCES) $(ffs_stage1_5_exec_SOURCES) \ $(minix_stage1_5_exec_SOURCES) $(pre_stage2_exec_SOURCES) \ $(start_exec_SOURCES) -DATA = $(nodist_pkgdata_DATA) $(noinst_DATA) +DATA = $(nodist_noinst_DATA) $(nodist_pkgdata_DATA) HEADERS = $(noinst_HEADERS) -DIST_COMMON = $(noinst_DATA) $(noinst_HEADERS) Makefile.am Makefile.in \ -compile +DIST_COMMON = $(noinst_HEADERS) Makefile.am Makefile.in compile DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -415,6 +414,24 @@ start.exec: $(start_exec_OBJECTS) $(start_exec_DEPENDENCIES) .c.o: $(COMPILE) -c $< +install-nodist_noinstDATA: $(nodist_noinst_DATA) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(noinstdir) + @list='$(nodist_noinst_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d= ; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(INSTALL_DATA) $$d$$p $(DESTDIR)$(noinstdir)/$$f"; \ + $(INSTALL_DATA) $$d$$p $(DESTDIR)$(noinstdir)/$$f; \ + done + +uninstall-nodist_noinstDATA: + @$(NORMAL_UNINSTALL) + @list='$(nodist_noinst_DATA)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f $(DESTDIR)$(noinstdir)/$$f"; \ + rm -f $(DESTDIR)$(noinstdir)/$$f; \ + done + install-nodist_pkgdataDATA: $(nodist_pkgdata_DATA) @$(NORMAL_INSTALL) $(mkinstalldirs) $(DESTDIR)$(pkgdatadir) @@ -1529,20 +1546,21 @@ installcheck: installcheck-am install-exec-am: install-exec: install-exec-am -install-data-am: install-nodist_pkgdataDATA +install-data-am: install-nodist_noinstDATA install-nodist_pkgdataDATA install-data: install-data-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am install: install-am -uninstall-am: uninstall-nodist_pkgdataDATA +uninstall-am: uninstall-nodist_noinstDATA uninstall-nodist_pkgdataDATA uninstall: uninstall-am all-am: Makefile $(LIBRARIES) $(PROGRAMS) $(SCRIPTS) $(DATA) $(HEADERS) all-redirect: all-am install-strip: $(MAKE) $(AM_MAKEFLAGS) INSTALL_STRIP_FLAG=-s install installdirs: - $(mkinstalldirs) $(DESTDIR)$(nodist_pkgdatadir) + $(mkinstalldirs) $(DESTDIR)$(nodist_noinstdir) \ + $(DESTDIR)$(nodist_pkgdatadir) mostlyclean-generic: @@ -1590,7 +1608,8 @@ clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \ mostlyclean-compile distclean-compile clean-compile \ maintainer-clean-compile mostlyclean-noinstPROGRAMS \ distclean-noinstPROGRAMS clean-noinstPROGRAMS \ -maintainer-clean-noinstPROGRAMS uninstall-nodist_pkgdataDATA \ +maintainer-clean-noinstPROGRAMS uninstall-nodist_noinstDATA \ +install-nodist_noinstDATA uninstall-nodist_pkgdataDATA \ install-nodist_pkgdataDATA tags mostlyclean-tags distclean-tags \ clean-tags maintainer-clean-tags distdir mostlyclean-depend \ distclean-depend clean-depend maintainer-clean-depend check-TESTS \ diff --git a/util/Makefile.am b/util/Makefile.am index 21e9a9d56..5e1ab6b1b 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -1,5 +1,5 @@ bin_PROGRAMS = mbchk -sbin_SCRIPS = grub-install +sbin_SCRIPTS = grub-install # XXX: Need to search for a header file in docs, because of multiboot.h. AM_CFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir)/docs diff --git a/util/Makefile.in b/util/Makefile.in index 3f4051980..c646b901a 100644 --- a/util/Makefile.in +++ b/util/Makefile.in @@ -83,7 +83,7 @@ install_sh = @install_sh@ bin_PROGRAMS = mbchk -sbin_SCRIPS = grub-install +sbin_SCRIPTS = grub-install # XXX: Need to search for a header file in docs, because of multiboot.h. AM_CFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir)/docs @@ -105,6 +105,8 @@ am_mbchk_OBJECTS = mbchk.o mbchk_OBJECTS = $(am_mbchk_OBJECTS) mbchk_DEPENDENCIES = ../lib/libcommon.a mbchk_LDFLAGS = +SCRIPTS = $(sbin_SCRIPTS) + COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CFLAGS = @CFLAGS@ CCLD = $(CC) @@ -174,6 +176,28 @@ maintainer-clean-compile: mbchk: $(mbchk_OBJECTS) $(mbchk_DEPENDENCIES) @rm -f mbchk $(LINK) $(mbchk_LDFLAGS) $(mbchk_OBJECTS) $(mbchk_LDADD) $(LIBS) + +install-sbinSCRIPTS: $(sbin_SCRIPTS) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(sbindir) + @list='$(sbin_SCRIPTS)'; for p in $$list; do \ + f="`echo $$p|sed '$(transform)'`"; \ + if test -f $$p; then \ + echo " $(INSTALL_SCRIPT) $$p $(DESTDIR)$(sbindir)/$$f"; \ + $(INSTALL_SCRIPT) $$p $(DESTDIR)$(sbindir)/$$f; \ + elif test -f $(srcdir)/$$p; then \ + echo " $(INSTALL_SCRIPT) $(srcdir)/$$p $(DESTDIR)$(sbindir)/$$f"; \ + $(INSTALL_SCRIPT) $(srcdir)/$$p $(DESTDIR)$(sbindir)/$$f; \ + else :; fi; \ + done + +uninstall-sbinSCRIPTS: + @$(NORMAL_UNINSTALL) + @list='$(sbin_SCRIPTS)'; for p in $$list; do \ + f="`echo $$p|sed '$(transform)'`"; \ + echo " rm -f $(DESTDIR)$(sbindir)/$$f"; \ + rm -f $(DESTDIR)$(sbindir)/$$f; \ + done .c.o: $(COMPILE) -c $< @@ -268,7 +292,7 @@ check-am: all-am check: check-am installcheck-am: installcheck: installcheck-am -install-exec-am: install-binPROGRAMS +install-exec-am: install-binPROGRAMS install-sbinSCRIPTS install-exec: install-exec-am install-data-am: @@ -277,14 +301,14 @@ install-data: install-data-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am install: install-am -uninstall-am: uninstall-binPROGRAMS +uninstall-am: uninstall-binPROGRAMS uninstall-sbinSCRIPTS uninstall: uninstall-am -all-am: Makefile $(PROGRAMS) +all-am: Makefile $(PROGRAMS) $(SCRIPTS) all-redirect: all-am install-strip: $(MAKE) $(AM_MAKEFLAGS) INSTALL_STRIP_FLAG=-s install installdirs: - $(mkinstalldirs) $(DESTDIR)$(bindir) + $(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(sbindir) mostlyclean-generic: @@ -324,14 +348,15 @@ maintainer-clean: maintainer-clean-am .PHONY: mostlyclean-binPROGRAMS distclean-binPROGRAMS clean-binPROGRAMS \ maintainer-clean-binPROGRAMS uninstall-binPROGRAMS install-binPROGRAMS \ mostlyclean-compile distclean-compile clean-compile \ -maintainer-clean-compile tags mostlyclean-tags distclean-tags \ -clean-tags maintainer-clean-tags distdir mostlyclean-depend \ -distclean-depend clean-depend maintainer-clean-depend info-am info \ -dvi-am dvi check check-am installcheck-am installcheck install-exec-am \ -install-exec install-data-am install-data install-am install \ -uninstall-am uninstall all-redirect all-am all install-strip \ -installdirs mostlyclean-generic distclean-generic clean-generic \ -maintainer-clean-generic clean mostlyclean distclean maintainer-clean +maintainer-clean-compile uninstall-sbinSCRIPTS install-sbinSCRIPTS tags \ +mostlyclean-tags distclean-tags clean-tags maintainer-clean-tags \ +distdir mostlyclean-depend distclean-depend clean-depend \ +maintainer-clean-depend info-am info dvi-am dvi check check-am \ +installcheck-am installcheck install-exec-am install-exec \ +install-data-am install-data install-am install uninstall-am uninstall \ +all-redirect all-am all install-strip installdirs mostlyclean-generic \ +distclean-generic clean-generic maintainer-clean-generic clean \ +mostlyclean distclean maintainer-clean # Tell versions [3.59,3.63) of GNU make to not export all variables. diff --git a/util/grub-install.in b/util/grub-install.in index 34c7db123..5fa9c32b8 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -32,10 +32,11 @@ pkgdatadir=${datadir}/${PACKAGE}/${host_cpu}-${host_vendor} grub_shell=${sbindir}/grub bootdir=/boot grubdir=${bootdir}/grub -device_map=${grub_dir}/device.map +device_map=${grubdir}/device.map log_file=/tmp/grub-install.log.$$ install_device= +debug=no # Usage: usage # Print the usage. @@ -55,6 +56,12 @@ EOF # Convert an OS device to the corresponding GRUB drive. # This part is OS-specific. convert () { + # First, check if the device file exists. + if test ! -e $1; then + echo "$1: Not found." 1>&2 + exit 1 + fi + # Break the device name into the disk part and the partition part. case $host_os in linux*) @@ -64,17 +71,17 @@ convert () { tmp_disk=`echo $1 | sed 's%s[0-9]*[a-g]?%%'` tmp_part=`echo $1 | sed "s%$tmp_disk%%"` ;; *) - echo "grub-install does not support your OS yet." + echo "grub-install does not support your OS yet." 1>&2 exit 1 ;; esac # Get the drive name. tmp_drive=`grep -v '^#' $device_map | grep $tmp_disk \ - | sed 's%.*\(/dev/[a-z0-9]*\).*%\1%'` + | sed 's%.*\(([hf]d[0-9][a-g0-9,]*)\).*%\1%'` # If not found, print an error message and exit. - if "x$tmp_drive" = x; then - echo "$1 does not have any corresponding BIOS drive." + if test "x$tmp_drive" = x; then + echo "$1 does not have any corresponding BIOS drive." 1>&2 exit 1 fi @@ -110,15 +117,42 @@ for option; do -v | --version) echo "grub-install (GNU GRUB ${VERSION})" exit 0 ;; + # This is an undocumented feature... + --debug) + debug=yes ;; *) if test "x$install_device" != x; then usage exit 1 fi - install_device=${option} ;; + install_device="${option}" ;; esac done +# If the debugging feature is enabled, print commands. +if test $debug = yes; then + set -x +fi + +# Check if GRUB is installed +if test ! -f $grub_shell; then + echo "${grub_shell}: Not found." 1>&2 + exit 1 +fi + +if test ! -f $pkgdatadir/stage1; then + echo "${pkgdatadir}/stage1: Not found." 1>&2 + exit 1 +fi + +if test ! -f $pkgdatadir/stage2; then + echo "${pkgdatadir}/stage2: Not found." 1>&2 + exit 1 +fi + +# Don't check for *stage1_5, because it is not fatal even if any +# Stage 1.5 does not exist. + # Create the GRUB directory if it is not present. if test ! -d $bootdir; then mkdir $bootdir @@ -134,28 +168,32 @@ if test ! -f $device_map; then quit EOF if grep "Error: " $log_file >/dev/null; then - cat $log_file + cat $log_file 1>&2 exit 1 fi rm -f $log_file fi -# Copy the GRUB images to the GRUB directory. -rm -f ${grubdir}/stage1 ${grubdir}/stage2 ${grubdir}/*stage1_5 -cp ${pkgdatadir}/stage1 ${pkgdatadir}/stage2 ${pkgdatadir}/*stage1_5 ${grubdir} - # Check for INSTALL_DEVICE. if test "x$install_device" = x; then usage exit 1 -elif echo $install_device | sed 's%^/dev/%%' >/dev/null; then - install_drive=`convert $install_device` -elif echo $install_device | sed 's%^([hf][0-9,]*)$%%' >/dev/null; then - install_drive=$install_device else - usage - exit 1 + 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 # Get the root drive. @@ -163,6 +201,13 @@ fi # this really portable? root_device=`df ${grubdir} | grep /dev/ | sed 's%.*\(/dev/[a-z0-9]*\).*%\1%'` root_drive=`convert $root_device` +if test "x$root_drive" = x; then + exit 1 +fi + +# Copy the GRUB images to the GRUB directory. +rm -f ${grubdir}/stage1 ${grubdir}/stage2 ${grubdir}/*stage1_5 +cp ${pkgdatadir}/stage1 ${pkgdatadir}/stage2 ${pkgdatadir}/*stage1_5 ${grubdir} # Now perform the installation. $grub_shell --batch --device-map=$device_map <$log_file @@ -172,7 +217,7 @@ quit EOF if grep "Error: " $log_file >/dev/null; then - cat $log_file + cat $log_file 1>&2 exit 1 fi