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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20