-# bool is_vserver_sys()
-#
-# return 0 if the currently running system is a Linux VServer
-#
-# EXAMPLE: if is_vserver_sys ; then ...
-#
-is_vserver_sys() {
- grep -qs '^s_context:[[:space:]]*[1-9]' /proc/self/status
- return $?
-}
-
-# bool get_mount_fstab(path)
-#
-# return the parameters to pass to the mount command generated from fstab
-#
-# EXAMPLE: cmd=$( get_mount_fstab /proc )
-# cmd=${cmd:--t proc none /proc}
-# mount -n ${cmd}
-#
-get_mount_fstab() {
- awk '$1 ~ "^#" { next }
- $2 == "'$*'" { if (found++ == 0) { print "-t "$3,"-o "$4,$1,$2 } }
- END { if (found > 1) { print "More than one entry for '$*' found in /etc/fstab!" > "/dev/stderr" } }
- ' /etc/fstab
-}
-
-# char *reverse_list(list)
-#
-# Returns the reversed order of list
-#
-reverse_list() {
- for (( i = $# ; i > 0 ; --i )); do
- echo -n "${!i} "
- done
-}
-
-# bool is_older_than(reference, files/dirs to check)
-#
-# return 0 if any of the files/dirs are newer than
-# the reference file
-#
-# EXAMPLE: if is_older_than a.out *.o ; then ...
-is_older_than() {
- local x=
- local ref="$1"
- shift
-
- for x in "$@" ; do
- [[ ${x} -nt ${ref} ]] && return 0
-
- if [[ -d ${x} ]] ; then
- is_older_than "${ref}" "${x}"/* && return 0
- fi
- done
-
- return 1
-}
-
-if [ -z "${EBUILD}" ] ; then
- # Setup a basic $PATH. Just add system default to existing.
- # This should solve both /sbin and /usr/sbin not present when
- # doing 'su -c foo', or for something like: PATH= rcscript start
- PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:${PATH}"
-
- if [ "$(/sbin/consoletype 2> /dev/null)" = "serial" ] ; then
- # We do not want colors/endcols on serial terminals
- RC_NOCOLOR="yes"
- RC_ENDCOL="no"
- fi
-
- for arg in "$@" ; do
- case "${arg}" in
- # Lastly check if the user disabled it with --nocolor argument
- --nocolor|-nc)
- RC_NOCOLOR="yes"
- ;;
- esac
- done
-
-else
- # Should we use colors ?
- if [[ $* != *depend* ]]; then
- # Check user pref in portage
- RC_NOCOLOR="$(portageq envvar NOCOLOR 2>/dev/null)"
- [ "${RC_NOCOLOR}" = "true" ] && RC_NOCOLOR="yes"
- else
- # We do not want colors during emerge depend
- RC_NOCOLOR="yes"
- # No output is seen during emerge depend, so this is not needed.
- RC_ENDCOL="no"
- fi
-fi
-
-if [[ -n ${EBUILD} && $* == *depend* ]]; then
- # We do not want stty to run during emerge depend
- COLS=80
-else
- # Setup COLS and ENDCOL so eend can line up the [ ok ]
- COLS=${COLUMNS:-0} # bash's internal COLUMNS variable
- (( COLS == 0 )) && COLS=$(stty size 2>/dev/null | cut -d' ' -f2)
- (( COLS > 0 )) || (( COLS = 80 )) # width of [ ok ] == 7
-fi
-
-if [[ ${RC_ENDCOL} == yes ]]; then
- ENDCOL=$'\e[A\e['$(( COLS - 7 ))'G'
-else
- ENDCOL=''
-fi
-
-# Setup the colors so our messages all look pretty
-if [[ ${RC_NOCOLOR} == yes ]]; then
- unset GOOD WARN BAD NORMAL HILITE BRACKET
-else
- GOOD=$'\e[32;01m'
- WARN=$'\e[33;01m'
- BAD=$'\e[31;01m'
- NORMAL=$'\e[0m'
- HILITE=$'\e[36;01m'
- BRACKET=$'\e[34;01m'
-fi
-
-# vim:ts=4
-# }}}