|
Karanbir Singh |
2dd0be |
#!/bin/bash
|
|
Karanbir Singh |
2dd0be |
|
|
Steve Barnes |
e801dc |
# Description: call this function whenever you need to log output (preferred to calling echo)
|
|
Steve Barnes |
e801dc |
# Arguments: log string to display
|
|
Karanbir Singh |
2dd0be |
function t_Log
|
|
Karanbir Singh |
2dd0be |
{
|
|
Steve Barnes |
e801dc |
printf "[+] `date` -> $*\n"
|
|
Karanbir Singh |
2dd0be |
}
|
|
Karanbir Singh |
2dd0be |
|
|
Steve Barnes |
e801dc |
# Description: call this at the end of your script to assess the exit status
|
|
Steve Barnes |
e801dc |
# Arguments: the exit status from whatever you want checked (ie, '$?')
|
|
Karanbir Singh |
2dd0be |
function t_CheckExitStatus
|
|
Karanbir Singh |
2dd0be |
{
|
|
Steve Barnes |
e801dc |
[ $1 -eq 0 ] && { t_Log "PASS"; return $PASS; }
|
|
Karanbir Singh |
2dd0be |
|
|
Steve Barnes |
e801dc |
t_Log "FAIL"
|
|
Steve Barnes |
e801dc |
exit $FAIL
|
|
Karanbir Singh |
2dd0be |
}
|
|
Karanbir Singh |
2dd0be |
|
|
Steve Barnes |
e801dc |
# Description: call this to perform yum-based installs of packages
|
|
Steve Barnes |
e801dc |
# Arguments: a space separated list of package names to install.
|
|
Karanbir Singh |
2dd0be |
function t_InstallPackage
|
|
Karanbir Singh |
2dd0be |
{
|
|
Steve Barnes |
e801dc |
t_Log "Attempting yum install: $*"
|
|
Steve Barnes |
e801dc |
/usr/bin/yum -y -d0 install "$@"
|
|
Steve Barnes |
e801dc |
t_CheckExitStatus $?
|
|
Karanbir Singh |
2dd0be |
}
|
|
Karanbir Singh |
2dd0be |
|
|
Steve Barnes |
e801dc |
# Description: call this to perform a yum-based removal of packages
|
|
Steve Barnes |
e801dc |
# Arguments: a space separated list of package names to remove.
|
|
Karanbir Singh |
2dd0be |
function t_RemovePackage
|
|
Karanbir Singh |
2dd0be |
{
|
|
Steve Barnes |
e801dc |
t_Log "Attempting yum remove: $*"
|
|
Steve Barnes |
e801dc |
/usr/bin/yum -y -d0 remove "$@"
|
|
Steve Barnes |
e801dc |
t_CheckExitStatus $?
|
|
Karanbir Singh |
2dd0be |
}
|
|
Karanbir Singh |
2dd0be |
|
|
Steve Barnes |
e801dc |
# Description: call this to process a list of folders containing test scripts
|
|
Steve Barnes |
e801dc |
# Arguments: a list of folder paths to process (see example in runtests.sh)
|
|
Steve Barnes |
464547 |
function t_Process
|
|
Karanbir Singh |
2dd0be |
{
|
|
Steve Barnes |
464547 |
exec 7< $@
|
|
Steve Barnes |
464547 |
|
|
Steve Barnes |
464547 |
while read -u 7 f
|
|
Steve Barnes |
e801dc |
do
|
|
Steve Barnes |
e801dc |
# skip files named readme or those that start with an _
|
|
Steve Barnes |
e801dc |
[[ "${f}" =~ readme|^_ ]] && continue;
|
|
Steve Barnes |
e801dc |
|
|
Steve Barnes |
464547 |
# handy tip: chmod -x to disable individual test scripts.
|
|
Steve Barnes |
e801dc |
[ -x ${f} ] && ${f}
|
|
Steve Barnes |
e801dc |
|
|
Steve Barnes |
464547 |
done
|
|
Steve Barnes |
e801dc |
|
|
Steve Barnes |
e801dc |
return 0
|
|
Steve Barnes |
e801dc |
}
|
|
Steve Barnes |
e801dc |
|
|
Steve Barnes |
e801dc |
# Description: check to see if one or more packages are installed
|
|
Steve Barnes |
e801dc |
# return true if they're all installed, false if not.
|
|
Steve Barnes |
e801dc |
# Arguments: one or more package names to check for.
|
|
Steve Barnes |
e801dc |
function t_CheckDeps
|
|
Steve Barnes |
e801dc |
{
|
|
Steve Barnes |
e801dc |
# TODO
|
|
Steve Barnes |
e801dc |
|
|
Steve Barnes |
e801dc |
# success, all packages are installed
|
|
Steve Barnes |
e801dc |
return 0
|
|
Karanbir Singh |
2dd0be |
}
|
|
Karanbir Singh |
2dd0be |
|
|
Steve Barnes |
464547 |
# Description: perform a service control and sleep for a few seconds to let
|
|
Steve Barnes |
464547 |
# the dust settle. Failing to do this means tests that check for an
|
|
Steve Barnes |
464547 |
# open network port or response banner will probably fail for no
|
|
Steve Barnes |
464547 |
# apparent reason.
|
|
Steve Barnes |
464547 |
function t_ServiceControl
|
|
Steve Barnes |
464547 |
{
|
|
Steve Barnes |
464547 |
/sbin/service $1 $2
|
|
Steve Barnes |
464547 |
|
|
Steve Barnes |
464547 |
# aaaand relax...
|
|
Steve Barnes |
464547 |
sleep 3
|
|
Steve Barnes |
464547 |
}
|
|
Steve Barnes |
464547 |
|
|
Karanbir Singh |
2dd0be |
export -f t_Log
|
|
Karanbir Singh |
2dd0be |
export -f t_CheckExitStatus
|
|
Karanbir Singh |
2dd0be |
export -f t_InstallPackage
|
|
Karanbir Singh |
2dd0be |
export -f t_RemovePackage
|
|
Steve Barnes |
464547 |
export -f t_Process
|
|
Steve Barnes |
e801dc |
export -f t_CheckDeps
|
|
Steve Barnes |
464547 |
export -f t_ServiceControl
|