Drop NAME="%k" from debian/grml-udev-config.grml-usbdev.udev
[grml-udev-config.git] / debian / grml-udev-config.init
1 #!/bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          grml-udev-config
4 # Required-Start:    mountkernfs
5 # Required-Stop:
6 # Should-Start:
7 # Should-Stop:
8 # Default-Start:     S
9 # Default-Stop:
10 # Short-Description: wrapper around udev to support bootoptions noudev and blacklist
11 ### END INIT INFO
12
13 . /lib/lsb/init-functions
14
15 # are we running within init (non_interactive) or within shell (interactive)?
16 check_for_non_interactive() {
17   if [ "$RUNLEVEL" = "S" -a "$PREVLEVEL" = "N" ]; then
18     return
19   fi
20
21   TTY=$(my_tty)
22   if [ -z "$TTY" -o "$TTY" = "/dev/console" -o "$TTY" = "/dev/null" ]; then
23     return
24   fi
25
26   return 1
27 }
28
29 exec_wrapper() {
30   if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
31     invoke-rc.d $1 $2
32   else
33     /etc/init.d/$1 $2
34   fi
35 }
36
37 udev_init_check() {
38   # test whether udev is enabled in init's configuration
39   # if so do not execute our script but instead use original
40   # udev init script only
41   if update-rc.d -n udev start 3 S >/dev/null ; then
42     log_warning_msg "Original udev init script is configured for startup, ignoring request to start $0"
43     return 1
44   fi
45
46   return 0
47 }
48
49 case "$1" in
50   start)
51         # do not flood console with kernel driver messages
52         # grep -q debug /proc/cmdline || echo 0 > /proc/sys/kernel/printk
53
54         # do not display anything when bootoption *splash is present:
55         # if grep -qe ' splash' -qe ' tsplash' -qe ' textsplash' /proc/cmdline ; then
56         #   exec >/dev/null </dev/null
57         # fi
58
59         # support bootoption blacklist, must be executed *before* udev is present
60         if [ -r /etc/grml/autoconfig.functions ] ; then
61           ( zsh -c '. /etc/grml/autoconfig.functions && config_blacklist || printf "Error when trying to run config_blacklist.\n">&2' )
62         else
63           printf 'Warning: /etc/grml/autoconfig.functions could not be read.\n'>&2
64         fi
65
66         # support bootoption noudev and inform user how to skip
67         # execution of udev (being bootoption noudev)
68         if ! grep -q noudev /proc/cmdline ; then
69            check_for_non_interactive && \
70               log_warning_msg "If your system hangs now skip execution of udev via bootoption noudev"
71         else
72            # - allow execution of initscript through FORCE=1 when booting with noudev
73            if [ -z "$FORCE" ] ; then
74               log_failure_msg "Bootoption noudev found. Skipping execution of udev init script."
75               if ! check_for_non_interactive ; then
76                  printf "\nIt has been detected that the udev init script\n"
77                  printf "has been run from an interactive shell.\n"
78                  printf "You booted your system using bootoption noudev.\n"
79                  printf "To force startup of udev please run:\n\n"
80                  printf "\tFORCE=1 Start udev\n\n"
81               fi
82               exit 1
83            fi
84         fi
85
86         udev_init_check && exec_wrapper udev start
87
88         ;;
89
90   # in any other situation just directly invoke udev:
91   *)
92         udev_init_check && exec_wrapper udev $1
93         ;;
94 esac
95
96 exit 0
97
98 ##############################################################################