2008-01-11 19:45:59 +08: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 19:18:42 +08:00
|
|
|
|
2015-12-05 06:52:19 +08:00
|
|
|
# Copyright (c) 2007-2015 The OpenRC Authors.
|
|
|
|
# See the Authors file at the top-level directory of this distribution and
|
2021-12-21 09:07:00 +08:00
|
|
|
# https://github.com/OpenRC/openrc/blob/HEAD/AUTHORS
|
2015-12-05 06:52:19 +08:00
|
|
|
#
|
|
|
|
# This file is part of OpenRC. It is subject to the license terms in
|
|
|
|
# the LICENSE file found in the top-level directory of this
|
2021-12-21 09:07:00 +08:00
|
|
|
# distribution and at https://github.com/OpenRC/openrc/blob/HEAD/LICENSE
|
2015-12-05 06:52:19 +08:00
|
|
|
# This file may not be copied, modified, propagated, or distributed
|
|
|
|
# except according to the terms contained in the LICENSE file.
|
|
|
|
|
2007-04-05 19:18:42 +08:00
|
|
|
RC_GOT_FUNCTIONS="yes"
|
|
|
|
|
2008-01-11 20:13:46 +08:00
|
|
|
eindent()
|
|
|
|
{
|
2011-11-11 10:46:08 +08:00
|
|
|
: $(( EINFO_INDENT = ${EINFO_INDENT:-0} + 2 ))
|
2009-04-27 05:13:26 +08:00
|
|
|
[ "$EINFO_INDENT" -gt 40 ] && EINFO_INDENT=40
|
2007-12-06 18:48:00 +08:00
|
|
|
export EINFO_INDENT
|
2007-04-05 19:18:42 +08:00
|
|
|
}
|
|
|
|
|
2008-01-11 20:13:46 +08:00
|
|
|
eoutdent()
|
|
|
|
{
|
2011-11-11 10:46:08 +08:00
|
|
|
: $(( EINFO_INDENT = ${EINFO_INDENT:-0} - 2 ))
|
2009-04-27 05:13:26 +08:00
|
|
|
[ "$EINFO_INDENT" -lt 0 ] && EINFO_INDENT=0
|
2007-04-05 19:18:42 +08:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2007-11-22 20:18:24 +08:00
|
|
|
yesno()
|
|
|
|
{
|
|
|
|
[ -z "$1" ] && return 1
|
|
|
|
|
2013-12-01 05:21:15 +08:00
|
|
|
# Check the value directly so people can do:
|
|
|
|
# yesno ${VAR}
|
2007-11-22 20:18:24 +08:00
|
|
|
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
|
|
|
|
|
2013-12-01 05:21:15 +08:00
|
|
|
# Check the value of the var so people can do:
|
|
|
|
# yesno VAR
|
|
|
|
# Note: this breaks when the var contains a double quote.
|
2007-11-22 20:18:24 +08:00
|
|
|
local value=
|
2013-12-01 05:21:15 +08:00
|
|
|
eval value=\"\$$1\"
|
2009-04-27 05:13:26 +08:00
|
|
|
case "$value" in
|
2007-11-22 20:18:24 +08: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;;
|
2018-11-17 19:18:18 +08:00
|
|
|
*) vewarn "\$$1 is not set properly"; return 2;;
|
2007-11-22 20:18:24 +08:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2011-07-03 12:33:23 +08:00
|
|
|
rc_runlevel()
|
|
|
|
{
|
2008-04-09 00:01:40 +08:00
|
|
|
rc-status --runlevel
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:13:46 +08:00
|
|
|
_sanitize_path()
|
|
|
|
{
|
2007-11-28 23:45:03 +08:00
|
|
|
local IFS=":" p= path=
|
2009-04-27 05:13:26 +08:00
|
|
|
for p in $PATH; do
|
|
|
|
case "$p" in
|
2009-05-24 03:38:12 +08:00
|
|
|
@LIBEXECDIR@/bin|@LIBEXECDIR@/sbin);;
|
2013-02-13 06:09:51 +08:00
|
|
|
@BINDIR@|@SBINDIR@|/usr/bin|/usr/sbin);;
|
2008-03-19 23:21:42 +08:00
|
|
|
@PKG_PREFIX@/bin|@PKG_PREFIX@/sbin);;
|
|
|
|
@LOCAL_PREFIX@/bin|@LOCAL_PREFIX@/sbin);;
|
2009-04-27 05:13:26 +08:00
|
|
|
*) path="$path${path:+:}$p";;
|
2007-11-28 21:40:15 +08:00
|
|
|
esac
|
|
|
|
done
|
2009-04-27 05:13:26 +08:00
|
|
|
echo "$path"
|
2007-11-28 21:40:15 +08:00
|
|
|
}
|
|
|
|
|
2007-07-17 00:22:37 +08:00
|
|
|
# Allow our scripts to support zsh
|
2009-04-20 00:47:09 +08:00
|
|
|
if [ -n "$ZSH_VERSION" ]; then
|
2007-12-14 22:12:38 +08:00
|
|
|
emulate sh
|
|
|
|
NULLCMD=:
|
|
|
|
alias -g '${1+"$@"}'='"$@"'
|
|
|
|
setopt NO_GLOB_SUBST
|
2007-07-17 00:22:37 +08:00
|
|
|
fi
|
|
|
|
|
2008-03-19 23:21:42 +08:00
|
|
|
# Make a sane PATH
|
2008-03-21 03:57:31 +08:00
|
|
|
_PREFIX=@PREFIX@
|
2008-03-19 23:21:42 +08:00
|
|
|
_PKG_PREFIX=@PKG_PREFIX@
|
|
|
|
_LOCAL_PREFIX=@LOCAL_PREFIX@
|
2008-03-21 03:57:31 +08:00
|
|
|
_LOCAL_PREFIX=${_LOCAL_PREFIX:-/usr/local}
|
2009-05-24 03:38:12 +08:00
|
|
|
_PATH=@LIBEXECDIR@/bin
|
2009-04-27 05:13:26 +08:00
|
|
|
case "$_PREFIX" in
|
|
|
|
"$_PKG_PREFIX"|"$_LOCAL_PREFIX") ;;
|
|
|
|
*) _PATH="$_PATH:$_PREFIX/bin:$_PREFIX/sbin";;
|
2008-03-21 08:30:22 +08:00
|
|
|
esac
|
2009-04-27 05:13:26 +08:00
|
|
|
_PATH="$_PATH":/bin:/sbin:/usr/bin:/usr/sbin
|
2008-03-21 08:30:22 +08:00
|
|
|
|
2009-04-27 05:13:26 +08:00
|
|
|
if [ -n "$_PKG_PREFIX" ]; then
|
|
|
|
_PATH="$_PATH:$_PKG_PREFIX/bin:$_PKG_PREFIX/sbin"
|
2008-03-19 23:21:42 +08:00
|
|
|
fi
|
2009-04-27 05:13:26 +08:00
|
|
|
if [ -n "$_LOCAL_PREFIX" ]; then
|
|
|
|
_PATH="$_PATH:$_LOCAL_PREFIX/bin:$_LOCAL_PREFIX/sbin"
|
2008-03-19 23:21:42 +08:00
|
|
|
fi
|
2009-04-27 05:13:26 +08:00
|
|
|
_path="$(_sanitize_path "$PATH")"
|
2012-11-07 08:22:33 +08:00
|
|
|
PATH="$_PATH${_path:+:}$_path" ; export PATH
|
2008-03-28 02:34:12 +08:00
|
|
|
unset _sanitize_path _PREFIX _PKG_PREFIX _LOCAL_PREFIX _PATH _path
|
2007-04-05 19:18:42 +08:00
|
|
|
|
2007-11-29 19:23:06 +08:00
|
|
|
for arg; do
|
2009-04-27 05:13:26 +08:00
|
|
|
case "$arg" in
|
2007-09-29 03:29:59 +08:00
|
|
|
--nocolor|--nocolour|-C)
|
2012-11-07 08:22:33 +08:00
|
|
|
EINFO_COLOR="NO" ; export EINFO_COLOR
|
2007-04-05 19:18:42 +08:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2007-12-14 20:16:05 +08:00
|
|
|
if [ -t 1 ] && yesno "${EINFO_COLOR:-YES}"; then
|
2009-04-27 05:13:26 +08:00
|
|
|
if [ -z "$GOOD" ]; then
|
2007-12-14 20:16:05 +08: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
|
2012-10-18 06:55:02 +08:00
|
|
|
eval "$_e() { local _r; command $_e \"\$@\"; _r=\$?; \
|
2012-11-07 08:22:33 +08:00
|
|
|
EINFO_LASTCMD=$_e; export EINFO_LASTCMD ; return \$_r; }"
|
2007-12-14 20:16:05 +08:00
|
|
|
done
|
2008-03-24 13:54:18 +08:00
|
|
|
unset _e
|
2007-04-05 19:18:42 +08:00
|
|
|
fi
|