2009-05-01 15:11:40 +01:00
|
|
|
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
|
2008-01-11 15:31:10 +00:00
|
|
|
# All rights reserved. Released under the 2-clause BSD license.
|
2007-04-05 11:18:42 +00:00
|
|
|
|
2008-01-11 11:45:59 +00:00
|
|
|
# Allow any sh script to work with einfo functions and friends
|
|
|
|
# We also provide a few helpful functions for other programs to use
|
2007-04-05 11:18:42 +00:00
|
|
|
|
|
|
|
RC_GOT_FUNCTIONS="yes"
|
|
|
|
|
2008-01-11 12:13:46 +00:00
|
|
|
eindent()
|
|
|
|
{
|
2007-12-06 10:48:00 +00:00
|
|
|
EINFO_INDENT=$((${EINFO_INDENT:-0} + 2))
|
2009-04-26 21:13:26 +00:00
|
|
|
[ "$EINFO_INDENT" -gt 40 ] && EINFO_INDENT=40
|
2007-12-06 10:48:00 +00:00
|
|
|
export EINFO_INDENT
|
2007-04-05 11:18:42 +00:00
|
|
|
}
|
|
|
|
|
2008-01-11 12:13:46 +00:00
|
|
|
eoutdent()
|
|
|
|
{
|
2007-12-06 10:48:00 +00:00
|
|
|
EINFO_INDENT=$((${EINFO_INDENT:-0} - 2))
|
2009-04-26 21:13:26 +00:00
|
|
|
[ "$EINFO_INDENT" -lt 0 ] && EINFO_INDENT=0
|
2007-04-05 11:18:42 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2007-11-22 12:18:24 +00:00
|
|
|
yesno()
|
|
|
|
{
|
|
|
|
[ -z "$1" ] && return 1
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;;
|
|
|
|
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
local value=
|
|
|
|
eval value=\$${1}
|
2009-04-26 21:13:26 +00:00
|
|
|
case "$value" in
|
2007-11-22 12:18:24 +00:00
|
|
|
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;;
|
|
|
|
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;;
|
2009-04-26 21:13:26 +00:00
|
|
|
*) vewarn "\$$1 is not set properly"; return 1;;
|
2007-11-22 12:18:24 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2008-04-08 16:01:40 +00:00
|
|
|
rc_runlevel() {
|
|
|
|
rc-status --runlevel
|
|
|
|
}
|
|
|
|
|
2008-01-11 12:13:46 +00:00
|
|
|
_sanitize_path()
|
|
|
|
{
|
2007-11-28 15:45:03 +00:00
|
|
|
local IFS=":" p= path=
|
2009-04-26 21:13:26 +00:00
|
|
|
for p in $PATH; do
|
|
|
|
case "$p" in
|
2009-05-23 20:38:12 +01:00
|
|
|
@LIBEXECDIR@/bin|@LIBEXECDIR@/sbin);;
|
2008-03-27 18:34:12 +00:00
|
|
|
@PREFIX@/bin|@PREFIX@/sbin|/usr/bin|/usr/sbin);;
|
2008-03-19 15:21:42 +00:00
|
|
|
@PKG_PREFIX@/bin|@PKG_PREFIX@/sbin);;
|
|
|
|
@LOCAL_PREFIX@/bin|@LOCAL_PREFIX@/sbin);;
|
2009-04-26 21:13:26 +00:00
|
|
|
*) path="$path${path:+:}$p";;
|
2007-11-28 13:40:15 +00:00
|
|
|
esac
|
|
|
|
done
|
2009-04-26 21:13:26 +00:00
|
|
|
echo "$path"
|
2007-11-28 13:40:15 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 16:22:37 +00:00
|
|
|
# Allow our scripts to support zsh
|
2009-04-19 16:47:09 +00:00
|
|
|
if [ -n "$ZSH_VERSION" ]; then
|
2007-12-14 14:12:38 +00:00
|
|
|
emulate sh
|
|
|
|
NULLCMD=:
|
|
|
|
alias -g '${1+"$@"}'='"$@"'
|
|
|
|
setopt NO_GLOB_SUBST
|
2007-07-16 16:22:37 +00:00
|
|
|
fi
|
|
|
|
|
2008-03-19 15:21:42 +00:00
|
|
|
# Make a sane PATH
|
2008-03-20 19:57:31 +00:00
|
|
|
_PREFIX=@PREFIX@
|
2008-03-19 15:21:42 +00:00
|
|
|
_PKG_PREFIX=@PKG_PREFIX@
|
|
|
|
_LOCAL_PREFIX=@LOCAL_PREFIX@
|
2008-03-20 19:57:31 +00:00
|
|
|
_LOCAL_PREFIX=${_LOCAL_PREFIX:-/usr/local}
|
2009-05-23 20:38:12 +01:00
|
|
|
_PATH=@LIBEXECDIR@/bin
|
2009-04-26 21:13:26 +00:00
|
|
|
case "$_PREFIX" in
|
|
|
|
"$_PKG_PREFIX"|"$_LOCAL_PREFIX") ;;
|
|
|
|
*) _PATH="$_PATH:$_PREFIX/bin:$_PREFIX/sbin";;
|
2008-03-21 00:30:22 +00:00
|
|
|
esac
|
2009-04-26 21:13:26 +00:00
|
|
|
_PATH="$_PATH":/bin:/sbin:/usr/bin:/usr/sbin
|
2008-03-21 00:30:22 +00:00
|
|
|
|
2009-04-26 21:13:26 +00:00
|
|
|
if [ -n "$_PKG_PREFIX" ]; then
|
|
|
|
_PATH="$_PATH:$_PKG_PREFIX/bin:$_PKG_PREFIX/sbin"
|
2008-03-19 15:21:42 +00:00
|
|
|
fi
|
2009-04-26 21:13:26 +00:00
|
|
|
if [ -n "$_LOCAL_PREFIX" ]; then
|
|
|
|
_PATH="$_PATH:$_LOCAL_PREFIX/bin:$_LOCAL_PREFIX/sbin"
|
2008-03-19 15:21:42 +00:00
|
|
|
fi
|
2009-04-26 21:13:26 +00:00
|
|
|
_path="$(_sanitize_path "$PATH")"
|
|
|
|
export PATH="$_PATH${_path:+:}$_path"
|
2008-03-27 18:34:12 +00:00
|
|
|
unset _sanitize_path _PREFIX _PKG_PREFIX _LOCAL_PREFIX _PATH _path
|
2007-04-05 11:18:42 +00:00
|
|
|
|
2007-11-29 11:23:06 +00:00
|
|
|
for arg; do
|
2009-04-26 21:13:26 +00:00
|
|
|
case "$arg" in
|
2007-09-28 19:29:59 +00:00
|
|
|
--nocolor|--nocolour|-C)
|
2007-12-06 10:48:00 +00:00
|
|
|
export EINFO_COLOR="NO"
|
2007-04-05 11:18:42 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2007-12-14 12:16:05 +00:00
|
|
|
if [ -t 1 ] && yesno "${EINFO_COLOR:-YES}"; then
|
2009-04-26 21:13:26 +00:00
|
|
|
if [ -z "$GOOD" ]; then
|
2007-12-14 12:16:05 +00:00
|
|
|
eval $(eval_ecolors)
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# We need to have shell stub functions so our init scripts can remember
|
|
|
|
# the last ecmd
|
|
|
|
for _e in ebegin eend error errorn einfo einfon ewarn ewarnn ewend \
|
|
|
|
vebegin veend veinfo vewarn vewend; do
|
2009-05-23 20:38:12 +01:00
|
|
|
eval "$_e() { local _r; @LIBEXECDIR@/bin/$_e \"\$@\"; _r=$?; \
|
2009-04-26 21:13:26 +00:00
|
|
|
export EINFO_LASTCMD=$_e; return \$_r; }"
|
2007-12-14 12:16:05 +00:00
|
|
|
done
|
2008-03-24 05:54:18 +00:00
|
|
|
unset _e
|
2007-04-05 11:18:42 +00:00
|
|
|
fi
|