| #!/bin/bash |
| |
| |
| |
| |
| function t_Log |
| { |
| printf "[+] `date` -> $*\n" |
| } |
| |
| |
| |
| function t_CheckExitStatus |
| { |
| [ $1 -eq 0 ] && { t_Log "PASS"; return $PASS; } |
| |
| t_Log "FAIL" |
| exit $FAIL |
| } |
| |
| |
| |
| function t_InstallPackage |
| { |
| t_Log "Attempting yum install: $*" |
| /usr/bin/yum -y -d${YUMDEBUG} install "$@" |
| |
| |
| t_CheckExitStatus $? |
| } |
| |
| |
| |
| function t_RemovePackage |
| { |
| t_Log "Attempting yum remove: $*" |
| /usr/bin/yum -y -d0 remove "$@" |
| t_CheckExitStatus $? |
| } |
| |
| |
| |
| function t_Process |
| { |
| exec 7< $@ |
| |
| while read -u 7 f |
| do |
| |
| [[ "$(basename ${f})" =~ readme|^_ ]] && continue; |
| |
| |
| [ -x ${f} ] && ${f} |
| |
| done |
| |
| return 0 |
| } |
| |
| |
| |
| |
| function t_CheckDeps |
| { |
| |
| |
| |
| return 0 |
| } |
| |
| |
| |
| |
| |
| |
| |
| function t_ServiceControl |
| { |
| if [ $2 = "cycle" ]; then |
| /sbin/service $1 stop > /dev/null 2>&1 |
| sleep 3 |
| /sbin/service $1 start |
| else |
| /sbin/service $1 $2 |
| fi |
| |
| |
| sleep 3 |
| } |
| |
| |
| function t_GetPkgRel |
| { |
| rpm -q --queryformat '%{RELEASE}' $1 |
| } |
| |
| |
| function t_DistCheck |
| { |
| rpm -q $(rpm -qf /etc/redhat-release) --queryformat '%{version}\n'|cut -f 1 -d '.' |
| } |
| |
| centos_ver=$(t_DistCheck) |
| |
| |
| function t_GetPkgVer |
| { |
| rpm -q --queryformat '%{version}' $1 |
| } |
| |
| |
| function t_GetArch |
| { |
| rpm -q --queryformat '%{arch}\n' centos-release |
| } |
| |
| function t_CheckForPort |
| { |
| while true |
| do |
| sleep 1 |
| >/dev/null 2>&1 >/dev/tcp/localhost/$1 |
| if [ "$?" = "0" ] ; then |
| t_Log "Waiting for tcp port $1 to be listening ..." |
| break |
| fi |
| done |
| |
| } |
| |
| function t_Assert |
| { |
| $@ >/dev/null 2>&1 |
| t_CheckExitStatus $? |
| } |
| |
| function t_Assert_Equals |
| { |
| [ $1 -eq $2 ] |
| t_CheckExitStatus $? |
| } |
| export -f t_Log |
| export -f t_CheckExitStatus |
| export -f t_InstallPackage |
| export -f t_RemovePackage |
| export -f t_Process |
| export -f t_CheckDeps |
| export -f t_ServiceControl |
| export -f t_GetPkgRel |
| export -f t_DistCheck |
| export -f t_GetPkgVer |
| export -f t_GetArch |
| export -f t_CheckForPort |
| export -f t_Assert |
| export -f t_Assert_Equals |
| export centos_ver |