Gentoo Archives: gentoo-user-fr

From: Marc-Olivier Meunier <momeunier@×××××.com>
To: gentoo-user-fr@l.g.o
Subject: Re: [gentoo-user-fr] Suppression /etc/init.d/functions.sh
Date: Wed, 07 Dec 2005 16:28:58
Message-Id: 26231d540512070827qa0a2b76l@mail.gmail.com
In Reply to: Re: [gentoo-user-fr] Suppression /etc/init.d/functions.sh by Marc-Olivier Meunier
1 oula j'ai merdé...
2
3 la c'est bon
4
5
6 # Copyright 1999-2005 Gentoo Foundation
7 # Distributed under the terms of the GNU General Public License v2
8
9 RC_GOT_FUNCTIONS="yes"
10
11 # Override defaults with user settings ...
12 [ -f /etc/conf.d/rc ] && source /etc/conf.d/rc
13
14 # daemontools dir
15 SVCDIR="/var/lib/supervise"
16
17 # Check /etc/conf.d/rc for a description of these ...
18 svclib="/lib/rcscripts"
19 svcdir=${svcdir:-/var/lib/init.d}
20 svcmount=${svcmount:-no}
21 svcfstype=${svcfstype:-tmpfs}
22 svcsize=${svcsize:-1024}
23
24 # Different types of dependencies
25 deptypes="need use"
26 # Different types of order deps
27 ordtypes="before after"
28
29 #
30 # Internal variables
31 #
32
33 # Dont output to stdout?
34 RC_QUIET_STDOUT="no"
35 RC_VERBOSE=${RC_VERBOSE:-no}
36
37 # Should we use color?
38 RC_NOCOLOR=${RC_NOCOLOR:-no}
39 # Can the terminal handle endcols?
40 RC_ENDCOL="yes"
41
42 #
43 # Default values for rc system
44 #
45 RC_TTY_NUMBER=${RC_TTY_NUMBER:-11}
46 RC_PARALLEL_STARTUP=${RC_PARALLEL_STARTUP:-no}
47 RC_NET_STRICT_CHECKING=${RC_NET_STRICT_CHECKING:-no}
48 RC_VOLUME_ORDER=${RC_VOLUME_ORDER:-raid evms lvm dm}
49 RC_USE_FSTAB=${RC_USE_FSTAB:-no}
50 RC_USE_CONFIG_PROFILE=${RC_USE_CONFIG_PROFILE:-yes}
51 RC_FORCE_AUTO=${RC_FORCE_AUTO:-no}
52 RC_DEVICES=${RC_DEVICES:-auto}
53
54 #
55 # Default values for e-message indentation and dots
56 #
57 RC_INDENTATION=''
58 RC_DEFAULT_INDENT=2
59 #RC_DOT_PATTERN=' .'
60 RC_DOT_PATTERN=''
61
62 # void import_addon(char *addon)
63 #
64 # Import code from the specified addon if it exists
65 #
66 import_addon() {
67 local addon=${svclib}/addons/$1
68 if [[ -r ${addon} ]] ; then
69 source "${addon}"
70 return 0
71 fi
72 return 1
73 }
74
75 # void splash(...)
76 #
77 # Notify bootsplash/splashutils/gensplash/whatever about
78 # important events.
79 #
80 splash() {
81 return 0
82 }
83 # This will override the splash() function...
84 if ! import_addon splash-functions.sh ; then
85 [ -f /sbin/splash-functions.sh ] && source /sbin/splash-functions.sh
86 fi
87
88 # void profiling(...)
89 #
90 # Notify bootsplash/whatever about important events.
91 #
92 profiling() {
93 return 0
94 }
95 import_addon profiling-functions.sh
96
97 # void bootlog(...)
98 #
99 # Notify bootlogger about important events.
100 bootlog() {
101 return 0
102 }
103 [[ ${RC_BOOTLOG} == "yes" ]] && import_addon bootlogger.sh
104
105 # void get_bootconfig()
106 #
107 # Get the BOOTLEVEL and SOFTLEVEL by setting
108 # 'bootlevel' and 'softlevel' via kernel
109 # parameters.
110 #
111 get_bootconfig() {
112 local copt=
113 local newbootlevel=
114 local newsoftlevel=
115
116 if [[ -r /proc/cmdline ]] ; then
117 for copt in $(</proc/cmdline) ; do
118 case "${copt%=*}" in
119 bootlevel)
120 newbootlevel=${copt##*=}
121 ;;
122 softlevel)
123 newsoftlevel=${copt##*=}
124 ;;
125 esac
126 done
127 fi
128
129 if [[ -n ${newbootlevel} ]] ; then
130 export BOOTLEVEL=${newbootlevel}
131 else
132 export BOOTLEVEL="boot"
133 fi
134
135 if [[ -n ${newsoftlevel} ]] ; then
136 export DEFAULTLEVEL=${newsoftlevel}
137 else
138 export DEFAULTLEVEL="default"
139 fi
140
141 return 0
142 }
143
144 setup_defaultlevels() {
145 get_bootconfig
146
147 if get_bootparam "noconfigprofile" ; then
148 export RC_USE_CONFIG_PROFILE="no"
149
150 elif get_bootparam "configprofile" ; then
151 export RC_USE_CONFIG_PROFILE="yes"
152 fi
153
154 if [ "${RC_USE_CONFIG_PROFILE}" = "yes" -a -n "${DEFAULTLEVEL}" ] && \
155 [ -d "/etc/runlevels/${BOOTLEVEL}.${DEFAULTLEVEL}" -o \
156 -L "/etc/runlevels/${BOOTLEVEL}.${DEFAULTLEVEL}" ]
157 then
158 export BOOTLEVEL="${BOOTLEVEL}.${DEFAULTLEVEL}"
159 fi
160
161 if [ -z "${SOFTLEVEL}" ] ; then
162 if [ -f "${svcdir}/softlevel" ] ; then
163 export SOFTLEVEL="$(< ${svcdir}/softlevel)"
164 else
165 export SOFTLEVEL="${BOOTLEVEL}"
166 fi
167 fi
168
169 return 0
170 }
171
172 # void get_libdir(void)
173 #
174 # prints the current libdir {lib,lib32,lib64}
175 #
176 get_libdir() {
177 if [ -n "${CONF_LIBDIR_OVERRIDE}" ] ; then
178 CONF_LIBDIR="${CONF_LIBDIR_OVERRIDE}"
179 elif [ -x "/usr/bin/portageq" ] ; then
180 CONF_LIBDIR="$(/usr/bin/portageq envvar CONF_LIBDIR)"
181 fi
182 echo ${CONF_LIBDIR:=lib}
183 }
184
185 # void esyslog(char* priority, char* tag, char* message)
186 #
187 # use the system logger to log a message
188 #
189 esyslog() {
190 local pri=
191 local tag=
192
193 if [ -x /usr/bin/logger ]
194 then
195 pri="$1"
196 tag="$2"
197
198 shift 2
199 [[ -z "$*" ]] && return 0
200
201 /usr/bin/logger -p "${pri}" -t "${tag}" -- "$*"
202 fi
203
204 return 0
205 }
206
207 # void eindent(int num)
208 #
209 # increase the indent used for e-commands.
210 #
211 eindent() {
212 local i=$1
213 (( i > 0 )) || (( i = RC_DEFAULT_INDENT ))
214 esetdent $(( ${#RC_INDENTATION} + i ))
215 }
216
217 # void eoutdent(int num)
218 #
219 # decrease the indent used for e-commands.
220 #
221 eoutdent() {
222 local i=$1
223 (( i > 0 )) || (( i = RC_DEFAULT_INDENT ))
224 esetdent $(( ${#RC_INDENTATION} - i ))
225 }
226
227 # void esetdent(int num)
228 #
229 # hard set the indent used for e-commands.
230 # num defaults to 0
231 #
232 esetdent() {
233 local i=$1
234 (( i < 0 )) && (( i = 0 ))
235 RC_INDENTATION=$(printf "%${i}s" '')
236 }
237
238 # void einfo(char* message)
239 #
240 # show an informative message (with a newline)
241 #
242 einfo() {
243 einfon "$*\n"
244 LAST_E_CMD=einfo
245 return 0
246 }
247
248 # void einfon(char* message)
249 #
250 # show an informative message (without a newline)
251 #
252 einfon() {
253 [[ ${RC_QUIET_STDOUT} == yes ]] && return 0
254 [[ ${RC_ENDCOL} != yes && ${LAST_E_CMD} == ebegin ]] && echo
255 echo -ne " ${GOOD}*${NORMAL} ${RC_INDENTATION}$*"
256 LAST_E_CMD=einfon
257 return 0
258 }
259
260 # void ewarn(char* message)
261 #
262 # show a warning message + log it
263 #
264 ewarn() {
265 if [[ ${RC_QUIET_STDOUT} == yes ]]; then
266 echo " $*"
267 else
268 [[ ${RC_ENDCOL} != yes && ${LAST_E_CMD} == ebegin ]] && echo
269 echo -e " ${WARN}*${NORMAL} ${RC_INDENTATION}$*"
270 fi
271
272 # Log warnings to system log
273 esyslog "daemon.warning" "rc-scripts" "$*"
274
275 LAST_E_CMD=ewarn
276 return 0
277 }
278
279 # void eerror(char* message)
280 #
281 # show an error message + log it
282 #
283 eerror() {
284 if [[ ${RC_QUIET_STDOUT} == yes ]]; then
285 echo " $*" >/dev/stderr
286 else
287 [[ ${RC_ENDCOL} != yes && ${LAST_E_CMD} == ebegin ]] && echo
288 echo -e " ${BAD}*${NORMAL} ${RC_INDENTATION}$*"
289 fi
290
291 # Log errors to system log
292 esyslog "daemon.err" "rc-scripts" "$*"
293
294 LAST_E_CMD=eerror
295 return 0
296 }
297
298 # void ebegin(char* message)
299 #
300 # show a message indicating the start of a process
301 #
302 ebegin() {
303 local msg="$*" dots spaces=${RC_DOT_PATTERN//?/ }
304 [[ ${RC_QUIET_STDOUT} == yes ]] && return 0
305
306 if [[ -n ${RC_DOT_PATTERN} ]]; then
307 dots=$(printf "%$(( COLS - 3 - ${#RC_INDENTATION} -
308 ${#msg} - 7 ))s" '')
309 dots=${dots//${spaces}/${RC_DOT_PATTERN}}
310 msg="${msg}${dots}"
311 else
312 msg="${msg} ..."
313 fi
314 einfon "${msg}"
315 [[ ${RC_ENDCOL} == yes ]] && echo
316
317 LAST_E_LEN=$(( 3 + ${#RC_INDENTATION} + ${#msg} ))
318 LAST_E_CMD=ebegin
319 return 0
320 }
321
322 # void _eend(int error, char *efunc, char* errstr)
323 #
324 # indicate the completion of process, called from eend/ewend
325 # if error, show errstr via efunc
326 #
327 # This function is private to functions.sh. Do not call it from a
328 # script.
329 #
330 _eend() {
331 local retval=${1:-0} efunc=${2:-eerror} msg
332 shift 2
333
334 if [[ ${retval} == 0 ]]; then
335 [[ ${RC_QUIET_STDOUT} == yes ]] && return 0
336 msg="${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}"
337 else
338 if [[ -c /dev/null ]]; then
339 rc_splash "stop" &>/dev/null &
340 else
341 rc_splash "stop" &
342 fi
343 if [[ -n "$*" ]]; then
344 ${efunc} "$*"
345 fi
346 msg="${BRACKET}[ ${BAD}!!${BRACKET} ]${NORMAL}"
347 fi
348
349 if [[ ${RC_ENDCOL} == yes ]]; then
350 echo -e "${ENDCOL} ${msg}"
351 else
352 [[ ${LAST_E_CMD} == ebegin ]] || LAST_E_LEN=0
353 printf "%$(( COLS - LAST_E_LEN - 6 ))s%b\n" '' "${msg}"
354 fi
355
356 return ${retval}
357 }
358
359 # void eend(int error, char* errstr)
360 #
361 # indicate the completion of process
362 # if error, show errstr via eerror
363 #
364 eend() {
365 local retval=${1:-0}
366 shift
367
368 _eend ${retval} eerror "$*"
369
370 LAST_E_CMD=eend
371 return $retval
372 }
373
374 # void ewend(int error, char* errstr)
375 #
376 # indicate the completion of process
377 # if error, show errstr via ewarn
378 #
379 ewend() {
380 local retval=${1:-0}
381 shift
382
383 _eend ${retval} ewarn "$*"
384
385 LAST_E_CMD=ewend
386 return $retval
387 }
388
389 # v-e-commands honor RC_VERBOSE which defaults to no.
390 # The condition is negated so the return value will be zero.
391 veinfo() { [[ "${RC_VERBOSE}" != yes ]] || einfo "$@"; }
392 veinfon() { [[ "${RC_VERBOSE}" != yes ]] || einfon "$@"; }
393 vewarn() { [[ "${RC_VERBOSE}" != yes ]] || ewarn "$@"; }
394 veerror() { [[ "${RC_VERBOSE}" != yes ]] || eerror "$@"; }
395 vebegin() { [[ "${RC_VERBOSE}" != yes ]] || ebegin "$@"; }
396 veend() {
397 [[ "${RC_VERBOSE}" == yes ]] && { eend "$@"; return $?; }
398 return ${1:-0}
399 }
400 veend() {
401 [[ "${RC_VERBOSE}" == yes ]] && { ewend "$@"; return $?; }
402 return ${1:-0}
403 }
404
405 # char *KV_major(string)
406 #
407 # Return the Major (X of X.Y.Z) kernel version
408 #
409 KV_major() {
410 [[ -z $1 ]] && return 1
411
412 local KV=$@
413 echo ${KV%%.*}
414 }
415
416 # char *KV_minor(string)
417 #
418 # Return the Minor (Y of X.Y.Z) kernel version
419 #
420 KV_minor() {
421 [[ -z $1 ]] && return 1
422
423 local KV=$@
424 KV=${KV#*.}
425 echo ${KV%%.*}
426 }
427
428 # char *KV_micro(string)
429 #
430 # Return the Micro (Z of X.Y.Z) kernel version.
431 #
432 KV_micro() {
433 [[ -z $1 ]] && return 1
434
435 local KV=$@
436 KV=${KV#*.*.}
437 echo ${KV%%[^[:digit:]]*}
438 }
439
440 # int KV_to_int(string)
441 #
442 # Convert a string type kernel version (2.4.0) to an int (132096)
443 # for easy compairing or versions ...
444 #
445 KV_to_int() {
446 [[ -z $1 ]] && return 1
447
448 local KV_MAJOR=$(KV_major "$1")
449 local KV_MINOR=$(KV_minor "$1")
450 local KV_MICRO=$(KV_micro "$1")
451 local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO ))
452
453 # We make version 2.2.0 the minimum version we will handle as
454 # a sanity check ... if its less, we fail ...
455 if [[ ${KV_int} -ge 131584 ]] ; then
456 echo "${KV_int}"
457 return 0
458 fi
459
460 return 1
461 }
462
463 # int get_KV()
464 #
465 # Return the kernel version (major, minor and micro concated) as an integer.
466 # Assumes X and Y of X.Y.Z are numbers. Also assumes that some leading
467 # portion of Z is a number.
468 # e.g. 2.4.25, 2.6.10, 2.6.4-rc3, 2.2.40-poop, 2.0.15+foo
469 #
470 get_KV() {
471 local KV=$(uname -r)
472
473 echo $(KV_to_int "${KV}")
474
475 return $?
476 }
477
478 # bool get_bootparam(param)
479 #
480 # return 0 if gentoo=param was passed to the kernel
481 #
482 # EXAMPLE: if get_bootparam "nodevfs" ; then ....
483 #
484 get_bootparam() {
485 local x copt params retval=1
486
487 [ ! -r "/proc/cmdline" ] && return 1
488
489 for copt in $(< /proc/cmdline)
490 do
491 if [ "${copt%=*}" = "gentoo" ]
492 then
493 params="$(gawk -v PARAMS="${copt##*=}" '
494 BEGIN {
495 split(PARAMS, nodes, ",")
496 for (x in nodes)
497 print nodes[x]
498 }')"
499
500 # Parse gentoo option
501 for x in ${params}
502 do
503 if [ "${x}" = "$1" ]
504 then
505 # echo "YES"
506 retval=0
507 fi
508 done
509 fi
510 done
511
512 return ${retval}
513 }
514
515 # Safer way to list the contents of a directory,
516 # as it do not have the "empty dir bug".
517 #
518 # char *dolisting(param)
519 #
520 # print a list of the directory contents
521 #
522 # NOTE: quote the params if they contain globs.
523 # also, error checking is not that extensive ...
524 #
525 dolisting() {
526 local x=
527 local y=
528 local tmpstr=
529 local mylist=
530 local mypath="$*"
531
532 if [ "${mypath%/\*}" != "${mypath}" ]
533 then
534 mypath="${mypath%/\*}"
535 fi
536
537 for x in ${mypath}
538 do
539 [ ! -e "${x}" ] && continue
540
541 if [ ! -d "${x}" ] && ( [ -L "${x}" -o -f "${x}" ] )
542 then
543 mylist="${mylist} $(ls "${x}" 2> /dev/null)"
544 else
545 [ "${x%/}" != "${x}" ] && x="${x%/}"
546
547 cd "${x}"; tmpstr="$(ls)"
548
549 for y in ${tmpstr}
550 do
551 mylist="${mylist} ${x}/${y}"
552 done
553 fi
554 done
555
556 echo "${mylist}"
557 }
558
559 # void save_options(char *option, char *optstring)
560 #
561 # save the settings ("optstring") for "option"
562 #
563 save_options() {
564 local myopts="$1"
565
566 shift
567 if [ ! -d "${svcdir}/options/${myservice}" ]
568 then
569 mkdir -p -m 0755 "${svcdir}/options/${myservice}"
570 fi
571
572 echo "$*" > "${svcdir}/options/${myservice}/${myopts}"
573
574 return 0
575 }
576
577 # char *get_options(char *option)
578 #
579 # get the "optstring" for "option" that was saved
580 # by calling the save_options function
581 #
582 get_options() {
583 if [ -f "${svcdir}/options/${myservice}/$1" ]
584 then
585 echo "$(< ${svcdir}/options/${myservice}/$1)"
586 fi
587
588 return 0
589 }
590
591 # char *add_suffix(char * configfile)
592 #
593 # Returns a config file name with the softlevel suffix
594 # appended to it. For use with multi-config services.
595 add_suffix() {
596 if [ "${RC_USE_CONFIG_PROFILE}" = "yes" -a -e "$1.${DEFAULTLEVEL}" ]
597 then
598 echo "$1.${DEFAULTLEVEL}"
599 else
600 echo "$1"
601 fi
602
603 return 0
604 }
605
606 # char *get_base_ver()
607 #
608 # get the version of baselayout that this system is running
609 #
610 get_base_ver() {
611 [[ ! -r /etc/gentoo-release ]] && return 0
612 local ver=$(</etc/gentoo-release)
613 echo ${ver##* }
614 }
615
616 # Network filesystems list for common use in rc-scripts.
617 # This variable is used in is_net_fs and other places such as
618 # localmount.
619 NET_FS_LIST="afs cifs coda davfs gfs ncpfs nfs nfs4 ocfs2 shfs smbfs"
620
621 # bool is_net_fs(path)
622 #
623 # return 0 if path is the mountpoint of a networked filesystem
624 #
625 # EXAMPLE: if is_net_fs / ; then ...
626 #
627 is_net_fs() {
628 local fstype
629 # /proc/mounts is always accurate but may not always be available
630 if [[ -e /proc/mounts ]]; then
631 fstype=$( sed -n -e '/^rootfs/!s:.* '"$1"' \([^
632 ]*\).*:\1:p' /proc/mounts )
633 else
634 fstype=$( mount | sed -n -e 's:.* on '"$1"' type \([^
635 ]*\).*:\1:p' )
636 fi
637 [[ " ${NET_FS_LIST} " == *" ${fstype} "* ]]
638 return $?
639 }
640
641 # bool is_uml_sys()
642 #
643 # return 0 if the currently running system is User Mode Linux
644 #
645 # EXAMPLE: if is_uml_sys ; then ...
646 #
647 is_uml_sys() {
648 grep -qs 'UML' /proc/cpuinfo
649 return $?
650 }
651
652 # bool is_vserver_sys()
653 #
654 # return 0 if the currently running system is a Linux VServer
655 #
656 # EXAMPLE: if is_vserver_sys ; then ...
657 #
658 is_vserver_sys() {
659 grep -qs '^s_context:[[:space:]]*[1-9]' /proc/self/status
660 return $?
661 }
662
663 # bool is_xenU_sys()
664 #
665 # return 0 if the currently running system is an unprivileged Xen domain
666 #
667 # EXAMPLE: if is_xenU_sys ; then ...
668 #
669 is_xenU_sys() {
670 [[ -d /proc/xen && ! -f /proc/xen/privcmd ]]
671 }
672
673 # bool get_mount_fstab(path)
674 #
675 # return the parameters to pass to the mount command generated from fstab
676 #
677 # EXAMPLE: cmd=$( get_mount_fstab /proc )
678 # cmd=${cmd:--t proc none /proc}
679 # mount -n ${cmd}
680 #
681 get_mount_fstab() {
682 awk '$1 ~ "^#" { next }
683 $2 == "'$*'" { stab="-t "$3" -o "$4" "$1" "$2; }
684 END { print stab; }
685 ' /etc/fstab
686 }
687
688 # char *reverse_list(list)
689 #
690 # Returns the reversed order of list
691 #
692 reverse_list() {
693 for (( i = $# ; i > 0 ; --i )); do
694 echo -n "${!i} "
695 done
696 }
697
698 # void start_addon(addon)
699 #
700 # Starts addon.
701 #
702 start_addon() {
703 local addon=$1
704 (import_addon ${addon}-start.sh)
705 return 0
706 }
707
708 # void start_volumes()
709 #
710 # Starts all volumes in RC_VOLUME_ORDER.
711 #
712 start_volumes() {
713 local x=
714
715 for x in ${RC_VOLUME_ORDER}; do
716 start_addon "${x}"
717 done
718
719 return 0
720 }
721
722 # void stop_addon(addon)
723 #
724 # Stops addon.
725 #
726 stop_addon() {
727 local addon=$1
728 (import_addon ${addon}-stop.sh)
729 return 0
730 }
731
732 # void stop_volumes()
733 #
734 # Stops all volumes in RC_VOLUME_ORDER (reverse order).
735 #
736 stop_volumes() {
737 local x=
738
739 for x in $(reverse_list ${RC_VOLUME_ORDER}); do
740 stop_addon "${x}"
741 done
742
743 return 0
744 }
745
746 # bool is_older_than(reference, files/dirs to check)
747 #
748 # return 0 if any of the files/dirs are newer than
749 # the reference file
750 #
751 # EXAMPLE: if is_older_than a.out *.o ; then ...
752 is_older_than() {
753 local x=
754 local ref="$1"
755 shift
756
757 for x in "$@" ; do
758 [[ ${x} -nt ${ref} ]] && return 0
759
760 if [[ -d ${x} ]] ; then
761 is_older_than "${ref}" "${x}"/* && return 0
762 fi
763 done
764
765 return 1
766 }
767
768 # char* bash_variable(char *variable)
769 #
770 # Turns the given variable into something that bash can use
771 # Basically replaces anything not a-z,A-Z into a _
772 #
773 bash_variable() {
774 local args="$@"
775 LC_ALL=C echo "${args//[![:word:]]/_}"
776 }
777
778 # void requote()
779 #
780 # Requotes params so they're suitable to be eval'd, just like this would:
781 # set -- 1 2 "3 4"
782 # /usr/bin/getopt -- '' "$@" | sed 's/^ -- //'
783 #
784 requote() {
785 local q=\'
786 set -- "${@//\'/$q\'$q}" # quote inner instances of '
787 set -- "${@/#/$q}" # add ' to start of each param
788 set -- "${@/%/$q}" # add ' to end of each param
789 echo "$*"
790 }
791
792 ##############################################################################
793 # #
794 # This should be the last code in here, please add all functions above!! #
795 # #
796 # *** START LAST CODE *** #
797 # #
798 ##############################################################################
799
800 if [ -z "${EBUILD}" ] ; then
801 # Setup a basic $PATH. Just add system default to existing.
802 # This should solve both /sbin and /usr/sbin not present when
803 # doing 'su -c foo', or for something like: PATH= rcscript start
804 PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:${PATH}"
805
806 # Cache the CONSOLETYPE - this is important as backgrounded shells don't
807 # have a TTY. rc unsets it at the end of running so it shouldn't hang
808 # around
809 if [[ -z ${CONSOLETYPE} ]]; then
810 export CONSOLETYPE=$( /sbin/consoletype 2>/dev/null )
811 fi
812 if [[ ${CONSOLETYPE} == "serial" ]] ; then
813 RC_NOCOLOR="yes"
814 RC_ENDCOL="no"
815 fi
816
817 for arg in "$@" ; do
818 case "${arg}" in
819 # Lastly check if the user disabled it with
820 --nocolor argument
821 --nocolor|-nc)
822 RC_NOCOLOR="yes"
823 ;;
824 esac
825 done
826
827 if [ -r "/proc/cmdline" ] ; then
828 setup_defaultlevels
829 fi
830 else
831 # Should we use colors ?
832 if [[ $* != *depend* ]]; then
833 # Check user pref in portage
834 RC_NOCOLOR="$(portageq envvar NOCOLOR 2>/dev/null)"
835 [ "${RC_NOCOLOR}" = "true" ] && RC_NOCOLOR="yes"
836 else
837 # We do not want colors during emerge depend
838 RC_NOCOLOR="yes"
839 # No output is seen during emerge depend, so this is not needed.
840 RC_ENDCOL="no"
841 fi
842 fi
843
844 if [[ -n ${EBUILD} && $* = *depend* ]]; then
845 # We do not want stty to run during emerge depend
846 COLS=80
847 else
848 # Setup COLS and ENDCOL so eend can line up the [ ok ]
849 COLS=${COLUMNS:-0} # bash's internal COLUMNS variable
850 (( COLS == 0 )) && COLS=$(stty size 2>/dev/null | cut -d' ' -f2)
851 (( COLS > 0 )) || (( COLS = 80 )) # width of [ ok ] == 7
852 fi
853
854 if [[ ${RC_ENDCOL} == yes ]]; then
855 ENDCOL=$'\e[A\e['$(( COLS - 8 ))'C'
856 else
857 ENDCOL=''
858 fi
859
860 # Setup the colors so our messages all look pretty
861 if [[ ${RC_NOCOLOR} == yes ]]; then
862 unset GOOD WARN BAD NORMAL HILITE BRACKET
863 else
864 GOOD=$'\e[32;01m'
865 WARN=$'\e[33;01m'
866 BAD=$'\e[31;01m'
867 NORMAL=$'\e[0m'
868 HILITE=$'\e[36;01m'
869 BRACKET=$'\e[34;01m'
870 fi
871
872 ##############################################################################
873 # #
874 # *** END LAST CODE *** #
875 # #
876 # This should be the last code in here, please add all functions above!! #
877 # #
878 ##############################################################################
879
880
881 # vim:ts=4
882
883 --
884 gentoo-user-fr@g.o mailing list