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