-
Notifications
You must be signed in to change notification settings - Fork 3
/
base.blp
185 lines (161 loc) · 4.95 KB
/
base.blp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env bash
############
# base.blp - A bash library of common functions to increase reusability of code
#
#
# @install /usr/local/lib/blp
# installation- It is recommended that this file be placed in /usr/local/lib and sourced
# into your code via the . /usr/local/lib/base.blp method
#
# Conventions:
# Funciton names start with lower case followed by camel text
# Variables start with upper case followed by camel text
# Library constants are written in ALL upper case letters. The should limit the amount of name space munging.
#
# @author Mikel King <mikel.king@olivent.com>
# @descr
# @copyright 2012 Olivent Technologies, llc
# @package base.blp
# @version 2.0
# @license http://opensource.org/licenses/bsd-license.php New/Simplified BSD License
# @TODO add improved library handling and sourcing as well as move include and require to std.blp
# both include and require should be able to search a series of paths for the target file. These
# are some good examples.
# /usr/local/lib/blp
# /usr/local/lib
# /usr/local/lib/${MyName}
# ./
#
SILENT=${FALSE}
QUIET=${FALSE}
RETURN=${TRUE}
# echo "Funtion name: ${FUNCNAME}"
# @experimental
# @method getSrcPath
# @descr this is an experimental function mostly for research. I was just trying to
# validate a theory. I'll purge it from the blp in the 2.0 release
# @todo purge from blp
# @param void
function getSrcPath() {
# In this example dirname returns . which means we have just a file name to contend with.
# Ultimately as a result of the way in which dirname processes the file name the path will
# always be different.
blp=string.blp
blpPath=`dirname ${blp}`
if [ "${blpPath}" != "." ];
then
echo "Fantastic we have a winner! They are not equal."
else
echo "Ok looks like we need ot try the default blp path, because they are equal."
fi
echo "blpPath: ${blpPath} & blp: ${blp} results"
}
# If the appropriate Optarg is set then warning and below output is suppressed.
#
# @TODO gather diagnostic information and output that in lieu of the normal output.
# need to dump a bunch of version info and path info to the screen.
# this will be an involved function and
# @method debugOpt
# @return $DEBUG
function debugOpt () {
DEBUG=${TRUE}
}
# If the appropriate Optarg is set then warning and below output is suppressed.
# This was functionalized because I intended to add more to it.
#
# @method silentOpt
# @return $SILENT
function silentOpt () {
SILENT=${TRUE}
}
# If the appropriate Optarg is set then warning and below output is suppressed.
# This was functionalized because I intended to add more to it.
#
# @method unsetSilentOpt
# @return $SILENT
function unsetSilentOpt () {
SILENT=${FALSE}
}
# If the appropriate Optarg is set then ALL output is suppressed.
# This was functionalized because I intended to add more to it.
#
# @method quiteOpt
# @return $QUIET
function quietOpt () {
QUIET=${TRUE}
}
# If the appropriate Optarg is set then ALL output is suppressed.
# This was functionalized because I intended to add more to it.
#
# @method suppressLoggingOpt
# @return $QUIET
function suppressLoggingOpt () {
SupressLogging=${TRUE}
}
# If the appropriate Optarg is set then app version is displayed
#
# @method version
# @return
function version () {
outputMsg "${LongName} - Version ${Version}: ${Descr} "
}
# @method logOutput
# @param string $1
# @global $LogTag = A tag to identify your entry
# @global $LogCMD = the path to logger
# @global $MSG
# A simple output catcher to facilitate quiet and silence modes
function logOutput() {
if [ ${SupressLogging} -eq ${FALSE} ];
then
if [[ ! ${1+isset} = isset ]];
then
echo ${MSG} | ${LogCMD} -t ${LogTag}
else
echo "${1}" | ${LogCMD} -t ${LogTag}
fi
fi
}
#
#
#
# @method getArrayTop
# @descr Takes a string treating it like an array then extracts the top element
# @return $Fore
function getArrayTop() {
if [[ ! ${1+isset} = isset ]];
then
Fore=${1}
shift
else
throw 4
fi
echo ${Fore}
}
# Unfortunately one of the main drawbacks of bash is the lack of decent process handling. It has been argued and I am of the opinion that as soon as you
# consider doing something that requires the complication of process handling even something as simple as knowing your script's PID you must resort to
# a different language. FYI...Even using solution like pidof() return less than desirable results. Perhaps bash4 will address this short coming?
#
# @method getMyPid
# @descr
# @return $MyPid
function getMyPid() {
if [[ ! ${1+isset} = isset ]];
then
echo "Received var 1 ${1}"
Process=`ps ax|grep "${1}|head -1"`
echo "Nothing found? ${Process}"
getArrayTop ${Process}
MyPid=${Fore}
else
Process=`ps ax|grep ${SrvcName}|head -1`
echo ${Process}
getArrayTop ${Process}
MyPid=${Fore}
echo "Using default ${SrvcName}"
fi
}
# The following functions can be cirmcumvented by defining the associated values for ConfPath, blpPath & UsrblpPath respectively
#setConfPath
#setblpPath
#setUsrblpPath