/[baselayout]/trunk/sbin/functions.sh
Gentoo

Contents of /trunk/sbin/functions.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2091 - (show annotations) (download) (as text)
Wed Jun 14 21:13:31 2006 UTC (8 years, 6 months ago) by uberlord
File MIME type: text/x-sh
File size: 19078 byte(s)
    {start,stop}_volumes moved to rc and halt.sh respectively.

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

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20