diff --git a/Probe/utils.sh b/Probe/utils.sh new file mode 100644 index 0000000..e018d4c --- /dev/null +++ b/Probe/utils.sh @@ -0,0 +1,162 @@ +#!/bin/bash + +# host_addr=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"` +host_addr=`ifconfig -a|grep inet|grep -v inet6|grep -v 127.0.0.1|perl -pe 's/.*inet\s?(.*?)\s+.*/\1/g'`; +base_dir=`cd $(dirname $0); pwd -P`; + +function printSuccess(){ + echo -e "\033[92m\033[1m"$1"\033[0m"; +} + +function printFail(){ + echo -e "\033[91m\033[1m"$1"\033[0m"; +} + +function printInfo(){ + echo -e "\033[96m\033[1m"$1"\033[0m"; +} + +function printWarn(){ + echo -e "\033[101m\033[33m\033[1m"$1"\033[0m"; +} + +loadmsg_time=0; +function loadMsg(){ + let loadmsg_time++ + echo -ne "\r\033[33m\033[1m"$1"("$loadmsg_time"s)\033[0m\r"; +} + +function ostype(){ + os=`lsb_release -a|grep "Distributor ID"|awk '{print $3}'`; + echo $os; +} + +function mkd () { + if [ ! -d "$1" ]; then + mkdir -p $1 + fi +} + + +function puase () { + read -n 1 -p "Press A-Z key to continue..." INP + if [[ -n "${INP}" ]] ; then + echo -ne '\b \n' + fi +} + + +function firewall-addport(){ + if [ "`firewall-cmd --zone=public --query-port=$1/tcp`" = "no" ]; then + printInfo "防火墙添加端口$1,执行结果:"`firewall-cmd --permanent --zone=public --add-port=$1/tcp` + printInfo "防火墙重载,执行结果:"`firewall-cmd --reload` + else + printInfo "防火墙已存在端口$1"; + fi +} + +function firewall-addservice(){ + if [ "`firewall-cmd --zone=public --query-service=$1`" = "no" ]; then + printInfo "防火墙添加服务$1,执行结果:"`firewall-cmd --permanent --zone=public --add-service=$1` + printInfo "防火墙重载,执行结果:"`firewall-cmd --reload` + else + printInfo "防火墙已存在服务$1"; + fi +} + +function firewall-must-run(){ +# if [[ "`systemctl status firewalld.service|grep Active|awk '{print $2}'`" != "active" ]]; +# then +# printFail "防火墙未启动!"; +# exit; +# else +# printSuccess "防火墙状态正常。"; +# fi + if [ "`firewall-cmd --state`" != "running" ]; + then + printFail "防火墙未启动!"; + exit; + else + printSuccess "防火墙状态正常。"; + fi +} + +function requireJava(){ + if [ ! -f "/opt/jdk/bin/java" ]; + then +bash /home/shell/java-install.sh<