# Authors: grml-team (grml.org), (c) Michael Gebetsroither <gebi@grml.org>
# Bug-Reports: see http://grml.org/bugs/
# License: This file is licensed under the GPL v2.
-# Latest change: Mon May 02 00:17:44 CEST 2005 [gebi]
################################################################################
LANG__="$LANG"
LC_ALL__="$LC_ALL"
+LANGUAGE__="$LANGUAGE"
# CONFIG FUNCTIONS {{{
function disableSyslog { SYSLOG__="NO"; }
function enableSyslog { SYSLOG__="YES"; }
-function saveLang { LANG__="$LANG"; LC_ALL__="$LC_ALL"; }
-function restoreLang { LANG="$LANG__"; LC_ALL="$LC_ALL__"; }
-function setCLang { saveLang; LANG="C"; LC_ALL="C"; }
+function saveLang { LANG__="$LANG"; LC_ALL__="$LC_ALL"; LANGUAGE__="$LANGUAGE"; }
+function restoreLang { LANG="$LANG__"; LC_ALL="$LC_ALL__"; LANGUAGE="$LANGUAGE__"; }
+function setCLang { saveLang; LANG="C"; LC_ALL="C"; LANGUAGE="C"; }
# }}}
local level_="$1"
local type_="$2"
local message_="$3"
-
+
if [ $VERBOSE__ -ge $level_ -a -n "$message_" ]; then
echo -n "$type_" >&2
echo "$message_" >&2
{
local message_="$1" # error message
local exit_code_="$2"
-
+
if [ -n "$exit_code_" ]; then
logger -p user.alert -t "$PROG_NAME__" -i "$message_ ret($exit_code_)" >&2
else
###
##
-# ATTENTION... THIS FUNCTINOS IS A BIG SECURITY HOLE
+# ATTENTION... THIS FUNCTION IS A BIG SECURITY HOLE
# this function will be changed in future release
##
-# i don't want to write exit status controle stuff every time
+# I don't want to write exit status control stuff every time
function execute
{
local to_exec_="$1" # command to execute
if [ -e "$file_to_test_" ]; then
if [ -z "$message_" ]; then
- $error_function_ "file does allready exist \"$file_to_test_\"" 67
+ $error_function_ "file does already exist \"$file_to_test_\"" 67
else
$error_function_ "$message_"
fi
function isGrml
{
- if [ -f /etc/grml_version ] ; then
+ if [ -f /etc/grml_version ] ; then
dprint "isGrml(): this seems to be a grml system"
- return 0
- else
+ return 0
+ else
dprint "isGrml(): this is not a grml system"
- return 1
- fi
+ return 1
+ fi
}
function runsFromHd
function secureInput
{
local to_secure_="$1"
-
+
local secured_=''
secured_=`echo -n "$to_secure_" |tr -c '[:alnum:]/.\-,\(\)' '_'`
echo "$abspath_"
}
+
+# Trim off white-space characters
+# white-space in the "C" and "POSIX" locales are:
+# space
+# form-feed ('\f')
+# newline ('\n')
+# carriage return ('\r')
+# horizontal tab ('\t')
+# vertical tab ('\v')
+function stringTrim
+{
+ local str_="$1"
+ local result_=""
+
+ result_="`echo "$str_" | sed -e 's/^\s*//' -e 's/\s*$//'`" || \
+ warn "stringTrim(): Problems stripping of blanks" || return 1
+ dprint "stringTrim(): \"$str_\" => \"$result_\""
+ echo "$result_"
+}
+
# Simple shell grep
function stringInFile
{
# validates an IP FIXME
function netValidIp
{
- local ip_="$1" # ip addresse to validate
+ local ip_="$1" # ip address to validate
local error_function_=${2:-"eprint"} # function to call on error
local message_="$3" # user supplied error message
-
+
local ret_=''
echo "$ip_" | grep -E -q -e '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}' \
ret_=$?
if [ $ret_ -ne 0 ]; then
if [ -z "$message_" ]; then
- "$error_function_" "ip-addresse \"$ip_\" is NOT valied" $ret_
+ "$error_function_" "ip-address \"$ip_\" is NOT valid" $ret_
else
"$error_function_" "$message_" $ret_
fi
return 1
fi
- dprint "ip-addresse \"$ip_\" is valied" $ret_
+ dprint "ip-address \"$ip_\" is valid" $ret_
return $ret_
}
{
local error_function_=${1:-"eprint"} # function to call on error
local message_="$2" # user supplied error message
-
+
local ip_=''
local ret_=''
-
+
setCLang
ip_=`route -n | awk '/^0\.0\.0\.0/{print $2; exit}'`
ret_=$?
local iface_="$1"
local error_function_=${2:-"eprint"} # function to call on error
local message_="$3" # user supplied error message
-
+
local nm_=''
local ret_=''
-
+
setCLang
nm_=`ifconfig "$iface_" | awk '/[Mm]ask/{FS="[: ]*"; $0=$0; print $8; exit}'`
ret_=$?
if [ -z "$nm_" ]; then
if [ -z "$message_" ]; then
"$error_function_" "could not find a netmask for \"$iface_\"" $ret_
- else
+ else
"$error_function_" "$message_" $ret_
fi
return 1
fi
return 1
fi
- dprint "addresse for \"$iface_\" is \"$ip_\"" $ret_
+ dprint "address for \"$iface_\" is \"$ip_\"" $ret_
echo "$ip_"
return 0
-}
+}
function netGetNameservers
{
local error_function_=${1:-"eprint"} # function to call on error
local message_="$2" # user supplied error message
-
+
local file_="/etc/resolv.conf"
local ns_=""
warn "file \"$file_\" does not exist, could not get nameservers"
return 1
fi
-
+
setCLang
ns_=`awk '/^nameserver/{printf "%s ",$2}' $file_ |xargs echo`
restoreLang
if [ ! -x "$service_path_" ]; then
warn "_touchService(): service is not executable: \"$service_\""
fi
-
+
local ret_=""
"$service_path_" "$action_"
ret_=$?
local tmp_='' # tmp
local i='' # counter
local ret_='' # saved return value
-
+
for i in 'losetup' 'losetup.orig'; do
tmp_=`$i -f 2>/dev/null`
if [ $? -eq 0 ]; then
function _initProgName
{
local name_="$1" # program name
-
+
local tmp_name_=`basename "$name_"` || \
logger -p user.alert -i "Init-initProgName: problems executing ( basename \"$name_\" ) ret($?)" >/dev/null
-
+
secureInput "$tmp_name_"
}
PROG_NAME__=`_initProgName "$0"`