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