summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/functions.sh')
-rwxr-xr-xsbin/functions.sh88
1 files changed, 47 insertions, 41 deletions
diff --git a/sbin/functions.sh b/sbin/functions.sh
index 304c03a..1911236 100755
--- a/sbin/functions.sh
+++ b/sbin/functions.sh
@@ -4,14 +4,14 @@
RC_GOT_FUNCTIONS="yes"
# Override defaults with user settings ...
-[ -f /etc/conf.d/rc ] && source /etc/conf.d/rc
+[[ -f /etc/conf.d/rc ]] && source /etc/conf.d/rc
# daemontools dir
SVCDIR="/var/lib/supervise"
# Check /etc/conf.d/rc for a description of these ...
-svclib="/lib/rcscripts"
-svcdir=${svcdir:-/var/lib/init.d}
+declare -r svclib="/lib/rcscripts"
+declare -r svcdir="${svcdir:-/var/lib/init.d}"
# Different types of dependencies
deptypes="need use"
@@ -23,21 +23,21 @@ ordtypes="before after"
#
# Dont output to stdout?
-RC_QUIET_STDOUT=${RC_QUIET_STDOUT:-no}
-RC_VERBOSE=${RC_VERBOSE:-no}
+RC_QUIET_STDOUT="${RC_QUIET_STDOUT:-no}"
+RC_VERBOSE="${RC_VERBOSE:-no}"
# Should we use color?
-RC_NOCOLOR=${RC_NOCOLOR:-no}
+RC_NOCOLOR="${RC_NOCOLOR:-no}"
# Can the terminal handle endcols?
RC_ENDCOL="yes"
#
# Default values for rc system
#
-RC_TTY_NUMBER=${RC_TTY_NUMBER:-0}
-RC_PARALLEL_STARTUP=${RC_PARALLEL_STARTUP:-no}
-RC_NET_STRICT_CHECKING=${RC_NET_STRICT_CHECKING:-none}
-RC_DOWN_INTERFACE=${RC_DOWN_INTERFACE:-yes}
+RC_TTY_NUMBER="${RC_TTY_NUMBER:-0}"
+RC_PARALLEL_STARTUP="${RC_PARALLEL_STARTUP:-no}"
+RC_NET_STRICT_CHECKING="${RC_NET_STRICT_CHECKING:-none}"
+RC_DOWN_INTERFACE="${RC_DOWN_INTERFACE:-yes}"
#
# Default values for e-message indentation and dots
@@ -123,9 +123,9 @@ get_libdir() {
if [[ -n ${CONF_LIBDIR_OVERRIDE} ]] ; then
CONF_LIBDIR="${CONF_LIBDIR_OVERRIDE}"
elif [[ -x /usr/bin/portageq ]] ; then
- CONF_LIBDIR=$(/usr/bin/portageq envvar CONF_LIBDIR)
+ CONF_LIBDIR="$(/usr/bin/portageq envvar CONF_LIBDIR)"
fi
- echo ${CONF_LIBDIR:=lib}
+ echo "${CONF_LIBDIR:=lib}"
}
# void esyslog(char* priority, char* tag, char* message)
@@ -245,12 +245,12 @@ eerror() {
# show a message indicating the start of a process
#
ebegin() {
- local msg="$*" dots spaces=${RC_DOT_PATTERN//?/ }
+ local msg="$*" dots spaces="${RC_DOT_PATTERN//?/ }"
[[ ${RC_QUIET_STDOUT} == "yes" ]] && return 0
if [[ -n ${RC_DOT_PATTERN} ]] ; then
- dots=$(printf "%$(( COLS - 3 - ${#RC_INDENTATION} - ${#msg} - 7 ))s" '')
- dots=${dots//${spaces}/${RC_DOT_PATTERN}}
+ dots="$(printf "%$((COLS - 3 - ${#RC_INDENTATION} - ${#msg} - 7))s" '')"
+ dots="${dots//${spaces}/${RC_DOT_PATTERN}}"
msg="${msg}${dots}"
else
msg="${msg} ..."
@@ -258,7 +258,7 @@ ebegin() {
einfon "${msg}"
[[ ${RC_ENDCOL} == "yes" ]] && echo
- LAST_E_LEN=$(( 3 + ${#RC_INDENTATION} + ${#msg} ))
+ LAST_E_LEN="$(( 3 + ${#RC_INDENTATION} + ${#msg} ))"
LAST_E_CMD="ebegin"
return 0
}
@@ -272,7 +272,7 @@ ebegin() {
# script.
#
_eend() {
- local retval=${1:-0} efunc=${2:-eerror} msg
+ local retval="${1:-0}" efunc="${2:-eerror}" msg
shift 2
if [[ ${retval} == "0" ]] ; then
@@ -301,10 +301,10 @@ _eend() {
# if error, show errstr via eerror
#
eend() {
- local retval=${1:-0}
+ local retval="${1:-0}"
shift
- _eend ${retval} eerror "$*"
+ _eend "${retval}" eerror "$*"
LAST_E_CMD="eend"
return ${retval}
@@ -316,10 +316,10 @@ eend() {
# if error, show errstr via ewarn
#
ewend() {
- local retval=${1:-0}
+ local retval="${1:-0}"
shift
- _eend ${retval} ewarn "$*"
+ _eend "${retval}" ewarn "$*"
LAST_E_CMD="ewend"
return ${retval}
@@ -348,7 +348,7 @@ veend() {
KV_major() {
[[ -z $1 ]] && return 1
- local KV=$@
+ local KV="$@"
echo "${KV%%.*}"
}
@@ -359,8 +359,8 @@ KV_major() {
KV_minor() {
[[ -z $1 ]] && return 1
- local KV=$@
- KV=${KV#*.}
+ local KV="$@"
+ KV="${KV#*.}"
echo "${KV%%.*}"
}
@@ -371,8 +371,8 @@ KV_minor() {
KV_micro() {
[[ -z $1 ]] && return 1
- local KV=$@
- KV=${KV#*.*.}
+ local KV="$@"
+ KV="${KV#*.*.}"
echo "${KV%%[^[:digit:]]*}"
}
@@ -384,10 +384,10 @@ KV_micro() {
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 ))
+ 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 ...
@@ -409,9 +409,9 @@ KV_to_int() {
_RC_GET_KV_CACHE=""
get_KV() {
[[ -z ${_RC_GET_KV_CACHE} ]] \
- && _RC_GET_KV_CACHE=$(uname -r)
+ && _RC_GET_KV_CACHE="$(uname -r)"
- echo $(KV_to_int "${_RC_GET_KV_CACHE}")
+ echo "$(KV_to_int "${_RC_GET_KV_CACHE}")"
return $?
}
@@ -474,11 +474,11 @@ save_options() {
local myopts="$1"
shift
- if [[ ! -d "${svcdir}/options/${myservice}" ]] ; then
- mkdir -p -m 0755 "${svcdir}/options/${myservice}"
+ if [[ ! -d "${svcdir}/options/${SVCNAME}" ]] ; then
+ mkdir -p -m 0755 "${svcdir}/options/${SVCNAME}"
fi
- echo "$*" > "${svcdir}/options/${myservice}/${myopts}"
+ echo "$*" > "${svcdir}/options/${SVCNAME}/${myopts}"
return 0
}
@@ -489,8 +489,8 @@ save_options() {
# by calling the save_options function
#
get_options() {
- if [[ -f "${svcdir}/options/${myservice}/$1" ]] ; then
- echo "$(< ${svcdir}/options/${myservice}/$1)"
+ if [[ -f "${svcdir}/options/${SVCNAME}/$1" ]] ; then
+ echo "$(< ${svcdir}/options/${SVCNAME}/$1)"
fi
return 0
@@ -512,7 +512,7 @@ add_suffix() {
#
get_base_ver() {
[[ ! -r /etc/gentoo-release ]] && return 0
- local ver=$(</etc/gentoo-release)
+ local ver="$(</etc/gentoo-release)"
echo "${ver##* }"
}
@@ -687,7 +687,7 @@ if [[ -z ${EBUILD} ]] ; then
# have a TTY. rc unsets it at the end of running so it shouldn't hang
# around
if [[ -z ${CONSOLETYPE} ]] ; then
- export CONSOLETYPE=$( /sbin/consoletype 2>/dev/null )
+ export CONSOLETYPE="$( /sbin/consoletype 2>/dev/null )"
fi
if [[ ${CONSOLETYPE} == "serial" ]] ; then
RC_NOCOLOR="yes"
@@ -704,6 +704,12 @@ if [[ -z ${EBUILD} ]] ; then
done
setup_defaultlevels
+
+ # If we are not /sbin/rc then ensure that we cannot change level variables
+ if [[ -n ${BASH_SOURCE} \
+ && ${BASH_SOURCE[${#BASH_SOURCE[@]}-1]} != "/sbin/rc" ]] ; then
+ declare -r BOOTLEVEL DEFAULTLEVEL SOFTLEVEL
+ fi
else
setup_defaultlevels
# Should we use colors ?
@@ -724,8 +730,8 @@ if [[ -n ${EBUILD} && $* == *depend* ]] ; then
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=$(set -- `stty size 2>/dev/null` ; echo $2)
+ COLS="${COLUMNS:-0}" # bash's internal COLUMNS variable
+ (( COLS == 0 )) && COLS="$(set -- `stty size 2>/dev/null` ; echo "$2")"
(( COLS > 0 )) || (( COLS = 80 )) # width of [ ok ] == 7
fi