#! /bin/sh set -e # Generate VasEBoot.cfg by inspecting /boot contents. # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. # # VAS_EBOOT 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. # # VAS_EBOOT 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 VAS_EBOOT. If not, see . prefix="@prefix@" exec_prefix="@exec_prefix@" datarootdir="@datarootdir@" prefix="@prefix@" exec_prefix="@exec_prefix@" sbindir="@sbindir@" bindir="@bindir@" sysconfdir="@sysconfdir@" PACKAGE_NAME=@PACKAGE_NAME@ PACKAGE_VERSION=@PACKAGE_VERSION@ host_os=@host_os@ datadir="@datadir@" if [ "x$pkgdatadir" = x ]; then pkgdatadir="${datadir}/@PACKAGE@" fi # export it for scripts export pkgdatadir VasEBoot_cfg="" VasEBoot_mkconfig_dir="${sysconfdir}"/VasEBoot.d self=`basename $0` VasEBoot_probe="${sbindir}/@VasEBoot_probe@" VasEBoot_file="${bindir}/@VasEBoot_file@" VasEBoot_editenv="${bindir}/@VasEBoot_editenv@" VasEBoot_script_check="${bindir}/@VasEBoot_script_check@" export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR="@localedir@" . "${pkgdatadir}/VasEBoot-mkconfig_lib" # Usage: usage # Print the usage. usage () { gettext_printf "Usage: %s [OPTION]\n" "$self" gettext "Generate a VasEBoot config file"; echo echo print_option_help "-o, --output=$(gettext FILE)" "$(gettext "output generated config to FILE [default=stdout]")" print_option_help "-h, --help" "$(gettext "print this message and exit")" print_option_help "-V, --version" "$(gettext "print the version information and exit")" echo gettext "Report bugs to ."; echo } argument () { opt=$1 shift if test $# -eq 0; then gettext_printf "%s: option requires an argument -- \`%s'\n" "$self" "$opt" 1>&2 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 ;; -o | --output) VasEBoot_cfg=`argument $option "$@"`; shift;; --output=*) VasEBoot_cfg=`echo "$option" | sed 's/--output=//'` ;; -*) gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2 usage exit 1 ;; # Explicitly ignore non-option arguments, for compatibility. esac done if [ "x$EUID" = "x" ] ; then EUID=`id -u` fi if [ "$EUID" != 0 ] ; then root=f case "`uname 2>/dev/null`" in CYGWIN*) # Cygwin: Assume root if member of admin group for g in `id -G 2>/dev/null` ; do case $g in 0|544) root=t ;; esac done ;; esac if [ $root != t ] ; then gettext_printf "%s: You must run this as root\n" "$self" >&2 exit 1 fi fi set $VasEBoot_probe dummy if test -f "$1"; then : else gettext_printf "%s: Not found.\n" "$1" 1>&2 exit 1 fi # Device containing our userland. Typically used for root= parameter. VAS_EBOOT_DEVICE="`${VasEBoot_probe} --target=device /`" VAS_EBOOT_DEVICE_UUID="`${VasEBoot_probe} --device ${VAS_EBOOT_DEVICE} --target=fs_uuid 2> /dev/null`" || true VAS_EBOOT_DEVICE_PARTUUID="`${VasEBoot_probe} --device ${VAS_EBOOT_DEVICE} --target=partuuid 2> /dev/null`" || true # Device containing our /boot partition. Usually the same as VAS_EBOOT_DEVICE. VAS_EBOOT_DEVICE_BOOT="`${VasEBoot_probe} --target=device /boot`" VAS_EBOOT_DEVICE_BOOT_UUID="`${VasEBoot_probe} --device ${VAS_EBOOT_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true # Disable os-prober by default due to security reasons. VAS_EBOOT_DISABLE_OS_PROBER="true" # Filesystem for the device containing our userland. Used for stuff like # choosing Hurd filesystem module. VAS_EBOOT_FS="`${VasEBoot_probe} --device ${VAS_EBOOT_DEVICE} --target=fs 2> /dev/null || echo unknown`" if [ x"$VAS_EBOOT_FS" = xunknown ]; then VAS_EBOOT_FS="$(stat -f -c %T / || echo unknown)" fi # Provide a default set of stock linux early initrd images. # Define here so the list can be modified in the sourced config file. if [ "x${VAS_EBOOT_EARLY_INITRD_LINUX_STOCK}" = "x" ]; then VAS_EBOOT_EARLY_INITRD_LINUX_STOCK="intel-uc.img intel-ucode.img amd-uc.img amd-ucode.img early_ucode.cpio microcode.cpio" fi if test -f ${sysconfdir}/default/VasEBoot ; then . ${sysconfdir}/default/VasEBoot fi if [ "x${VAS_EBOOT_DISABLE_UUID}" = "xtrue" ]; then if [ -z "${VAS_EBOOT_DISABLE_LINUX_UUID}" ]; then VAS_EBOOT_DISABLE_LINUX_UUID="true" fi if [ -z "${VAS_EBOOT_DISABLE_LINUX_PARTUUID}" ]; then VAS_EBOOT_DISABLE_LINUX_PARTUUID="true" fi fi # XXX: should this be deprecated at some point? if [ "x${VAS_EBOOT_TERMINAL}" != "x" ] ; then VAS_EBOOT_TERMINAL_INPUT="${VAS_EBOOT_TERMINAL}" VAS_EBOOT_TERMINAL_OUTPUT="${VAS_EBOOT_TERMINAL}" fi termoutdefault=0 if [ "x${VAS_EBOOT_TERMINAL_OUTPUT}" = "x" ]; then VAS_EBOOT_TERMINAL_OUTPUT=gfxterm; termoutdefault=1; fi for x in ${VAS_EBOOT_TERMINAL_OUTPUT}; do case "x${x}" in xgfxterm) ;; xconsole | xserial | xofconsole | xvga_text) # make sure all our children behave in conformance with ascii.. export LANG=C;; *) echo "Invalid output terminal \"${VAS_EBOOT_TERMINAL_OUTPUT}\"" >&2 ; exit 1 ;; esac done VAS_EBOOT_ACTUAL_DEFAULT="$VAS_EBOOT_DEFAULT" if [ "x${VAS_EBOOT_ACTUAL_DEFAULT}" = "xsaved" ] ; then VAS_EBOOT_ACTUAL_DEFAULT="`"${VasEBoot_editenv}" - list | sed -n '/^saved_entry=/ s,^saved_entry=,,p'`" ; fi # These are defined in this script, export them here so that user can # override them. export VAS_EBOOT_DEVICE \ VAS_EBOOT_DEVICE_UUID \ VAS_EBOOT_DEVICE_PARTUUID \ VAS_EBOOT_DEVICE_BOOT \ VAS_EBOOT_DEVICE_BOOT_UUID \ VAS_EBOOT_DISABLE_OS_PROBER \ VAS_EBOOT_FS \ VAS_EBOOT_FONT \ VAS_EBOOT_PRELOAD_MODULES \ VAS_EBOOT_ACTUAL_DEFAULT # These are optional, user-defined variables. export VAS_EBOOT_DEFAULT \ VAS_EBOOT_HIDDEN_TIMEOUT \ VAS_EBOOT_HIDDEN_TIMEOUT_QUIET \ VAS_EBOOT_TIMEOUT \ VAS_EBOOT_TIMEOUT_STYLE \ VAS_EBOOT_DEFAULT_BUTTON \ VAS_EBOOT_HIDDEN_TIMEOUT_BUTTON \ VAS_EBOOT_TIMEOUT_BUTTON \ VAS_EBOOT_TIMEOUT_STYLE_BUTTON \ VAS_EBOOT_BUTTON_CMOS_ADDRESS \ VAS_EBOOT_BUTTON_CMOS_CLEAN \ VAS_EBOOT_DISTRIBUTOR \ VAS_EBOOT_CMDLINE_LINUX \ VAS_EBOOT_CMDLINE_LINUX_DEFAULT \ VAS_EBOOT_CMDLINE_LINUX_RECOVERY \ VAS_EBOOT_CMDLINE_XEN \ VAS_EBOOT_CMDLINE_XEN_DEFAULT \ VAS_EBOOT_CMDLINE_LINUX_XEN_REPLACE \ VAS_EBOOT_CMDLINE_LINUX_XEN_REPLACE_DEFAULT \ VAS_EBOOT_CMDLINE_NETBSD \ VAS_EBOOT_CMDLINE_NETBSD_DEFAULT \ VAS_EBOOT_CMDLINE_GNUMACH \ VAS_EBOOT_TOP_LEVEL \ VAS_EBOOT_TOP_LEVEL_XEN \ VAS_EBOOT_TOP_LEVEL_OS_PROBER \ VAS_EBOOT_EARLY_INITRD_LINUX_CUSTOM \ VAS_EBOOT_EARLY_INITRD_LINUX_STOCK \ VAS_EBOOT_TERMINAL_INPUT \ VAS_EBOOT_TERMINAL_OUTPUT \ VAS_EBOOT_SERIAL_COMMAND \ VAS_EBOOT_DISABLE_UUID \ VAS_EBOOT_DISABLE_LINUX_UUID \ VAS_EBOOT_DISABLE_LINUX_PARTUUID \ VAS_EBOOT_DISABLE_RECOVERY \ VAS_EBOOT_VIDEO_BACKEND \ VAS_EBOOT_GFXMODE \ VAS_EBOOT_BACKGROUND \ VAS_EBOOT_THEME \ VAS_EBOOT_GFXPAYLOAD_LINUX \ VAS_EBOOT_INIT_TUNE \ VAS_EBOOT_SAVEDEFAULT \ VAS_EBOOT_ENABLE_CRYPTODISK \ VAS_EBOOT_BADRAM \ VAS_EBOOT_OS_PROBER_SKIP_LIST \ VAS_EBOOT_DISABLE_SUBMENU \ VAS_EBOOT_FORCE_EFI_ALL_VIDEO if test "x${VasEBoot_cfg}" != "x"; then rm -f "${VasEBoot_cfg}.new" oldumask=$(umask); umask 077 exec > "${VasEBoot_cfg}.new" umask $oldumask fi gettext "Generating VasEBoot configuration file ..." >&2 echo >&2 cat << EOF # # DO NOT EDIT THIS FILE # # It is automatically generated by $self using templates # from ${VasEBoot_mkconfig_dir} and settings from ${sysconfdir}/default/VasEBoot # EOF for i in "${VasEBoot_mkconfig_dir}"/* ; do case "$i" in # emacsen backup files. FIXME: support other editors *~) ;; # emacsen autosave files. FIXME: support other editors */\#*\#) ;; *) if VasEBoot_file_is_not_garbage "$i" && test -x "$i" ; then echo echo "### BEGIN $i ###" "$i" echo "### END $i ###" fi ;; esac done if test "x${VasEBoot_cfg}" != "x" ; then if ! ${VasEBoot_script_check} ${VasEBoot_cfg}.new; then # TRANSLATORS: %s is replaced by filename gettext_printf "Syntax errors are detected in generated VAS_EBOOT config file. Ensure that there are no errors in /etc/default/VasEBoot and /etc/VasEBoot.d/* files or please file a bug report with %s file attached." "${VasEBoot_cfg}.new" >&2 echo >&2 exit 1 else # none of the children aborted with error, install the new VasEBoot.cfg oldumask=$(umask) umask 077 cat ${VasEBoot_cfg}.new > ${VasEBoot_cfg} umask $oldumask rm -f ${VasEBoot_cfg}.new fi fi gettext "done" >&2 echo >&2