/etc/grml/lsb-functions: set RC_NOCOLOR if nocolor string is present in /proc/cmdline
[grml-etc-core.git] / etc / grml / lsb-functions
1 # lsb init-functions {{{
2 # /lib/lsb/init-functions for Debian -*- shell-script -*-
3 #
4 # Copyright (c) 2002-03 Chris Lawrence
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 #    notice, this list of conditions and the following disclaimer in the
14 #    documentation and/or other materials provided with the distribution.
15 # 3. Neither the name of the author nor the names of other contributors
16 #    may be used to endorse or promote products derived from this software
17 #    without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 # SUCH DAMAGE.
30
31 log_success_msg () {
32     echo " * $@"
33 }
34
35 log_failure_msg () {
36     TPUT=/usr/bin/tput
37     if [ -x $TPUT ] && $TPUT hpa 60 >/dev/null 2>&1; then
38         RED=`$TPUT setaf 1`
39         #NORMAL=`$TPUT op`
40         echo " ${RED}*${NORMAL} $@"
41     else
42         echo " * $@"
43     fi
44 }
45
46 log_warning_msg () {
47     TPUT=/usr/bin/tput
48     if [ -x $TPUT ] && $TPUT hpa 60 >/dev/null 2>&1; then
49         YELLOW=`$TPUT setaf 3`
50         #NORMAL=`$TPUT op`
51         # echo " *${NORMAL} $@"
52         echo " ${BLUE}*${NORMAL} $@"
53     else
54         echo " * $@"
55     fi
56 }
57
58 log_warning_msg_nn () {
59     TPUT=/usr/bin/tput
60     if [ -x $TPUT ] && $TPUT hpa 60 >/dev/null 2>&1; then
61         YELLOW=`$TPUT setaf 3`
62         echo -n " ${BLUE}*${NORMAL} $@"
63     else
64         echo -n " * $@"
65     fi
66 }
67
68 # int log_begin_message (char *message)
69 log_begin_msg () {
70         if [ -z "$1" ]; then
71                 return 1
72         fi
73         echo " ${GREEN}*${NORMAL} $@"
74 }
75
76 log_begin_msg_nn () {
77         if [ -z "$1" ]; then
78                 return 1
79         fi
80         echo -n " ${GREEN}*${NORMAL} $@"
81 }
82
83
84 SUBMSG="   ${GREEN}-${NORMAL} "
85   
86 # int log_end_message (int exitstatus)
87 log_end_msg () {
88
89     # If no arguments were passed, return
90     [ -z "$1" ] && return 1
91
92     # Only do the fancy stuff if we have an appropriate terminal
93     # and if /usr is already mounted
94     TPUT=/usr/bin/tput
95     EXPR=/usr/bin/expr
96     if [ -x $TPUT ] && [ -x $EXPR ] && $TPUT hpa 60 >/dev/null 2>&1; then
97         COLS=`$TPUT cols`
98         if [ -n "$COLS" ]; then
99             COL=`$EXPR $COLS - 7`
100         else
101             COL=73
102         fi
103         UP=`$TPUT cuu1`
104         END=`$TPUT hpa $COL`
105         START=`$TPUT hpa 0`
106         #RED=`$TPUT setaf 1`
107         #NORMAL=`$TPUT op`
108         if [ $1 -eq 0 ]; then
109             echo "$UP$END${BLUE}[ ${GREEN}ok ${BLUE}]${NORMAL}"
110         else
111             echo -e "${UP}${START} ${RED}*${NORMAL}${END}[${RED}fail${NORMAL}]"
112         fi
113     else
114         if [ $1 -eq 0 ]; then
115             echo "   ...done."
116         else
117             echo "   ...fail!"
118         fi
119     fi
120     return $1
121 }
122
123 # void esyslog(char* priority, char* tag, char* message)
124 #    use the system logger to log a message
125 #esyslog() {
126 #        local pri=
127 #        local tag=
128 #
129 #        if [ -x /usr/bin/logger ]
130 #        then
131 #                pri="$1"
132 #                tag="$2"
133 #
134 #                shift 2
135 #                [[ -z "$*" ]] && return 0
136 #
137 #                /usr/bin/logger -p "${pri}" -t "${tag}" -- "$*"
138 #        fi
139 #
140 #        return 0
141 #}
142
143 # Copyright 1999-2005 Gentoo Foundation
144 # Distributed under the terms of the GNU General Public License v2
145 # $Header: /var/cvsroot/gentoo-src/rc-scripts/sbin/functions.sh,v 1.81.2.6 2005/05/15 20:00:31 vapier Exp $
146
147 RC_GOT_FUNCTIONS="yes"
148
149 # Different types of dependencies
150 deptypes="need use"
151 # Different types of order deps
152 ordtypes="before after"
153
154 #
155 # Internal variables
156 #
157
158 # Dont output to stdout?
159 RC_QUIET_STDOUT="no"
160 RC_VERBOSE="${RC_VERBOSE:-no}"
161
162 # Should we use color?
163 if [ -r /proc/cmdline ] ; then
164    grep -q ' nocolor' /proc/cmdline && RC_NOCOLOR='yes'
165 fi
166 RC_NOCOLOR="${RC_NOCOLOR:-no}"
167 # Can the terminal handle endcols?
168 RC_ENDCOL="yes"
169
170 #
171 # Default values for rc system
172 #
173 RC_TTY_NUMBER=11
174 RC_NET_STRICT_CHECKING="no"
175 RC_PARALLEL_STARTUP="no"
176 RC_USE_CONFIG_PROFILE="yes"
177
178 #
179 # Default values for e-message indentation and dots
180 #
181 RC_INDENTATION=''
182 RC_DEFAULT_INDENT=2
183 #RC_DOT_PATTERN=' .'
184 RC_DOT_PATTERN=''
185
186 # void splash(...)
187 #
188 #  Notify bootsplash/splashutils/gensplash/whatever about
189 #  important events.
190 #
191 splash() {
192         return 0
193 }
194
195 # void profiling(...)
196 #
197 #  Notify bootsplash/whatever about important events.
198 #
199 profiling() {
200         return 0
201 }
202
203 # void get_bootconfig()
204 #
205 #    Get the BOOTLEVEL and SOFTLEVEL by setting
206 #    'bootlevel' and 'softlevel' via kernel
207 #    parameters.
208 #
209 get_bootconfig() {
210         local copt=
211         local newbootlevel=
212         local newsoftlevel=
213
214         for copt in $(</proc/cmdline) ; do
215                 case "${copt%=*}" in
216                         "bootlevel")
217                                 newbootlevel="${copt##*=}"
218                                 ;;
219                         "softlevel")
220                                 newsoftlevel="${copt##*=}"
221                                 ;;
222                 esac
223         done
224
225         if [ -n "${newbootlevel}" ] ; then
226                 export BOOTLEVEL="${newbootlevel}"
227         else
228                 export BOOTLEVEL="boot"
229         fi
230
231         if [ -n "${newsoftlevel}" ] ; then
232                 export DEFAULTLEVEL="${newsoftlevel}"
233         else
234                 export DEFAULTLEVEL="default"
235         fi
236
237         return 0
238 }
239
240 # void get_libdir(void)
241 #
242 #    prints the current libdir {lib,lib32,lib64}
243 #
244 get_libdir() {
245         if [ -n "${CONF_LIBDIR_OVERRIDE}" ] ; then
246                 CONF_LIBDIR="${CONF_LIBDIR_OVERRIDE}"
247         elif [ -x "/usr/bin/portageq" ] ; then
248                 CONF_LIBDIR="$(/usr/bin/portageq envvar CONF_LIBDIR)"
249         fi
250         echo ${CONF_LIBDIR:=lib}
251 }
252
253 # void esyslog(char* priority, char* tag, char* message)
254 #
255 #    use the system logger to log a message
256 #
257 esyslog() {
258         local pri=
259         local tag=
260
261         if [ -x /usr/bin/logger ]
262         then
263                 pri="$1"
264                 tag="$2"
265
266                 shift 2
267                 [[ -z "$*" ]] && return 0
268
269                 /usr/bin/logger -p "${pri}" -t "${tag}" -- "$*"
270         fi
271
272         return 0
273 }
274
275 # void eindent(int num)
276 #
277 #    increase the indent used for e-commands.
278 #
279 eindent() {
280         local i=$1
281         (( i > 0 )) || (( i = RC_DEFAULT_INDENT ))
282         esetdent $(( ${#RC_INDENTATION} + i ))
283 }
284
285 # void eoutdent(int num)
286 #
287 #    decrease the indent used for e-commands.
288 #
289 eoutdent() {
290         local i=$1
291         (( i > 0 )) || (( i = RC_DEFAULT_INDENT ))
292         esetdent $(( ${#RC_INDENTATION} - i ))
293 }
294
295 # void esetdent(int num)
296 #
297 #    hard set the indent used for e-commands.
298 #    num defaults to 0
299 #
300 esetdent() {
301         local i=$1
302         (( i < 0 )) && (( i = 0 ))
303         RC_INDENTATION=$(printf "%${i}s" '')
304 }
305
306 # void einfo(char* message)
307 #
308 #    show an informative message (with a newline)
309 #
310 einfo() {
311         einfon "$*\n"
312         LAST_E_CMD=einfo
313         return 0
314 }
315
316 # void einfon(char* message)
317 #
318 #    show an informative message (without a newline)
319 #
320 einfon() {
321         [[ ${RC_QUIET_STDOUT} == yes ]] && return 0
322         [[ ${RC_ENDCOL} != yes && ${LAST_E_CMD} == ebegin ]] && echo
323         echo -ne " ${GOOD}*${NORMAL} ${RC_INDENTATION}$*"
324         LAST_E_CMD=einfon
325         return 0
326 }
327
328 # void ewarn(char* message)
329 #
330 #    show a warning message + log it
331 #
332 ewarn() {
333         if [[ ${RC_QUIET_STDOUT} == yes ]]; then
334                 echo " $*"
335         else
336                 [[ ${RC_ENDCOL} != yes && ${LAST_E_CMD} == ebegin ]] && echo
337                 echo -e " ${WARN}*${NORMAL} ${RC_INDENTATION}$*"
338         fi
339
340         # Log warnings to system log
341         esyslog "daemon.warning" "rc-scripts" "$*"
342
343         LAST_E_CMD=ewarn
344         return 0
345 }
346
347 # void eerror(char* message)
348 #
349 #    show an error message + log it
350 #
351 eerror() {
352         if [[ ${RC_QUIET_STDOUT} == yes ]]; then
353                 echo " $*" >/dev/stderr
354         else
355                 [[ ${RC_ENDCOL} != yes && ${LAST_E_CMD} == ebegin ]] && echo
356                 echo -e " ${BAD}*${NORMAL} ${RC_INDENTATION}$*"
357         fi
358
359         # Log errors to system log
360         esyslog "daemon.err" "rc-scripts" "$*"
361
362         LAST_E_CMD=eerror
363         return 0
364 }
365
366 # void ebegin(char* message)
367 #
368 #    show a message indicating the start of a process
369 #
370 ebegin() {
371         local msg="$*" dots spaces=${RC_DOT_PATTERN//?/ }
372         [[ ${RC_QUIET_STDOUT} == yes ]] && return 0
373
374         if [[ -n ${RC_DOT_PATTERN} ]]; then
375                 dots=$(printf "%$(( COLS - 3 - ${#RC_INDENTATION} - ${#msg} - 7 ))s" '')
376                 dots=${dots//${spaces}/${RC_DOT_PATTERN}}
377                 msg="${msg}${dots}"
378         else
379                 msg="${msg} ..."
380         fi
381         einfon "${msg}"
382         [[ ${RC_ENDCOL} == yes ]] && echo
383
384         LAST_E_LEN=$(( 3 + ${#RC_INDENTATION} + ${#msg} ))
385         LAST_E_CMD=ebegin
386         return 0
387 }
388
389 # void _eend(int error, char *efunc, char* errstr)
390 #
391 #    indicate the completion of process, called from eend/ewend
392 #    if error, show errstr via efunc
393 #
394 #    This function is private to functions.sh.  Do not call it from a
395 #    script.
396 #
397 _eend() {
398         local retval=${1:-0} efunc=${2:-eerror} msg
399         shift 2
400
401         if [[ ${retval} == 0 ]]; then
402                 [[ ${RC_QUIET_STDOUT} == yes ]] && return 0
403                 msg="${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}"
404         else
405                 if [[ -n "$*" ]]; then
406                         ${efunc} "$*"
407                 fi
408                 msg="${BRACKET}[ ${BAD}!!${BRACKET} ]${NORMAL}"
409         fi
410
411         if [[ ${RC_ENDCOL} == yes ]]; then
412                 echo -e "${ENDCOL}  ${msg}"
413         else
414                 [[ ${LAST_E_CMD} == ebegin ]] || LAST_E_LEN=0
415                 printf "%$(( COLS - LAST_E_LEN - 6 ))s%b\n" '' "${msg}"
416         fi
417
418         return ${retval}
419 }
420
421 # void eend(int error, char* errstr)
422 #
423 #    indicate the completion of process
424 #    if error, show errstr via eerror
425 #
426 eend() {
427         local retval=${1:-0}
428         shift
429
430         _eend ${retval} eerror "$*"
431
432         LAST_E_CMD=eend
433         return $retval
434 }
435
436 # void ewend(int error, char* errstr)
437 #
438 #    indicate the completion of process
439 #    if error, show errstr via ewarn
440 #
441 ewend() {
442         local retval=${1:-0}
443         shift
444
445         _eend ${retval} ewarn "$*"
446
447         LAST_E_CMD=ewend
448         return $retval
449 }
450
451 # v-e-commands honor RC_VERBOSE which defaults to no.
452 # The condition is negated so the return value will be zero.
453 veinfo() { [[ "${RC_VERBOSE}" != yes ]] || einfo "$@"; }
454 veinfon() { [[ "${RC_VERBOSE}" != yes ]] || einfon "$@"; }
455 vewarn() { [[ "${RC_VERBOSE}" != yes ]] || ewarn "$@"; }
456 veerror() { [[ "${RC_VERBOSE}" != yes ]] || eerror "$@"; }
457 vebegin() { [[ "${RC_VERBOSE}" != yes ]] || ebegin "$@"; }
458 veend() {
459         [[ "${RC_VERBOSE}" == yes ]] && { eend "$@"; return $?; }
460         return ${1:-0}
461 }
462 veend() {
463         [[ "${RC_VERBOSE}" == yes ]] && { ewend "$@"; return $?; }
464         return ${1:-0}
465 }
466
467 # char *KV_major(string)
468 #
469 #    Return the Major (X of X.Y.Z) kernel version
470 #
471 KV_major() {
472         [[ -z $1 ]] && return 1
473
474         local KV=$@
475         echo ${KV%%.*}
476 }
477
478 # char *KV_minor(string)
479 #
480 #    Return the Minor (Y of X.Y.Z) kernel version
481 #
482 KV_minor() {
483         [[ -z $1 ]] && return 1
484
485         local KV=$@
486         KV=${KV#*.}
487         echo ${KV%%.*}
488 }
489
490 # char *KV_micro(string)
491 #
492 #    Return the Micro (Z of X.Y.Z) kernel version.
493 #
494 KV_micro() {
495         [[ -z $1 ]] && return 1
496
497         local KV=$@
498         KV=${KV#*.*.}
499         echo ${KV%%[^[:digit:]]*}
500 }
501
502 # int KV_to_int(string)
503 #
504 #    Convert a string type kernel version (2.4.0) to an int (132096)
505 #    for easy compairing or versions ...
506 #
507 KV_to_int() {
508         [[ -z $1 ]] && return 1
509
510         local KV_MAJOR=$(KV_major "$1")
511         local KV_MINOR=$(KV_minor "$1")
512         local KV_MICRO=$(KV_micro "$1")
513         local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO ))
514
515         # We make version 2.2.0 the minimum version we will handle as
516         # a sanity check ... if its less, we fail ...
517         if [[ ${KV_int} -ge 131584 ]] ; then
518                 echo "${KV_int}"
519                 return 0
520         fi
521
522         return 1
523 }
524
525 # int get_KV()
526 #
527 #    Return the kernel version (major, minor and micro concated) as an integer.
528 #    Assumes X and Y of X.Y.Z are numbers.  Also assumes that some leading
529 #    portion of Z is a number.
530 #    e.g. 2.4.25, 2.6.10, 2.6.4-rc3, 2.2.40-poop, 2.0.15+foo
531 #
532 get_KV() {
533         local KV=$(uname -r)
534
535         echo $(KV_to_int "${KV}")
536
537         return $?
538 }
539
540 # bool get_bootparam(param)
541 #
542 #   return 0 if gentoo=param was passed to the kernel
543 #
544 #   EXAMPLE:  if get_bootparam "nodevfs" ; then ....
545 #
546 get_bootparam() {
547         local x copt params retval=1
548
549         [ ! -r "/proc/cmdline" ] && return 1
550
551         for copt in $(< /proc/cmdline)
552         do
553                 if [ "${copt%=*}" = "gentoo" ]
554                 then
555                         params="$(gawk -v PARAMS="${copt##*=}" '
556                                 BEGIN {
557                                         split(PARAMS, nodes, ",")
558                                         for (x in nodes)
559                                                 print nodes[x]
560                                 }')"
561
562                         # Parse gentoo option
563                         for x in ${params}
564                         do
565                                 if [ "${x}" = "$1" ]
566                                 then
567 #                                       echo "YES"
568                                         retval=0
569                                 fi
570                         done
571                 fi
572         done
573
574         return ${retval}
575 }
576
577 # Safer way to list the contents of a directory,
578 # as it do not have the "empty dir bug".
579 #
580 # char *dolisting(param)
581 #
582 #    print a list of the directory contents
583 #
584 #    NOTE: quote the params if they contain globs.
585 #          also, error checking is not that extensive ...
586 #
587 dolisting() {
588         local x=
589         local y=
590         local tmpstr=
591         local mylist=
592         local mypath="$*"
593
594         if [ "${mypath%/\*}" != "${mypath}" ]
595         then
596                 mypath="${mypath%/\*}"
597         fi
598
599         for x in ${mypath}
600         do
601                 [ ! -e "${x}" ] && continue
602
603                 if [ ! -d "${x}" ] && ( [ -L "${x}" -o -f "${x}" ] )
604                 then
605                         mylist="${mylist} $(ls "${x}" 2> /dev/null)"
606                 else
607                         [ "${x%/}" != "${x}" ] && x="${x%/}"
608
609                         cd "${x}"; tmpstr="$(ls)"
610
611                         for y in ${tmpstr}
612                         do
613                                 mylist="${mylist} ${x}/${y}"
614                         done
615                 fi
616         done
617
618         echo "${mylist}"
619 }
620
621 # char *add_suffix(char * configfile)
622 #
623 #    Returns a config file name with the softlevel suffix
624 #    appended to it.  For use with multi-config services.
625 add_suffix() {
626         if [ "${RC_USE_CONFIG_PROFILE}" = "yes" -a -e "$1.${DEFAULTLEVEL}" ]
627         then
628                 echo "$1.${DEFAULTLEVEL}"
629         else
630                 echo "$1"
631         fi
632
633         return 0
634 }
635
636 # Network filesystems list for common use in rc-scripts.
637 # This variable is used in is_net_fs and other places such as
638 # localmount.
639 NET_FS_LIST="afs cifs coda gfs ncpfs nfs nfs4 shfs smbfs"
640
641 # bool is_net_fs(path)
642 #
643 #   return 0 if path is the mountpoint of a networked filesystem
644 #
645 #   EXAMPLE:  if is_net_fs / ; then ...
646 #
647 is_net_fs() {
648         local fstype
649         # /proc/mounts is always accurate but may not always be available
650         if [[ -e /proc/mounts ]]; then
651                 fstype=$( sed -n -e '/^rootfs/!s:.* '"$1"' \([^ ]*\).*:\1:p' /proc/mounts )
652         else
653                 fstype=$( mount | sed -n -e 's:.* on '"$1"' type \([^ ]*\).*:\1:p' )
654         fi
655         [[ " ${NET_FS_LIST} " == *" ${fstype} "* ]]
656         return $?
657 }
658
659 # bool is_uml_sys()
660 #
661 #   return 0 if the currently running system is User Mode Linux
662 #
663 #   EXAMPLE:  if is_uml_sys ; then ...
664 #
665 is_uml_sys() {
666         grep -qs 'UML' /proc/cpuinfo
667         return $?
668 }
669
670 # bool is_vserver_sys()
671 #
672 #   return 0 if the currently running system is a Linux VServer
673 #
674 #   EXAMPLE:  if is_vserver_sys ; then ...
675 #
676 is_vserver_sys() {
677         grep -qs '^s_context:[[:space:]]*[1-9]' /proc/self/status
678         return $?
679 }
680
681 # bool get_mount_fstab(path)
682 #
683 #   return the parameters to pass to the mount command generated from fstab
684 #
685 #   EXAMPLE: cmd=$( get_mount_fstab /proc )
686 #            cmd=${cmd:--t proc none /proc}
687 #            mount -n ${cmd}
688 #
689 get_mount_fstab() {
690         awk '$1 ~ "^#" { next }
691              $2 == "'$*'" { if (found++ == 0) { print "-t "$3,"-o "$4,$1,$2 } }
692              END { if (found > 1) { print "More than one entry for '$*' found in /etc/fstab!" > "/dev/stderr" } }
693         ' /etc/fstab
694 }
695
696 # char *reverse_list(list)
697 #
698 #   Returns the reversed order of list
699 #
700 reverse_list() {
701         for (( i = $# ; i > 0 ; --i )); do
702                 echo -n "${!i} "
703         done
704 }
705
706 # bool is_older_than(reference, files/dirs to check)
707 #
708 #   return 0 if any of the files/dirs are newer than
709 #   the reference file
710 #
711 #   EXAMPLE: if is_older_than a.out *.o ; then ...
712 is_older_than() {
713         local x=
714         local ref="$1"
715         shift
716
717         for x in "$@" ; do
718                 [[ ${x} -nt ${ref} ]] && return 0
719
720                 if [[ -d ${x} ]] ; then
721                         is_older_than "${ref}" "${x}"/* && return 0
722                 fi
723         done
724
725         return 1
726 }
727
728 if [ -z "${EBUILD}" ] ; then
729         # Setup a basic $PATH.  Just add system default to existing.
730         # This should solve both /sbin and /usr/sbin not present when
731         # doing 'su -c foo', or for something like:  PATH= rcscript start
732         PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:${PATH}"
733
734         if [ "$(/sbin/consoletype 2> /dev/null)" = "serial" ] ; then
735                 # We do not want colors/endcols on serial terminals
736                 RC_NOCOLOR="yes"
737                 RC_ENDCOL="no"
738         fi
739
740         for arg in "$@" ; do
741                 case "${arg}" in
742                         # Lastly check if the user disabled it with --nocolor argument
743                         --nocolor|-nc)
744                                 RC_NOCOLOR="yes"
745                                 ;;
746                 esac
747         done
748
749 else
750         # Should we use colors ?
751         if [[ $* != *depend* ]]; then
752                 # Check user pref in portage
753                 RC_NOCOLOR="$(portageq envvar NOCOLOR 2>/dev/null)"
754                 [ "${RC_NOCOLOR}" = "true" ] && RC_NOCOLOR="yes"
755         else
756                 # We do not want colors during emerge depend
757                 RC_NOCOLOR="yes"
758                 # No output is seen during emerge depend, so this is not needed.
759                 RC_ENDCOL="no"
760         fi
761 fi
762
763 if [[ -n ${EBUILD} && $* == *depend* ]]; then
764         # We do not want stty to run during emerge depend
765         COLS=80
766 else
767         # Setup COLS and ENDCOL so eend can line up the [ ok ]
768         COLS=${COLUMNS:-0}              # bash's internal COLUMNS variable
769         (( COLS == 0 )) && COLS=$(stty size 2>/dev/null | cut -d' ' -f2)
770         (( COLS > 0 )) || (( COLS = 80 ))       # width of [ ok ] == 7
771 fi
772
773 if [[ ${RC_ENDCOL} == yes ]]; then
774         ENDCOL=$'\e[A\e['$(( COLS - 7 ))'G'
775 else
776         ENDCOL=''
777 fi
778
779 # Setup the colors so our messages all look pretty
780 if [[ ${RC_NOCOLOR} == yes ]]; then
781         unset GOOD WARN BAD NORMAL HILITE BRACKET
782 else
783         GOOD=$'\e[32;01m'
784         WARN=$'\e[33;01m'
785         BAD=$'\e[31;01m'
786         NORMAL=$'\e[0m'
787         HILITE=$'\e[36;01m'
788         BRACKET=$'\e[34;01m'
789 fi
790
791 # vim:ts=4
792 # }}}