#! /bin/bash
#==========coloring==========================
# echo -e '\E[30m black \E[31mred \E[32mgreen \E[33myellow \E[34mblue \E[35mmagenta \E[36mcyan \E[37mwhite'
# echo -e "\E[31m\033[1mBOOOLD\033[0m"
#============Settings========================
cd /usr/src/mor
. "$(pwd)"/sh_scripts/install_configs.sh
. "$(pwd)"/sh_scripts/mor_install_functions.sh
. "$(pwd)"/test/asterisk_test.sh
. "$(pwd)"/test/miscellaneous.sh
# . "$(pwd)"/sh_scripts/various_install_functions.sh no such file
TEST_SCRIPT_MODE=0; # 0 - diagnose only; 1 = fix if possible
_M_python=`which python`;
#========== functions ================
check_config_line_and_execute_cmd2() #copied from mor install functions and modified to not fix the problem, jus diagnose it
{ #----------------------------
#function checks file for a specific line and executes a cmd if a line does not exist
#arg1=path to file
#arg2=string to check
#arg3=what to write in report
#arg4=cmd to execute
#-----------------------------
cat "$1" | grep "^$2" &> /dev/null
if [ $? == 1 ]; then
#$4 #executing cmd
cat "$1" | grep "^$2" &> /dev/null
if [ $? == 1 ]; then report_to_stdout 1 "$3"
else report_to_stdout 5 "$3"
fi
fi
if [ $? == 0 ]; then
report_to_stdout 0 "$3"
fi
}
#========================================
report()
{
#parameters
#1 - string what are you testing + tabs
#2 {"FAILED", "OK"} prints only OK or FAILED if present
if [ "$?" == "0" ]; then
if [ "$2" == "FAILED" ]; then return 0; fi #causes not to print [OK] blabblabla
echo -e "$1\t[\E[32m OK \E[37m]";
return 0;
else
ALL_OK=1
if [ "$2" == "OK" ]; then return 1; fi
echo -e "$1\t[\E[31m FAILED \E[37m]";
return 1;
fi
}
#========================================
crontab_add2()
{
#argument 1 - string to check in crontab
#argument 2 - string to add to crontab
#argument 3 - string to use when printing the results
#example: crontab_add "mor_ad_cron.log" "*/5 * * * * /home/mor_ad/mor_ad_cron >> /home/mor_ad/mor_ad_cron.log" "Autodialer_installed"
crontab_check "$1";
if [ $? == 0 ]; then
report_to_stdout 0 "$3"
return 0;
fi
}
#===========
exec_and_evaluate_warning()
{
if [ -z "$1" ]; then echo "Argument not passed for function evaluation"; read a; fi;
# first argument - test function name
$1 $2; #executing test
result=$?;
if [ "$result" != "0" ];
then
echo -e "\t\t\t\t\t\t\t$3[\E[33mWARNING!\E[37m]";
echo "$1 failed" >> $_log
elif [ "$result" == "0" ]; then
echo -e "\t\t\t\t\t\t\t$3[\E[32m OK \E[37m]";
fi
}
#=======================================
exec_and_evaluate_python()
{
if [ -z "$1" ]; then echo "Argument not passed for function evaluation"; read a; fi;
# first argument - python test script name with parameters
cd /usr/src/mor/test
$_M_python $1; #executing test
result=$?;
if [ "$result" != "0" ];
then
echo -e "\t\t\t\t[\E[31mFailed\E[37m]";
echo "$1 failed" >> $_log
elif [ "$result" == "0" ]; then echo -e "\t\t\t\t[\E[32m OK \E[37m]";
fi
}
#==========Pending delete?===============================
mime_construct()
{ #this function can't be made to look better, because the output of mime-construct is being redirected to stderr
echo -n "Checking mime-construct";
_MIME_CONSTRUCT_STATUS=`mime-construct | grep -i 'no recipients specified' `;
echo "$__MIME_CONSTRUCT_STATUS"
if [ -n $_MIME_CONSTRUCT_STATUS ];
then echo -e "\t[OK]";
else echo -e "\t[Failed]";
fi
}
#========================================
registration_script_test()
{ echo -ne "Testing registration script\t\t";
if [ -r /usr/local/mor/mor_ast_register ];
then return 0;
else return 1;
fi
}
#--------------------------------------------
fcgid_config_test()
{
echo -ne "Testing fcgid_config\t\t\t";
which_os;
if [ "$OS" == "DEBIAN" ];
then
_fcgid=`cat /etc/apache2/mods-enabled/fcgid.conf | grep "
AddHandler fcgid-script .fcgi
SocketPath /var/lib/apache2/fcgid/sock
DefaultInitEnv RAILS_ENV production
IdleTimeout 600
BusyTimeout 6000
ProcessLifeTime 3600
MaxProcessCount 8
DefaultMinClassProcessCount 3
DefaultMaxClassProcessCount 3
IPCConnectTimeout 8
IPCCommTimeout 6000
" | grep -m1 "Socke*"`;
if [ -n "$_fcgid" ];
then return 0;
else return 1;
fi;
else if [ "$OS" == "CENTOS" ];
then
_fcgid=`cat /etc/httpd/conf.d/mod_fcgid_include.conf | grep "
IdleTimeout 600
BusyTimeout 6000
ProcessLifeTime 3600
MaxProcessCount 16
DefaultMinClassProcessCount 3
DefaultMaxClassProcessCount 30
IPCConnectTimeout 8
IPCCommTimeout 6000
" | grep -m1 "MaxProcessCount*"`
if [ -n "$_fcgid" ];
then return 0;
else return 1;
fi;
fi
fi;
}
#========================================
dir_exists()
{
if [ -d "$1" ]; then return 0;
else return 1;
fi
}
#========================================
ip_tables_installed()
{ #argument $2 is for formatting (tabs, and etc)
echo -ne "Checking whether iptables installed $2"
IP_TABLES=`which iptables`;
if [ -z "$IP_TABLES" ]; then return 0;
else return 1;
fi
}
#========================================
file_exist()
{ echo -ne "Checking whether $1 exists $2"
if [ -f "$1" ]; then return 0;
else return 1;
fi
}
#========================================
selinux_stat()
{
echo -ne "Checking whether SElinux disabled $2"
if [ "$OS" == "CENTOS" ]; then
SEL=`sestatus | grep "disabled"`
if [ -n "$SEL" ]; then return 0;
else return 1;
fi
else
return 0;
fi
}
#============ main ============================================================================================================
#====== Disabled tests =======
#mime_construct
#/usr/src/mor/sh_scripts/check_autodialer.sh
#=====================================================
/usr/src/mor/sh_scripts/kolmisoft_logo_txt.sh
echo -e "\n\n=====================================================================\n"
echo -e "\t\t\033[1mMOR INSTALLATION TESTING SCRIPT\033[0m";
echo -e "\n=====================================================================\n"
#================= MySQL tests ====================
exec_and_evaluate file_exist /etc/my.cnf "\t"
if [ -r /etc/my.cnf ]; then
echo -e "\E[36m=================MySQL tests===================\E[37m"
############insert_line_after_pattern "\[mysqld\]" "max_allowed_packet=100M" "/etc/my.cnf" ;
#/etc/init.d/mysqld restart
mysql_replication_test
echo;
fi
#==================================================
exec_and_evaluate asterisk_exist "Checking_if_asterisk_exists" "\t\t\t"
asterisk_exist; #not duplicate, used to get another return status
if [ $? == 0 ]; then
echo -e "\E[36m===== Asterisk =====================\E[37m"
exec_and_evaluate realtime_mysql_status "" "\t"
exec_and_evaluate codecs_status "" "\t"
exec_and_evaluate h323_status "" "\t"
exec_and_evaluate asterisk_junk_files "" "\t\t"
exec_and_evaluate fax2email_status "" "\t"
check_asterisk_extcfg
check_sip_cfg_test
check_iax
#these two will display test resuls only if asterisk is newer than 1.4.18.1
check_extensions_mor.conf
extensions_mor_ad.conf
fail2ban_test
echo -e "\E[36m === checking asterisk dirs===============\E[37m"
exec_and_evaluate dir_exists "/var/lib/asterisk" "Checking whether /var/lib/asterisk dir exist\t"
exec_and_evaluate dir_exists /usr/lib/asterisk "Checking whether /usr/lib/asterisk dir exist\t"
exec_and_evaluate dir_exists /etc/asterisk "Checking whether /etc/asterisk dir exist\t"
echo -e "\E[36m====================================\E[37m"
fi
echo -e "\E[36m\n======= Miscellaneous tests =======================\E[37m"
if [ $INSTALL_APP == 1 ]; then exec_and_evaluate lame_test "" "\t"; fi;
autodialer_tst #not duplicate, waiting for return status
if [ $? != 3 ]; then
echo -e "\E[36m===================Checking Auto-Dialer Addon==========\E[37m"
exec_and_evaluate autodialer_tst "Cheking_AUTO-DIALER_connectivity" "\t\t" ;
#crontab_add "mor_ad_cron.log" "*/5 * * * * /home/mor_ad/mor_ad_cron >> /home/mor_ad/mor_ad_cron.log" "Checking if AUTO-DIALER crontab entry installed\t"
echo -e "\E[36m=======================================================\E[37m"
fi
if [ $INSTALL_GUI == 1 ]; then exec_and_evaluate localhost_accessibility_test "" "\t"; fi
exec_and_evaluate all_files_are_downloaded "" "\t"
exec_and_evaluate_warning selinux_stat "" "\t"
exec_and_evaluate registration_script_test "" "\t"
exec_and_evaluate fcgid_config_test "" "\t"
echo -e "\E[36m==============Checking dirs========================\E[37m"
exec_and_evaluate dir_exists /usr/local/mor "Checking whether /usr/local/mor dir exist\t"
if [ $INSTALL_GUI == 1 ]; then exec_and_evaluate dir_exists /home/mor "Checking whether /home/mor dir exist\t\t"; fi
exec_and_evaluate dir_exists /usr/local/mor "Checking whether /usr/local/mor dir exist\t"
exec_and_evaluate dir_exists /usr/local/mor/backups "Checking whether /usr/local/mor/backups dir exist"
exec_and_evaluate dir_exists /var/log/mor "Checking whether /var/log/mor dir exist\t\t"
echo -e "\E[36m==============Checking if required files exist=====\E[37m"
exec_and_evaluate file_exist /root/phpMyAdminPassword
if [ $INSTALL_GUI == 1 ]; then exec_and_evaluate file_exist /home/mor/log/production.log; fi
echo -e "\E[36m==============Checking for FULL duplex ================\E[37m"
/sbin/ifconfig | grep eth | awk '{ print $1}' | while read network_card; do
exec_and_evaluate ethtool_check_eth $network_card "\t\t"
done
echo -e "\E[36m=============Checking other crontab records=======================================\E[37m"
crontab_add2 "hourly_actions" "0 * * * * wget -o /dev/null -O /dev/null http://127.0.0.1/billing/callc/hourly_actions" "Hourly actions crontab installed\t\t\t\t"
crontab_add2 "daily_actions" "0 0 * * * wget -o /dev/null -O /dev/null http://127.0.0.1/billing/callc/daily_actions" "Daily actions crontab installed\t\t\t\t"
crontab_add2 "ntpdate.log" "0 * * * * /usr/sbin/ntpdate pool.ntp.org >> /var/log/ntpdate.log" "ntpdate crontab installed\t\t\t\t"
echo -e "\E[36m============================================================================\E[37m"
#============ ======
#space left on hdd tests
exec_and_evaluate_python "disk_space.py /var"
exec_and_evaluate_python "disk_space.py /home/mor"
exec_and_evaluate_python "disk_space.py /usr/local"
exec_and_evaluate_python "ram_available.py 384"
echo -e "\E[36m===================================================================================\E[37m"
#===================================
client_tag_test
report "Testing for [CLIENT] tag in /home/mor/config/environment.rb\t\t\t\t"
#/usr/src/mor/sh_scripts/test_gui.sh