initial checkin
[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 RC_NOCOLOR="${RC_NOCOLOR:-no}"
164 # Can the terminal handle endcols?
165 RC_ENDCOL="yes"
166
167 #
168 # Default values for rc system
169 #
170 RC_TTY_NUMBER=11
171 RC_NET_STRICT_CHECKING="no"
172 RC_PARALLEL_STARTUP="no"
173 RC_USE_CONFIG_PROFILE="yes"
174
175 #
176 # Default values for e-message indentation and dots
177 #
178 RC_INDENTATION=''
179 RC_DEFAULT_INDENT=2
180 #RC_DOT_PATTERN=' .'
181 RC_DOT_PATTERN=''
182
183 # void splash(...)
184 #
185 #  Notify bootsplash/splashutils/gensplash/whatever about
186 #  important events.
187 #
188 splash() {
189         return 0
190 }
191
192 # void profiling(...)
193 #
194 #  Notify bootsplash/whatever about important events.
195 #
196 profiling() {
197         return 0
198 }
199
200 # void get_bootconfig()
201 #
202 #    Get the BOOTLEVEL and SOFTLEVEL by setting
203 #    'bootlevel' and 'softlevel' via kernel
204 #    parameters.
205 #
206 get_bootconfig() {
207         local copt=
208         local newbootlevel=
209         local newsoftlevel=
210
211         for copt in $(</proc/cmdline) ; do
212                 case "${copt%=*}" in
213                         "bootlevel")
214                                 newbootlevel="${copt##*=}"
215                                 ;;
216                         "softlevel")
217                                 newsoftlevel="${copt##*=}"
218                                 ;;
219                 esac
220         done
221
222         if [ -n "${newbootlevel}" ] ; then
223                 export BOOTLEVEL="${newbootlevel}"
224         else
225                 export BOOTLEVEL="boot"
226         fi
227
228         if [ -n "${newsoftlevel}" ] ; then
229                 export DEFAULTLEVEL="${newsoftlevel}"
230         else
231                 export DEFAULTLEVEL="default"
232         fi
233
234         return 0
235 }
236
237 # void get_libdir(void)
238 #
239 #    prints the current libdir {lib,lib32,lib64}
240 #
241 get_libdir() {
242         if [ -n "${CONF_LIBDIR_OVERRIDE}" ] ; then
243                 CONF_LIBDIR="${CONF_LIBDIR_OVERRIDE}"
244         elif [ -x "/usr/bin/portageq" ] ; then
245                 CONF_LIBDIR="$(/usr/bin/portageq envvar CONF_LIBDIR)"
246         fi
247         echo ${CONF_LIBDIR:=lib}
248 }
249
250 # void esyslog(char* priority, char* tag, char* message)
251 #
252 #    use the system logger to log a message
253 #
254 esyslog() {
255         local pri=
256         local tag=
257
258         if [ -x /usr/bin/logger ]
259         then
260                 pri="$1"
261                 tag="$2"
262
263                 shift 2
264                 [[ -z "$*" ]] && return 0
265
266                 /usr/bin/logger -p "${pri}" -t "${tag}" -- "$*"
267         fi
268
269         return 0
270 }
271
272 # void eindent(int num)
273 #
274 #    increase the indent used for e-commands.
275 #
276 eindent() {
277         local i=$1
278         (( i > 0 )) || (( i = RC_DEFAULT_INDENT ))
279         esetdent $(( ${#RC_INDENTATION} + i ))
280 }
281
282 # void eoutdent(int num)
283 #
284 #    decrease the indent used for e-commands.
285 #
286 eoutdent() {
287         local i=$1
288         (( i > 0 )) || (( i = RC_DEFAULT_INDENT ))
289         esetdent $(( ${#RC_INDENTATION} - i ))
290 }
291
292 # void esetdent(int num)
293 #
294 #    hard set the indent used for e-commands.
295 #    num defaults to 0
296 #
297 esetdent() {
298         local i=$1
299         (( i < 0 )) && (( i = 0 ))
300         RC_INDENTATION=$(printf "%${i}s" '')
301 }
302
303 # void einfo(char* message)
304 #
305 #    show an informative message (with a newline)
306 #
307 einfo() {
308         einfon "$*\n"
309         LAST_E_CMD=einfo
310         return 0
311 }
312
313 # void einfon(char* message)
314 #
315 #    show an informative message (without a newline)
316 #
317 einfon() {
318         [[ ${RC_QUIET_STDOUT} == yes ]] && return 0
319         [[ ${RC_ENDCOL} != yes && ${LAST_E_CMD} == ebegin ]] && echo
320         echo -ne " ${GOOD}*${NORMAL} ${RC_INDENTATION}$*"
321         LAST_E_CMD=einfon
322         return 0
323 }
324
325 # void ewarn(char* message)
326 #
327 #    show a warning message + log it
328 #
329 ewarn() {
330         if [[ ${RC_QUIET_STDOUT} == yes ]]; then
331                 echo " $*"
332         else
333                 [[ ${RC_ENDCOL} != yes && ${LAST_E_CMD} == ebegin ]] && echo
334                 echo -e " ${WARN}*${NORMAL} ${RC_INDENTATION}$*"
335         fi
336
337         # Log warnings to system log
338         esyslog "daemon.warning" "rc-scripts" "$*"
339
340         LAST_E_CMD=ewarn
341         return 0
342 }
343
344 # void eerror(char* message)
345 #
346 #    show an error message + log it
347 #
348 eerror() {
349         if [[ ${RC_QUIET_STDOUT} == yes ]]; then
350                 echo " $*" >/dev/stderr
351         else
352                 [[ ${RC_ENDCOL} != yes && ${LAST_E_CMD} == ebegin ]] && echo
353                 echo -e " ${BAD}*${NORMAL} ${RC_INDENTATION}$*"
354         fi
355
356         # Log errors to system log
357         esyslog "daemon.err" "rc-scripts" "$*"
358
359         LAST_E_CMD=eerror
360         return 0
361 }
362
363 # void ebegin(char* message)
364 #
365 #    show a message indicating the start of a process
366 #
367 ebegin() {
368         local msg="$*" dots spaces=${RC_DOT_PATTERN//?/ }
369         [[ ${RC_QUIET_STDOUT} == yes ]] && return 0
370
371         if [[ -n ${RC_DOT_PATTERN} ]]; then
372                 dots=$(printf "%$(( COLS - 3 - ${#RC_INDENTATION} - ${#msg} - 7 ))s" '')
373                 dots=${dots//${spaces}/${RC_DOT_PATTERN}}
374                 msg="${msg}${dots}"
375         else
376                 msg="${msg} ..."
377         fi
378         einfon "${msg}"
379         [[ ${RC_ENDCOL} == yes ]] && echo
380
381         LAST_E_LEN=$(( 3 + ${#RC_INDENTATION} + ${#msg} ))
382         LAST_E_CMD=ebegin
383         return 0
384 }
385
386 # void _eend(int error, char *efunc, char* errstr)
387 #
388 #    indicate the completion of process, called from eend/ewend
389 #    if error, show errstr via efunc
390 #
391 #    This function is private to functions.sh.  Do not call it from a
392 #    script.
393 #
394 _eend() {
395         local retval=${1:-0} efunc=${2:-eerror} msg
396         shift 2
397
398         if [[ ${retval} == 0 ]]; then
399                 [[ ${RC_QUIET_STDOUT} == yes ]] && return 0
400                 msg="${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}"
401         else
402                 if [[ -n "$*" ]]; then
403                         ${efunc} "$*"
404                 fi
405                 msg="${BRACKET}[ ${BAD}!!${BRACKET} ]${NORMAL}"
406         fi
407
408         if [[ ${RC_ENDCOL} == yes ]]; then
409                 echo -e "${ENDCOL}  ${msg}"
410         else
411                 [[ ${LAST_E_CMD} == ebegin ]] || LAST_E_LEN=0
412                 printf "%$(( COLS - LAST_E_LEN - 6 ))s%b\n" '' "${msg}"
413         fi
414
415         return ${retval}
416 }
417
418 # void eend(int error, char* errstr)
419 #
420 #    indicate the completion of process
421 #    if error, show errstr via eerror
422 #
423 eend() {
424         local retval=${1:-0}
425         shift
426
427         _eend ${retval} eerror "$*"
428
429         LAST_E_CMD=eend
430         return $retval
431 }
432
433 # void ewend(int error, char* errstr)
434 #
435 #    indicate the completion of process
436 #    if error, show errstr via ewarn
437 #
438 ewend() {
439         local retval=${1:-0}
440         shift
441
442         _eend ${retval} ewarn "$*"
443
444         LAST_E_CMD=ewend
445         return $retval
446 }
447
448 # v-e-commands honor RC_VERBOSE which defaults to no.
449 # The condition is negated so the return value will be zero.
450 veinfo() { [[ "${RC_VERBOSE}" != yes ]] || einfo "$@"; }
451 veinfon() { [[ "${RC_VERBOSE}" != yes ]] || einfon "$@"; }
452 vewarn() { [[ "${RC_VERBOSE}" != yes ]] || ewarn "$@"; }
453 veerror() { [[ "${RC_VERBOSE}" != yes ]] || eerror "$@"; }
454 vebegin() { [[ "${RC_VERBOSE}" != yes ]] || ebegin "$@"; }
455 veend() {
456         [[ "${RC_VERBOSE}" == yes ]] && { eend "$@"; return $?; }
457         return ${1:-0}
458 }
459 veend() {
460         [[ "${RC_VERBOSE}" == yes ]] && { ewend "$@"; return $?; }
461         return ${1:-0}
462 }
463
464 # char *KV_major(string)
465 #
466 #    Return the Major (X of X.Y.Z) kernel version
467 #
468 KV_major() {
469         [[ -z $1 ]] && return 1
470
471         local KV=$@
472         echo ${KV%%.*}
473 }
474
475 # char *KV_minor(string)
476 #
477 #    Return the Minor (Y of X.Y.Z) kernel version
478 #
479 KV_minor() {
480         [[ -z $1 ]] && return 1
481
482         local KV=$@
483         KV=${KV#*.}
484         echo ${KV%%.*}
485 }
486
487 # char *KV_micro(string)
488 #
489 #    Return the Micro (Z of X.Y.Z) kernel version.
490 #
491 KV_micro() {
492         [[ -z $1 ]] && return 1
493
494         local KV=$@
495         KV=${KV#*.*.}
496         echo ${KV%%[^[:digit:]]*}
497 }
498
499 # int KV_to_int(string)
500 #
501 #    Convert a string type kernel version (2.4.0) to an int (132096)
502 #    for easy compairing or versions ...
503 #
504 KV_to_int() {
505         [[ -z $1 ]] && return 1
506
507         local KV_MAJOR=$(KV_major "$1")
508         local KV_MINOR=$(KV_minor "$1")
509         local KV_MICRO=$(KV_micro "$1")
510         local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO ))
511
512         # We make version 2.2.0 the minimum version we will handle as
513         # a sanity check ... if its less, we fail ...
514         if [[ ${KV_int} -ge 131584 ]] ; then
515                 echo "${KV_int}"
516                 return 0
517         fi
518
519         return 1
520 }
521
522 # int get_KV()
523 #
524 #    Return the kernel version (major, minor and micro concated) as an integer.
525 #    Assumes X and Y of X.Y.Z are numbers.  Also assumes that some leading
526 #    portion of Z is a number.
527 #    e.g. 2.4.25, 2.6.10, 2.6.4-rc3, 2.2.40-poop, 2.0.15+foo
528 #
529 get_KV() {
530         local KV=$(uname -r)
531
532         echo $(KV_to_int "${KV}")
533
534         return $?
535 }
536
537 # bool get_bootparam(param)
538 #
539 #   return 0 if gentoo=param was passed to the kernel
540 #
541 #   EXAMPLE:  if get_bootparam "nodevfs" ; then ....
542 #
543 get_bootparam() {
544         local x copt params retval=1
545
546         [ ! -r "/proc/cmdline" ] && return 1
547
548         for copt in $(< /proc/cmdline)
549         do
550                 if [ "${copt%=*}" = "gentoo" ]
551                 then
552                         params="$(gawk -v PARAMS="${copt##*=}" '
553                                 BEGIN {
554                                         split(PARAMS, nodes, ",")
555                                         for (x in nodes)
556                                                 print nodes[x]
557                                 }')"
558
559                         # Parse gentoo option
560                         for x in ${params}
561                         do
562                                 if [ "${x}" = "$1" ]
563                                 then
564 #                                       echo "YES"
565                                         retval=0
566                                 fi
567                         done
568                 fi
569         done
570
571         return ${retval}
572 }
573
574 # Safer way to list the contents of a directory,
575 # as it do not have the "empty dir bug".
576 #
577 # char *dolisting(param)
578 #
579 #    print a list of the directory contents
580 #
581 #    NOTE: quote the params if they contain globs.
582 #          also, error checking is not that extensive ...
583 #
584 dolisting() {
585         local x=
586         local y=
587         local tmpstr=
588         local mylist=
589         local mypath="$*"
590
591         if [ "${mypath%/\*}" != "${mypath}" ]
592         then
593                 mypath="${mypath%/\*}"
594         fi
595
596         for x in ${mypath}
597         do
598                 [ ! -e "${x}" ] && continue
599
600                 if [ ! -d "${x}" ] && ( [ -L "${x}" -o -f "${x}" ] )
601                 then
602                         mylist="${mylist} $(ls "${x}" 2> /dev/null)"
603                 else
604                         [ "${x%/}" != "${x}" ] && x="${x%/}"
605
606                         cd "${x}"; tmpstr="$(ls)"
607
608                         for y in ${tmpstr}
609                         do
610                                 mylist="${mylist} ${x}/${y}"
611                         done
612                 fi
613         done
614
615         echo "${mylist}"
616 }
617
618 # char *add_suffix(char * configfile)
619 #
620 #    Returns a config file name with the softlevel suffix
621 #    appended to it.  For use with multi-config services.
622 add_suffix() {
623         if [ "${RC_USE_CONFIG_PROFILE}" = "yes" -a -e "$1.${DEFAULTLEVEL}" ]
624         then
625                 echo "$1.${DEFAULTLEVEL}"
626         else
627                 echo "$1"
628         fi
629
630         return 0
631 }
632
633 # Network filesystems list for common use in rc-scripts.
634 # This variable is used in is_net_fs and other places such as
635 # localmount.
636 NET_FS_LIST="afs cifs coda gfs ncpfs nfs nfs4 shfs smbfs"
637
638 # bool is_net_fs(path)
639 #
640 #   return 0 if path is the mountpoint of a networked filesystem
641 #
642 #   EXAMPLE:  if is_net_fs / ; then ...
643 #
644 is_net_fs() {
645         local fstype
646         # /proc/mounts is always accurate but may not always be available
647         if [[ -e /proc/mounts ]]; then
648                 fstype=$( sed -n -e '/^rootfs/!s:.* '"$1"' \([^ ]*\).*:\1:p' /proc/mounts )
649         else
650                 fstype=$( mount | sed -n -e 's:.* on '"$1"' type \([^ ]*\).*:\1:p' )
651         fi
652         [[ " ${NET_FS_LIST} " == *" ${fstype} "* ]]
653         return $?
654 }
655
656 # bool is_uml_sys()
657 #
658 #   return 0 if the currently running system is User Mode Linux
659 #
660 #   EXAMPLE:  if is_uml_sys ; then ...
661 #
662 is_uml_sys() {
663         grep -qs 'UML' /proc/cpuinfo
664         return $?
665 }
666
667 # bool is_vserver_sys()
668 #
669 #   return 0 if the currently running system is a Linux VServer
670 #
671 #   EXAMPLE:  if is_vserver_sys ; then ...
672 #
673 is_vserver_sys() {
674         grep -qs '^s_context:[[:space:]]*[1-9]' /proc/self/status
675         return $?
676 }
677
678 # bool get_mount_fstab(path)
679 #
680 #   return the parameters to pass to the mount command generated from fstab
681 #
682 #   EXAMPLE: cmd=$( get_mount_fstab /proc )
683 #            cmd=${cmd:--t proc none /proc}
684 #            mount -n ${cmd}
685 #
686 get_mount_fstab() {
687         awk '$1 ~ "^#" { next }
688              $2 == "'$*'" { if (found++ == 0) { print "-t "$3,"-o "$4,$1,$2 } }
689              END { if (found > 1) { print "More than one entry for '$*' found in /etc/fstab!" > "/dev/stderr" } }
690         ' /etc/fstab
691 }
692
693 # char *reverse_list(list)
694 #
695 #   Returns the reversed order of list
696 #
697 reverse_list() {
698         for (( i = $# ; i > 0 ; --i )); do
699                 echo -n "${!i} "
700         done
701 }
702
703 # bool is_older_than(reference, files/dirs to check)
704 #
705 #   return 0 if any of the files/dirs are newer than
706 #   the reference file
707 #
708 #   EXAMPLE: if is_older_than a.out *.o ; then ...
709 is_older_than() {
710         local x=
711         local ref="$1"
712         shift
713
714         for x in "$@" ; do
715                 [[ ${x} -nt ${ref} ]] && return 0
716
717                 if [[ -d ${x} ]] ; then
718                         is_older_than "${ref}" "${x}"/* && return 0
719                 fi
720         done
721
722         return 1
723 }
724
725 if [ -z "${EBUILD}" ] ; then
726         # Setup a basic $PATH.  Just add system default to existing.
727         # This should solve both /sbin and /usr/sbin not present when
728         # doing 'su -c foo', or for something like:  PATH= rcscript start
729         PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:${PATH}"
730
731         if [ "$(/sbin/consoletype 2> /dev/null)" = "serial" ] ; then
732                 # We do not want colors/endcols on serial terminals
733                 RC_NOCOLOR="yes"
734                 RC_ENDCOL="no"
735         fi
736
737         for arg in "$@" ; do
738                 case "${arg}" in
739                         # Lastly check if the user disabled it with --nocolor argument
740                         --nocolor|-nc)
741                                 RC_NOCOLOR="yes"
742                                 ;;
743                 esac
744         done
745
746 else
747         # Should we use colors ?
748         if [[ $* != *depend* ]]; then
749                 # Check user pref in portage
750                 RC_NOCOLOR="$(portageq envvar NOCOLOR 2>/dev/null)"
751                 [ "${RC_NOCOLOR}" = "true" ] && RC_NOCOLOR="yes"
752         else
753                 # We do not want colors during emerge depend
754                 RC_NOCOLOR="yes"
755                 # No output is seen during emerge depend, so this is not needed.
756                 RC_ENDCOL="no"
757         fi
758 fi
759
760 if [[ -n ${EBUILD} && $* == *depend* ]]; then
761         # We do not want stty to run during emerge depend
762         COLS=80
763 else
764         # Setup COLS and ENDCOL so eend can line up the [ ok ]
765         COLS=${COLUMNS:-0}              # bash's internal COLUMNS variable
766         (( COLS == 0 )) && COLS=$(stty size 2>/dev/null | cut -d' ' -f2)
767         (( COLS > 0 )) || (( COLS = 80 ))       # width of [ ok ] == 7
768 fi
769
770 if [[ ${RC_ENDCOL} == yes ]]; then
771         ENDCOL=$'\e[A\e['$(( COLS - 7 ))'G'
772 else
773         ENDCOL=''
774 fi
775
776 # Setup the colors so our messages all look pretty
777 if [[ ${RC_NOCOLOR} == yes ]]; then
778         unset GOOD WARN BAD NORMAL HILITE BRACKET
779 else
780         GOOD=$'\e[32;01m'
781         WARN=$'\e[33;01m'
782         BAD=$'\e[31;01m'
783         NORMAL=$'\e[0m'
784         HILITE=$'\e[36;01m'
785         BRACKET=$'\e[34;01m'
786 fi
787
788 # vim:ts=4
789 # }}}