/[baselayout]/branches/baselayout-1_12/sbin/functions.sh
Gentoo

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20