You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.4 KiB
103 lines
2.4 KiB
#!/bin/dash
|
|
|
|
##
|
|
# make definitions only when not already defined
|
|
#
|
|
|
|
command -v filename2symbol >/dev/null
|
|
if [ $? -ne 0 ]
|
|
then
|
|
filename2symbol() {
|
|
local SYM="${1}"
|
|
|
|
if [ 1 -ne $# ]
|
|
then
|
|
${LOGGER} -p syslog.err 'filename2sybol: missing filename'
|
|
exit 1
|
|
fi
|
|
|
|
while [ "${SYM}" != "${SYM%/*}" -o "${SYM}" != "${SYM%.*}" ]
|
|
do
|
|
if [ "${SYM}" != "${SYM%.*}" ]
|
|
then
|
|
SYM="${SYM%%.*}_${SYM#*.}"
|
|
else
|
|
SYM="${SYM%%/*}_${SYM#*/}"
|
|
fi
|
|
done
|
|
|
|
echo "${SYM}"
|
|
}
|
|
|
|
##
|
|
# create an absolute filename from a given relative one.
|
|
# This deals only with leading ./ and ../ it does not
|
|
# handle then when they are in the middle of the name.
|
|
#
|
|
abs_filename() {
|
|
local FILE="${1}"
|
|
local DIR="${PWD}"
|
|
|
|
# if FILE starts with a / its already absolute
|
|
if [ "${FILE}" != ${FILE#/} ]
|
|
then
|
|
echo "${FILE}"
|
|
return 0
|
|
fi
|
|
|
|
# simply remove ./ and make a ../ remove a part from pwd
|
|
while [ "${FILE}" != ${FILE#./} -o "${FILE}" != ${FILE#../} ]
|
|
do
|
|
if [ "${FILE}" != ${FILE#./} ]
|
|
then
|
|
FILE="${FILE#./}"
|
|
else
|
|
FILE="${FILE#../}"
|
|
DIR="${DIR%/*}"
|
|
fi
|
|
done
|
|
|
|
echo "${DIR}/${FILE}"
|
|
}
|
|
|
|
include_once() {
|
|
local FILE="$(abs_filename "${1}")"
|
|
local SYM="$(filename2symbol "${FILE}")"
|
|
|
|
if [ 1 -ne $# ]
|
|
then
|
|
${LOGGER} -p syslog.err 'include_once: missing filename'
|
|
exit 1
|
|
fi
|
|
|
|
if eval [ -z \"\${SOURCED_${SYM}}\" ]
|
|
then
|
|
eval export SOURCED_${SYM}=\"\${FILE}\"
|
|
. ${FILE}
|
|
fi
|
|
}
|
|
|
|
##
|
|
# get and export the locations of used programs and export them
|
|
# I assume that on every UNIX/shell variant at least [ is globally
|
|
# available. I will use it throughout all other scripts without
|
|
# checking for existence.
|
|
# I also assume through all scripts that eval is available.
|
|
#
|
|
[ -z "${WHICH}" ] && WHICH="/usr/bin/which"
|
|
[ -z "${UNAME}" ] && UNAME="$(${WHICH} uname)"
|
|
[ -z "${GREP}" ] && GREP="$(${WHICH} grep)"
|
|
[ -z "${AWK}" ] && AWK="$(${WHICH} awk)"
|
|
[ -z "${ECHO}" ] && ECHO="$(${WHICH} echo)"
|
|
[ -z "${SORT}" ] && SORT="$(${WHICH} sort)"
|
|
[ -z "${TR}" ] && TR="$(${WHICH} tr)"
|
|
[ -z "${PRINTF}" ] && PRINTF="$(${WHICH} printf)"
|
|
[ -z "${LOGGER}" ] && LOGGER="$(${WHICH} logger)"
|
|
[ -z "${NPROC}" ] && NPROC="$(${WHICH} nproc)"
|
|
[ -z "${IP}" ] && IP="$(${WHICH} ip)"
|
|
[ -z "${IFCONFIG}" ] && IFCONFIG="$(${WHICH} ifconfig)"
|
|
|
|
export WHICH UNAME GREP AWK ECHO SORT TR PRINTF LOGGER IP IFCONFIG
|
|
fi
|
|
|
|
# vim: set ts=4 sw=4:
|