file.sh
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
##
# some functions for file handling...this includes a kind of
# include_once for shell scripts. This one also includes the
# utils/program.sh file as it is needed in all scripts.
#
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
}
include_once utils/programs.sh
fi
# vim: set ts=4 sw=4: