X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=debian%2Fgrml-udev-config.grml-udev.init;fp=debian%2Fgrml-udev-config.grml-udev.init;h=56b4a5a5308b49bb2b20355004fd6c950a2d318d;hb=a208bbbf0f6564e8c83083028f1edd06d0f38274;hp=0000000000000000000000000000000000000000;hpb=9011670651c2c711b68a387de0fc3d03bba95397;p=grml-udev-config.git diff --git a/debian/grml-udev-config.grml-udev.init b/debian/grml-udev-config.grml-udev.init new file mode 100644 index 0000000..56b4a5a --- /dev/null +++ b/debian/grml-udev-config.grml-udev.init @@ -0,0 +1,116 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: grml-udev +# Required-Start: mountkernfs +# Required-Stop: +# Should-Start: +# Should-Stop: +# Default-Start: S +# Default-Stop: +# Short-Description: wrapper around udev to support bootoptions noudev and blacklist +### END INIT INFO + +. /lib/lsb/init-functions + +# shell version of /usr/bin/tty +my_tty() { + [ -x /bin/readlink ] || return 0 + [ -e /proc/self/fd/0 ] || return 0 + readlink --silent /proc/self/fd/0 || true +} + +# are we running within init (non_interactive) or within shell (interactive)? +check_for_non_interactive() { + if [ "$RUNLEVEL" = "S" -a "$PREVLEVEL" = "N" ]; then + return + fi + + TTY=$(my_tty) + if [ -z "$TTY" -o "$TTY" = "/dev/console" -o "$TTY" = "/dev/null" ]; then + return + fi + + return 1 +} + +# start init script through official Debian way +udev_exec() { + # avoid syntax error if called without valid parameter: + [ -z "$1" ] && exec /etc/init.d/udev "$1" + + exec /etc/init.d/udev "$1" +} + +# test whether udev is enabled in init's configuration +udev_active() { + # file-rc: + if [ -r /etc/runlevel.conf ] && egrep -q '^[0-9]+.*-.*-.*\/etc\/init.d\/ydev$' /etc/runlevel.conf ; then + return 0 + fi + + # sysv-rc: + if ls /etc/rcS.d/*udev >/dev/null 2>&1 ; then + return 0 + fi + + return 1 +} + +# if original udev init script is enabled to not execute our script +udev_init_check() { + if udev_active ; then + log_warning_msg "Original udev init script is configured for startup, ignoring request to start $0" + return 1 + fi +} + +case "$1" in + start) + # do not flood console with kernel driver messages + # grep -q debug /proc/cmdline || echo 0 > /proc/sys/kernel/printk + + # do not display anything when bootoption *splash is present: + # if grep -qe ' splash' -qe ' tsplash' -qe ' textsplash' /proc/cmdline ; then + # exec >/dev/null &2' ) + else + printf 'Warning: /etc/grml/autoconfig.functions could not be read.\n'>&2 + fi + + # support bootoption noudev and inform user how to skip + # execution of udev (being bootoption noudev) + if ! grep -q noudev /proc/cmdline ; then + check_for_non_interactive && \ + log_warning_msg "If your system hangs now skip execution of udev via bootoption noudev" + else + # - allow execution of initscript through FORCE=1 when booting with noudev + if [ -z "$FORCE" ] ; then + log_failure_msg "Bootoption noudev found. Skipping execution of udev init script." + if ! check_for_non_interactive ; then + printf "\nIt has been detected that the udev init script\n" + printf "has been run from an interactive shell.\n" + printf "You booted your system using bootoption noudev.\n" + printf "To force startup of udev please run:\n\n" + printf "\tFORCE=1 Start udev\n\n" + fi + exit 1 + fi + fi + + udev_init_check && udev_exec start + + ;; + + # in any other situation just directly invoke udev: + *) + udev_init_check && udev_exec "$1" + ;; +esac + +exit 0 + +##############################################################################