Improve the way deborphan works in /etc/grml/fai/grml/grml_cleanup_chroot.deborphan...
[grml-live.git] / etc / grml / fai / live-initramfs / grml-script.init-top
1 #!/bin/sh
2
3 # helper functions {{{
4
5 if grep -qe debug -qe verbose /proc/cmdline 2>/dev/null ; then
6    echo "debug: scripts/init-top/grml running">/dev/console
7 fi
8
9 # get boot command line
10 CMDLINE="$(cat /proc/cmdline)"
11
12 # Simple shell grep
13 stringinfile(){
14   case "$(cat $2)" in *$1*) return 0;; esac
15   return 1
16 }
17
18 # same for strings
19 stringinstring(){
20   case "$2" in *$1*) return 0;; esac
21   return 1
22 }
23
24 # Reread boot command line; echo last parameter's argument or return false.
25 getbootparam(){
26   stringinstring " $1=" "$CMDLINE" || return 1
27   result="${CMDLINE##*$1=}"
28   result="${result%%[   ]*}"
29   echo "$result"
30   return 0
31 }
32
33 # Check boot commandline for specified option
34 checkbootparam(){
35   stringinstring " $1" "$CMDLINE"
36   return "$?"
37 }
38
39 if checkbootparam "nocolor" ; then
40   echo "Disabling colors in bootsequence as requested on commandline."
41   # Reset fb color mode
42   RESET="\e]R"
43   # ANSI COLORS
44   # Erase to end of line
45   CRE="\r\e[K"
46   # Clear and reset Screen
47   CLEAR="\ec"
48 else
49   # Reset fb color mode
50   RESET="\e]R"
51   # ANSI COLORS
52   # Erase to end of line
53   CRE="\r\e[K"
54   # Clear and reset Screen
55   CLEAR="\ec"
56   # Normal color
57   NORMAL="\e[0;39m"
58   # RED: Failure or error message
59   RED="\e[1;31m"
60   # GREEN: Success message
61   GREEN="\e[1;32m"
62   # YELLOW: Descriptions
63   YELLOW="\e[1;33m"
64   # BLUE: System mesages
65   BLUE="\e[1;34m"
66   # MAGENTA: Found devices or drivers
67   MAGENTA="\e[1;35m"
68   # CYAN: Questions
69   CYAN="\e[1;36m"
70   # BOLD WHITE: Hint
71   WHITE="\e[1;37m"
72 fi
73
74 log_grml_failure_msg () {
75   echo -n " ${RED}*${NORMAL} $@"
76 }
77
78 # int log_grml_begin_message (char *message)
79 log_grml_begin_msg () {
80   echo -n " ${GREEN}*${NORMAL} $@"
81 }
82
83 log_grml_warn_msg () {
84   echo -n " ${YELLOW}*${NORMAL} $@"
85 }
86
87 # int log_grml_end_message (int exitstatus)
88 SUCCESS=" ${BLUE}[ ${GREEN}ok ${BLUE}]${NORMAL}"
89 FAILED=" ${NORMAL}[${RED}fail${NORMAL}]"
90
91 # }}}
92
93 # welcome splash {{{
94
95 DISTRI="$(getbootparam 'distri' 2>/dev/null)"
96
97 if [ -r /etc/grml_version ] ; then
98    GRML_VERSION="$(cat /etc/grml_version)"
99 fi
100
101 if [ -n "$DISTRI" ] ; then
102 SPLASH="
103 ${RED} $DISTRI
104
105 ${WHITE}based on grml.org.
106
107 ${NORMAL}"
108 else
109 SPLASH="
110 ${RED}   ____ ____  __  __ _
111 ${RED}  / ___|  _ \|  \/  | |
112 ${RED} | |  _| |_) | |\/| | |
113 ${RED} | |_| |  _ <| |  | | |___
114 ${RED}  \____|_| \_\_|  |_|_____|
115
116 ${WHITE}grml.org - Linux for sysadmins and texttool users.${NORMAL}"
117 fi
118
119 echo ""
120 echo "${WHITE}Welcome to"
121 echo "$SPLASH"
122 echo
123
124 if [ -n "$GRML_VERSION" ] ; then
125    log_grml_begin_msg "Running $GRML_VERSION"
126    echo
127 fi
128
129 # don't output anything if running with bootsplash feature
130 if checkbootparam "splash" ; then
131   exec >/dev/null </dev/null 2>&1
132 fi
133 # }}}
134
135 ## /proc/cmdline handling {{{
136 # No kernel messages while probing modules:
137 if ! grep -qe debug -qe verbose /proc/cmdline 2>/dev/null ; then
138    [ -r /proc/sys/kernel/printk ] && echo "0" > /proc/sys/kernel/printk
139 fi
140
141 # Make sure we support squashfs:
142 if ! grep -q squashfs /proc/filesystems ; then
143    modprobe -q squashfs || log_grml_failure_msg "Warning: look like you do not have support for squashfs"
144 fi
145
146 if grep -q 'boot=live' /proc/cmdline 2>/dev/null ; then
147    log_grml_begin_msg "Finished early booting sequence." ; echo "$SUCCESS"
148    log_grml_begin_msg "Searching for GRML file, this might take a few seconds..."
149    echo
150 fi
151 ## }}}
152
153 # vim: foldmethod=marker expandtab ai ft=sh