|
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)
|
|
Karanbir Singh |
2dd0be |
function t_ProcessFolder
|
|
Karanbir Singh |
2dd0be |
{
|
|
Steve Barnes |
e801dc |
while read 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 |
e801dc |
# handy tip: chmod ug-x to disable individual test scripts.
|
|
Steve Barnes |
e801dc |
[ -x ${f} ] && ${f}
|
|
Steve Barnes |
e801dc |
|
|
Steve Barnes |
e801dc |
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 |
|
|
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
|
|
Karanbir Singh |
2dd0be |
export -f t_ProcessFolder
|
|
Steve Barnes |
e801dc |
export -f t_CheckDeps
|
|
Steve Barnes |
e801dc |
|