>> 3.0.2c. Added more PCMCIA modules to the x86 module list; and added the bug
[genkernel.git] / gen_funcs.sh
1 #!/bin/bash
2
3 isTrue() {
4         case "$1" in
5                 [Tt][Rr][Uu][Ee])
6                         return 0
7                 ;;
8                 [Tt])
9                         return 0
10                 ;;
11                 [Yy][Ee][Ss])
12                         return 0
13                 ;;
14                 [Yy])
15                         return 0
16                 ;;
17                 1)
18                         return 0
19                 ;;
20         esac
21         return 1
22 }
23
24 if isTrue ${USECOLOR}
25 then
26         GOOD=$'\e[32;01m'
27         WARN=$'\e[33;01m'
28         BAD=$'\e[31;01m'
29         NORMAL=$'\e[0m'
30         BOLD=$'\e[0;01m'
31         UNDER=$'\e[4m'
32 else
33         GOOD=''
34         WARN=''
35         BAD=''
36         NORMAL=''
37         BOLD=''
38         UNDER=''
39 fi
40
41 # print_info(debuglevel, print [, newline [, prefixline [, forcefile ] ] ])
42 print_info() {
43         local NEWLINE=1
44         local FORCEFILE=0
45         local PREFIXLINE=1
46         local SCRPRINT=0
47         local STR=''
48
49         # NOT ENOUGH ARGS
50         if [ "$#" -lt '2' ] ; then return 1; fi
51
52         # IF 3 OR MORE ARGS, CHECK IF WE WANT A NEWLINE AFTER PRINT
53         if [ "$#" -gt '2' ]
54         then
55                 if isTrue "$3"
56                 then
57                         NEWLINE='1';
58                 else
59                         NEWLINE='0';
60                 fi
61         fi
62
63         # IF 4 OR MORE ARGS, CHECK IF WE WANT TO PREFIX WITH A *
64         if [ "$#" -gt '3' ]
65         then
66                 if isTrue "$4"
67                 then
68                         PREFIXLINE='1'
69                 else
70                         PREFIXLINE='0'
71                 fi
72         fi
73
74         # IF 5 OR MORE ARGS, CHECK IF WE WANT TO FORCE OUTPUT TO DEBUG
75         # FILE EVEN IF IT DOESN'T MEET THE MINIMUM DEBUG REQS
76         if [ "$#" -gt '4' ]
77         then
78                 if isTrue "$5"
79                 then
80                         FORCEFILE='1'
81                 else
82                         FORCEFILE='0'
83                 fi
84         fi
85
86         # PRINT TO SCREEN ONLY IF PASSED DEBUGLEVEL IS HIGHER THAN
87         # OR EQUAL TO SET DEBUG LEVEL
88         if [ "$1" -lt "${DEBUGLEVEL}" -o "$1" -eq "${DEBUGLEVEL}" ]
89         then
90                 SCRPRINT='1'
91         fi
92
93         # RETURN IF NOT OUTPUTTING ANYWHERE
94         if [ "${SCRPRINT}" != '1' -a "${FORCEFILE}" != '1' ]
95         then
96                 return 0
97         fi
98
99         # STRUCTURE DATA TO BE OUTPUT TO SCREEN, AND OUTPUT IT
100         if [ "${SCRPRINT}" -eq '1' ]
101         then
102                 if [ "${PREFIXLINE}" = '1' ]
103                 then
104                         STR="${GOOD}*${NORMAL} ${2}"
105                 else
106                         STR="${2}"
107                 fi
108
109                 if [ "${NEWLINE}" = '0' ]
110                 then
111                         echo -ne "${STR}"
112                 else
113                         echo "${STR}"
114                 fi
115         fi
116
117         # STRUCTURE DATA TO BE OUTPUT TO FILE, AND OUTPUT IT
118         if [ "${SCRPRINT}" -eq '1' -o "${FORCEFILE}" -eq '1' ]
119         then
120                 STRR=${2//${WARN}/}
121                 STRR=${STRR//${BAD}/}
122                 STRR=${STRR//${BOLD}/}
123                 STRR=${STRR//${NORMAL}/}
124
125                 if [ "${PREFIXLINE}" = '1' ]
126                 then
127                         STR="* ${STRR}"
128                 else
129                         STR="${STRR}"
130                 fi
131
132                 if [ "${NEWLINE}" = '0' ]
133                 then
134                         echo -ne "${STR}" >> ${DEBUGFILE}
135                 else
136                         echo "${STR}" >> ${DEBUGFILE}
137                 fi
138         fi
139
140         return 0
141 }
142
143 print_error()
144 {
145         GOOD=${BAD} print_info "$@"
146 }
147
148 print_warning()
149 {
150         GOOD=${WARN} print_info "$@"
151 }
152
153 # var_replace(var_name, var_value, string)
154 # $1 = variable name
155 # $2 = variable value
156 # $3 = string
157
158 var_replace()
159 {
160   echo "${3}" | sed -e "s/%%${1}%%/${2}/g" -
161 }
162
163 arch_replace() {
164   var_replace "ARCH" "${ARCH}" "${1}"
165 }
166
167 clear_log() {
168   rm -f ${DEBUGFILE}
169   touch ${DEBUGFILE}
170 }
171
172 gen_die() {
173         if [ "$#" -gt '0' ]
174         then
175                 print_error 1 "ERROR: ${1}"
176         fi
177         echo
178         print_info 1 "-- Grepping log... --"
179         echo
180
181         if isTrue ${USECOLOR}
182         then
183                 GREP_COLOR='1' grep -B5 -E --colour=always "([Ww][Aa][Rr][Nn][Ii][Nn][Gg]|[Ee][Rr][Rr][Oo][Rr][ :,!]|[Ff][Aa][Ii][Ll][Ee]?[Dd]?)" ${DEBUGFILE}
184         else
185                 grep -B5 -E "([Ww][Aa][Rr][Nn][Ii][Nn][Gg]|[Ee][Rr][Rr][Oo][Rr][ :,!]|[Ff][Aa][Ii][Ll][Ee]?[Dd]?)" ${DEBUGFILE}
186         fi
187         echo
188         print_info 1 "-- End log... --"
189         echo
190         print_info 1 "Please consult ${DEBUGFILE} for more information and any"
191         print_info 1 "errors that were reported above."
192         echo
193         print_info 1 "Report any genkernel bugs to bugs.gentoo.org and"
194         print_info 1 "assign your bug to genkernel@gentoo.org. Please include"
195         print_info 1 "as much information as you can in your bug report; attaching"
196         print_info 1 "${DEBUGFILE} so that your issue can be dealt with effectively."
197         print_info 1 ''
198         print_info 1 'Please do *not* report compilation failures as genkernel bugs!'
199         print_info 1 ''
200         exit 1
201 }
202
203 has_loop() {
204         dmesg | egrep -q '^loop:'
205         if [ -e '/dev/loop0' -o -e '/dev/loop/0' -a $? ]
206         then
207                 # We found devfs or standard dev loop device, assume
208                 # loop is compiled into the kernel or the module is loaded
209                 return 0
210         else
211                 return 1
212         fi
213 }
214
215 isBootRO()
216 {
217         for mo in `grep ' /boot ' /proc/mounts | cut -d ' ' -f 4 | sed -e 's/,/ /'`
218         do
219                 if [ "x${mo}x" == "xrox" ]
220                 then
221                         return 0
222                 fi
223         done
224         return 1
225 }