- local retval=${1:-0}
- shift
-
- _eend ${retval} ewarn "$*"
-
- LAST_E_CMD=ewend
- return $retval
-}
-
-# v-e-commands honor RC_VERBOSE which defaults to no.
-# The condition is negated so the return value will be zero.
-veinfo() { [[ "${RC_VERBOSE}" != yes ]] || einfo "$@"; }
-veinfon() { [[ "${RC_VERBOSE}" != yes ]] || einfon "$@"; }
-vewarn() { [[ "${RC_VERBOSE}" != yes ]] || ewarn "$@"; }
-veerror() { [[ "${RC_VERBOSE}" != yes ]] || eerror "$@"; }
-vebegin() { [[ "${RC_VERBOSE}" != yes ]] || ebegin "$@"; }
-veend() {
- [[ "${RC_VERBOSE}" == yes ]] && { eend "$@"; return $?; }
- return ${1:-0}
-}
-veend() {
- [[ "${RC_VERBOSE}" == yes ]] && { ewend "$@"; return $?; }
- return ${1:-0}
-}
-
-# char *KV_major(string)
-#
-# Return the Major (X of X.Y.Z) kernel version
-#
-KV_major() {
- [[ -z $1 ]] && return 1
-
- local KV=$@
- echo ${KV%%.*}
-}
-
-# char *KV_minor(string)
-#
-# Return the Minor (Y of X.Y.Z) kernel version
-#
-KV_minor() {
- [[ -z $1 ]] && return 1
-
- local KV=$@
- KV=${KV#*.}
- echo ${KV%%.*}
-}
-
-# char *KV_micro(string)
-#
-# Return the Micro (Z of X.Y.Z) kernel version.
-#
-KV_micro() {
- [[ -z $1 ]] && return 1
-
- local KV=$@
- KV=${KV#*.*.}
- echo ${KV%%[^[:digit:]]*}
-}
-
-# int KV_to_int(string)
-#
-# Convert a string type kernel version (2.4.0) to an int (132096)
-# for easy compairing or versions ...
-#
-KV_to_int() {
- [[ -z $1 ]] && return 1
-
- local KV_MAJOR=$(KV_major "$1")
- local KV_MINOR=$(KV_minor "$1")
- local KV_MICRO=$(KV_micro "$1")
- local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO ))
-
- # We make version 2.2.0 the minimum version we will handle as
- # a sanity check ... if its less, we fail ...
- if [[ ${KV_int} -ge 131584 ]] ; then
- echo "${KV_int}"
- return 0
- fi
-
- return 1
-}
-
-# int get_KV()
-#
-# Return the kernel version (major, minor and micro concated) as an integer.
-# Assumes X and Y of X.Y.Z are numbers. Also assumes that some leading
-# portion of Z is a number.
-# e.g. 2.4.25, 2.6.10, 2.6.4-rc3, 2.2.40-poop, 2.0.15+foo
-#
-get_KV() {
- local KV=$(uname -r)
-
- echo $(KV_to_int "${KV}")
-
- return $?
-}
-
-# bool get_bootparam(param)
-#
-# return 0 if gentoo=param was passed to the kernel
-#
-# EXAMPLE: if get_bootparam "nodevfs" ; then ....
-#
-get_bootparam() {
- local x copt params retval=1
-
- [ ! -r "/proc/cmdline" ] && return 1
-
- for copt in $(< /proc/cmdline)
- do
- if [ "${copt%=*}" = "gentoo" ]
- then
- params="$(gawk -v PARAMS="${copt##*=}" '
- BEGIN {
- split(PARAMS, nodes, ",")
- for (x in nodes)
- print nodes[x]
- }')"
-
- # Parse gentoo option
- for x in ${params}
- do
- if [ "${x}" = "$1" ]
- then
-# echo "YES"
- retval=0
- fi
- done
- fi
- done
-
- return ${retval}
-}
-
-# Safer way to list the contents of a directory,
-# as it do not have the "empty dir bug".
-#
-# char *dolisting(param)
-#
-# print a list of the directory contents
-#
-# NOTE: quote the params if they contain globs.
-# also, error checking is not that extensive ...
-#
-dolisting() {
- local x=
- local y=
- local tmpstr=
- local mylist=
- local mypath="$*"
-
- if [ "${mypath%/\*}" != "${mypath}" ]
- then
- mypath="${mypath%/\*}"
- fi
-
- for x in ${mypath}
- do
- [ ! -e "${x}" ] && continue
-
- if [ ! -d "${x}" ] && ( [ -L "${x}" -o -f "${x}" ] )
- then
- mylist="${mylist} $(ls "${x}" 2> /dev/null)"
- else
- [ "${x%/}" != "${x}" ] && x="${x%/}"
-
- cd "${x}"; tmpstr="$(ls)"
-
- for y in ${tmpstr}
- do
- mylist="${mylist} ${x}/${y}"
- done
- fi
- done
-
- echo "${mylist}"
-}
-
-# char *add_suffix(char * configfile)
-#
-# Returns a config file name with the softlevel suffix
-# appended to it. For use with multi-config services.
-add_suffix() {
- if [ "${RC_USE_CONFIG_PROFILE}" = "yes" -a -e "$1.${DEFAULTLEVEL}" ]
- then
- echo "$1.${DEFAULTLEVEL}"
- else
- echo "$1"
- fi
-
- return 0
-}
-
-# Network filesystems list for common use in rc-scripts.
-# This variable is used in is_net_fs and other places such as
-# localmount.
-NET_FS_LIST="afs cifs coda gfs ncpfs nfs nfs4 shfs smbfs"
-
-# bool is_net_fs(path)
-#
-# return 0 if path is the mountpoint of a networked filesystem
-#
-# EXAMPLE: if is_net_fs / ; then ...
-#
-is_net_fs() {
- local fstype
- # /proc/mounts is always accurate but may not always be available
- if [[ -e /proc/mounts ]]; then
- fstype=$( sed -n -e '/^rootfs/!s:.* '"$1"' \([^ ]*\).*:\1:p' /proc/mounts )
- else
- fstype=$( mount | sed -n -e 's:.* on '"$1"' type \([^ ]*\).*:\1:p' )
- fi
- [[ " ${NET_FS_LIST} " == *" ${fstype} "* ]]
- return $?
-}