| 关键词: nbsp port mobigw server mobi grep mobiwt etc mobihq mobiauth |
我现在跑到一个金融软件企业干活了,比起上一家干了小半年还没有营业执照的企业靠谱多了,而且现在总监也还是靠谱的。到公司后给我的第一个工作就是将软件配置写一个交互式的自动化脚本给工程人员,也是完成产品化、自动化的一个关键步骤。今天将它发出来,哈哈,也相当于给自己一个备忘。 #!/bin/bash ################## Warning ################################### ## This script is sitable for Centos 5.x , used by engineers ## ## to build 10jqka mobile server automaticly. # # ## +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ## ## V20110906-2.3 ## # # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++## ## Mobile B2B Department ## ############################################################################# cat << EOF Notification This script has run on RedHat/Centos 5.x , make sure you use the same OS . ** this script mobigw.conf only start 1 listen_port in hq & wt , if you want two ports ,you'd better add by yourself. ** yybinfo.info in this scripts is not config , you must config by your self. ** you must config hosts crontab rc.local by yourselves EOF sleep 6 # root run this script if [ $(id -u) != "0" ] then echo -e "Error!You must be root to run this script! " exit 1 fi echo ""echo ""echo "Environment is preparing,please wait ......"sleep 3 # check php /usr/bin/which php > /dev/null 2>&1 if [ $? = "0" ] then mv $(/usr/bin/which php) $(/usr/bin/which php).bak cp -p etc/php /usr/local/bin else cp -p etc/php /usr/local/bin fi ## config system files # bakcup initial files cp /etc/crontab /etc/crontab.rpmcp /etc/hosts /etc/hosts.rpmcp /etc/rc.d/rc.local /etc/rc.d/rc.local.rpm cp etc/mobigw.conf /etc/cp etc/mobihq.conf /etc/ sed -i "s/H:hq2:2:127.0.0.1:10002/#H:hq2:2:127.0.0.1:10002/g" /etc/mobigw.confsed -i "s/H:wt2:3:127.0.0.1:20002/#H:wt2:3:127.0.0.1:20002/g" /etc/mobigw.conf echo "Backuping necessary files !!! hosts,crontab,rc.local,checking whether have php "echo ""echo "Backup files are *.rpm"sleep 3echo ""echo "Check environment is OK !!! please configurate hosts crontab rc.local by yourself"echo ""sleep 3 echo "Begin config mobigw mobiauth mobihq mobiwt modules !!"echo ""echo ""sleep 3 # ---- mobigw ---------------- 脚本分割线 ----------------------- ## modify modigw.sh ; make sure http_port & tcp_port # mobigw http porthttp_port=$(grep "\-h " mobigw/mobigw.sh | awk '{print $3}') # mobigw tcp porttcp_port=$(grep "\-h " mobigw/mobigw.sh | awk '{print $5}') while truedo# input mobigw http portread -p "please enter your mobigw_http_port (initial is 80):" gw_http_port# input mobigw tcp portread -p "please enter your mobigw_tcp_port (initial is 9528):" gw_tcp_port read -p "continue?(y/n)" tipif [ "$tip" = "y" ] || [ "x$tip" = "x" ]then breakfidone if [ "x${gw_http_port}" = "x" ] then sed -i "s/${http_port}/80/g" mobigw/mobigw.shelse sed -i "s/${http_port}/${gw_http_port}/g" mobigw/mobigw.shfi if [ "x${gw_http_port}" = "x" ] then sed -i "s/${tcp_port}/9528/g" mobigw/mobigw.shelse sed -i "s/${tcp_port}/${gw_tcp_port}/g" mobigw/mobigw.shfi # ---- mobiauth ---------------- 脚本分割线 ----------------------- #mobiauth ip#auth_ip=$( grep -v "^#" /etc/mobigw.conf | grep "H\:" | grep um1 | awk -F ":" '{print $4}')auth_ip=$(grep -v "^#" /etc/mobigw.conf | grep "H\:" | grep um1 | awk -F ":" '{print $4}' | sed 's#\.#\\\.#g') # mobiauth portauth_port=$(grep -v "^#" /etc/mobigw.conf | grep "H\:" | grep um1 | awk -F ":" '{print $5}') # modify mobiauth.shauth_listen_port=$(grep "\-n" mobiauth/mobiauth.sh | awk '{print $4}') while true do# enter mobiauth ipread -p "please enter mobiauth_ip (example:127.0.0.1):" mobi_auth_ip # enter mobiauth portread -p "please enter mobiauth_port (example:9529):" mobi_auth_port read -p "continue?(y/n)" tip if [ "$tip" = "y" ] || [ "x$tip" = "x" ] then break fidone if [ "x${mobi_auth_ip}" = "x" ] then sed -i "/um1/ s#${auth_ip}#127.0.0.1#g" /etc/mobigw.conf else sed -i "/um1/ s#${auth_ip}#${mobi_auth_ip}#g" /etc/mobigw.conffi if [ "x${mobi_auth_port}" = "x" ] then sed -i "s/${auth_port}/9529/g" /etc/mobigw.conf sed -i "s/${auth_listen_port}/9529/g" mobiauth/mobiauth.sh else sed -i "s/${auth_port}/${mobi_auth_port}/g" /etc/mobigw.conf sed -i "s/${auth_listen_port}/${mobi_auth_port}/g" mobiauth/mobiauth.shfi #sed -i "/um1/ s/${auth_ip}/${mobi_auth_ip}/g" /etc/mobigw.conf#sed -i "s/${auth_port}/${mobi_auth_port}/g" /etc/mobigw.conf#sed -i "s/${auth_listen_port}/${mobi_auth_port}/g" mobiauth/mobiauth.sh # ---- mobiwt ---------------- 脚本分割线 ----------------------- # mobiwt ipwt_ip=$(grep -v "^#" /etc/mobigw.conf | grep "H\:" | grep wt1 | awk -F ":" '{print $4}') # mobiwt portwt_port=$( grep -v "^#" /etc/mobigw.conf | grep "H\:" | grep wt1 | awk -F ":" '{print $5}') wt_listen_port=$(grep "\-s" mobiwt/mobiwt.sh | awk '{print $5}')wt_my_id=$(grep "\-s" mobiwt/mobiwt.sh | awk '{print $3}')wt_server_ip=$(grep "\-s" mobiwt/mobiwt.sh | awk '{print $7}')wt_server_port=$(grep "\-s" mobiwt/mobiwt.sh | awk '{print $9}') while truedo# enter mobilwt ipread -p "please enter wt_ip (example:127.0.0.1):" mobi_wt_ip# enter mobiwt portread -p "please enter wt_port (example:20001):" mobi_wt_port read -p "continue?(y/n)" tip if [ "$tip" = "y" ] || [ "x$tip" = "x" ] then break fidone if [ "x${mobi_wt_ip}" = "x" ] then sed -i "/wt1/ s/${wt_ip}/127.0.0.1/g" /etc/mobigw.conf else sed -i "/wt1/ s/${wt_ip}/${mobi_wt_ip}/g" /etc/mobigw.conffi if [ "x${mobi_wt_port}" = "x" ] then sed -i "s/${wt_port}/20001/g" /etc/mobigw.conf sed -i "s/${wt_my_id}/20001/g" mobiwt/mobiwt.sh sed -i "s/${wt_listen_port}/20001/g" mobiwt/mobiwt.shelse sed -i "s/${wt_port}/${mobi_wt_port}/g" /etc/mobigw.conf sed -i "s/${wt_my_id}/${mobi_wt_port}/g" mobiwt/mobiwt.sh sed -i "s/${wt_listen_port}/${mobi_wt_port}/g" mobiwt/mobiwt.shfi # --- mobiwt--remote--server ------- read -p "please enter remote wt server (example:2.2.2.2):" mobi_wt_server_ip while [ "x${mobi_wt_server_ip}" = "x" ]doread -p "please enter remote wt server (example:2.2.2.2):" mobi_wt_server_ipdonesed -i "s/${wt_server_ip}/${mobi_wt_server_ip}/g" mobiwt/mobiwt.sh read -p "please enter remote wt server port (example:8080):" mobi_wt_server_portwhile [ "x${mobi_wt_server_port}" = "x" ]doread -p "please enter remote wt server port (example:8080):" mobi_wt_server_portdonesed -i "s/${wt_server_port}/${mobi_wt_server_port}/g" mobiwt/mobiwt.sh # ---- mobihq ---------------- 脚本分割线 ----------------------- # mobihq iphq_ip=$(grep -v "^#" /etc/mobigw.conf | grep "H\:" | grep hq1 | awk -F ":" '{print $4}' | sed 's#\.#\\\.#g') # mobihq porthq_port=$( grep -v "^#" /etc/mobigw.conf | grep "H\:" | grep hq1 | awk -F ":" '{print $5}') hq_listen_port=$(grep "\-f" mobihq/mobihq.sh | awk '{print $5}')hq_my_id=$(grep "\-f" mobihq/mobihq.sh | awk '{print $3}') while truedo# enter mobilhq ipread -p "please enter hq_ip (example:127.0.0.1):" mobi_hq_ip # enter mobihq portread -p "please enter hq_port (example:10001):" mobi_hq_port read -p "continue?(y/n)" tip if [ "$tip" = "y" ] || [ "x$tip" = "x" ] then break fidone if [ "x${mobi_hq_ip}" = "x" ]then sed -i "/hq1/ s/${hq_ip}/127.0.0.1/g" /etc/mobigw.confelse sed -i "/hq1/ s/${hq_ip}/${mobi_hq_ip}/g" /etc/mobigw.conffi if [ "x${mobi_hq_port}" = "x" ]then sed -i "s/${hq_port}/10001/g" /etc/mobigw.conf sed -i "s/${hq_my_id}/10001/g" mobihq/mobihq.sh sed -i "s/${hq_listen_port}/10001/g" mobihq/mobihq.shelse sed -i "s/${hq_port}/${mobi_hq_port}/g" /etc/mobigw.conf sed -i "s/${hq_my_id}/${mobi_hq_port}/g" mobihq/mobihq.sh sed -i "s/${hq_listen_port}/${mobi_hq_port}/g" mobihq/mobihq.shfi # ------ config remote hq server ----- hq_server=$(grep "S:1" /etc/mobihq.conf | awk -F ":" '{print $4":"$5":"$6":"$7}')level2_server=$(grep "Level2" /etc/mobihq.conf | awk -F ":" '{print $4":"$5":"$6":"$7}') read -p "please enter remote hq_server and port example (server:port[:server2:port2]):" mobi_hq_server while [ "x${mobi_hq_server}" = "x" ]doread -p "please enter remote hq_server and port example (server:port[:server2:port2]):" mobi_hq_serverdonesed -i "s/${hq_server}/${mobi_hq_server}/g" /etc/mobihq.conf # ------ config level2 server ------- while truedoread -p "do you have level2 server (y/n)? :" yn if [ "$yn" = "y" ] then while true do read -p "please enter level2 server and port example (server:port [:server2:port2]):" mobi_level2_server read -p "are you sure(y/n)?" tip if [ "$tip" = "y" ] then break fi done sed -i "s/${level2_server}/${mobi_level2_server}/g" /etc/mobihq.conf break elif [ "$yn" = "n" ] then break else continue fi done # ---- authserv.txt ---------------- 脚本分割线 ----------------------- # modify authsev.txtwhile truedoread -p "please enter authserv port and ip (example 1.1.1.1:7000):" authservread -p "continue?(y/n)" tip if [ "$tip" = "y" ] then break fidone echo "${authserv}" > mobiauth/config/authserv/authserv.txt # ---- monitor ip or segment ---------------- 脚本分割线 ----------------------- # mobi_monitor_ip , usually router outbound mobi_monitor_ip=$(grep -v "127.0.0.1" /etc/mobigw.conf | grep "^M:" | awk -F ":" '{print $2}') # inter monitor segment while truedo read -p "please enter your monitor ip,example[ip/mask]:" monitor_ip read -p "continue?(y/n)" tip if [ "$tip" = "y" ] then break fidone sed -i "s#${mobi_monitor_ip}#${monitor_ip}#g" /etc/mobigw.conf # ------------------------------- THE END FOR MODULES ------------------- cat <<EOF ################################## ## Config is OK,Please recheck ! ## ################################## EOF sleep 2 echo "configure complete,please check again !!!"echo "please start service use $(pwd)/mobi.sh and check again"echo ""echo ""echo "" #!/bin/bash ################## Warning ################################### ## This script is sitable for Centos 5.x , used by engineers ## ## to build 10jqka mobile server automaticly. # # ## +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ## ## V20110906-2.3 ## # # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++## ## Mobile B2B Department ## ############################################################################# cat << EOF Notification This script has run on RedHat/Centos 5.x , make sure you use the same OS . ** this script mobigw.conf only start 1 listen_port in hq & wt , if you want two ports ,you'd better add by yourself. ** yybinfo.info in this scripts is not config , you must config by your self. ** you must config hosts crontab rc.local by yourselves EOF sleep 6 # root run this script if [ $(id -u) != "0" ] then echo -e "Error!You must be root to run this script! " exit 1 fi echo ""echo ""echo "Environment is preparing,please wait ......"sleep 3 # check php /usr/bin/which php > /dev/null 2>&1 if [ $? = "0" ] then mv $(/usr/bin/which php) $(/usr/bin/which php).bak cp -p etc/php /usr/local/bin else cp -p etc/php /usr/local/bin fi ## config system files # bakcup initial files cp /etc/crontab /etc/crontab.rpmcp /etc/hosts /etc/hosts.rpmcp /etc/rc.d/rc.local /etc/rc.d/rc.local.rpm cp etc/mobigw.conf /etc/cp etc/mobihq.conf /etc/ sed -i "s/H:hq2:2:127.0.0.1:10002/#H:hq2:2:127.0.0.1:10002/g" /etc/mobigw.confsed -i "s/H:wt2:3:127.0.0.1:20002/#H:wt2:3:127.0.0.1:20002/g" /etc/mobigw.conf echo "Backuping necessary files !!! hosts,crontab,rc.local,checking whether have php "echo ""echo "Backup files are *.rpm"sleep 3echo ""echo "Check environment is OK !!! please configurate hosts crontab rc.local by yourself"echo ""sleep 3 echo "Begin config mobigw mobiauth mobihq mobiwt modules !!"echo ""echo ""sleep 3 # ---- mobigw ---------------- 脚本分割线 ----------------------- ## modify modigw.sh ; make sure http_port & tcp_port # mobigw http porthttp_port=$(grep "\-h " mobigw/mobigw.sh | awk '{print $3}') # mobigw tcp porttcp_port=$(grep "\-h " mobigw/mobigw.sh | awk '{print $5}') while truedo# input mobigw http portread -p "please enter your mobigw_http_port (initial is 80):" gw_http_port# input mobigw tcp portread -p "please enter your mobigw_tcp_port (initial is 9528):" gw_tcp_port read -p "continue?(y/n)" tipif [ "$tip" = "y" ] || [ "x$tip" = "x" ]then breakfidone if [ "x${gw_http_port}" = "x" ] then sed -i "s/${http_port}/80/g" mobigw/mobigw.shelse sed -i "s/${http_port}/${gw_http_port}/g" mobigw/mobigw.shfi if [ "x${gw_http_port}" = "x" ] then sed -i "s/${tcp_port}/9528/g" mobigw/mobigw.shelse sed -i "s/${tcp_port}/${gw_tcp_port}/g" mobigw/mobigw.shfi # ---- mobiauth ---------------- 脚本分割线 ----------------------- #mobiauth ip#auth_ip=$( grep -v "^#" /etc/mobigw.conf | grep "H\:" | grep um1 | awk -F ":" '{print $4}')auth_ip=$(grep -v "^#" /etc/mobigw.conf | grep "H\:" | grep um1 | awk -F ":" '{print $4}' | sed 's#\.#\\\.#g') # mobiauth portauth_port=$(grep -v "^#" /etc/mobigw.conf | grep "H\:" | grep um1 | awk -F ":" '{print $5}') # modify mobiauth.shauth_listen_port=$(grep "\-n" mobiauth/mobiauth.sh | awk '{print $4}') while true do# enter mobiauth ipread -p "please enter mobiauth_ip (example:127.0.0.1):" mobi_auth_ip # enter mobiauth portread -p "please enter mobiauth_port (example:9529):" mobi_auth_port read -p "continue?(y/n)" tip if [ "$tip" = "y" ] || [ "x$tip" = "x" ] then break fidone if [ "x${mobi_auth_ip}" = "x" ] then sed -i "/um1/ s#${auth_ip}#127.0.0.1#g" /etc/mobigw.conf else sed -i "/um1/ s#${auth_ip}#${mobi_auth_ip}#g" /etc/mobigw.conffi if [ "x${mobi_auth_port}" = "x" ] then sed -i "s/${auth_port}/9529/g" /etc/mobigw.conf sed -i "s/${auth_listen_port}/9529/g" mobiauth/mobiauth.sh else sed -i "s/${auth_port}/${mobi_auth_port}/g" /etc/mobigw.conf sed -i "s/${auth_listen_port}/${mobi_auth_port}/g" mobiauth/mobiauth.shfi #sed -i "/um1/ s/${auth_ip}/${mobi_auth_ip}/g" /etc/mobigw.conf#sed -i "s/${auth_port}/${mobi_auth_port}/g" /etc/mobigw.conf#sed -i "s/${auth_listen_port}/${mobi_auth_port}/g" mobiauth/mobiauth.sh # ---- mobiwt ---------------- 脚本分割线 ----------------------- # mobiwt ipwt_ip=$(grep -v "^#" /etc/mobigw.conf | grep "H\:" | grep wt1 | awk -F ":" '{print $4}') # mobiwt portwt_port=$( grep -v "^#" /etc/mobigw.conf | grep "H\:" | grep wt1 | awk -F ":" '{print $5}') wt_listen_port=$(grep "\-s" mobiwt/mobiwt.sh | awk '{print $5}')wt_my_id=$(grep "\-s" mobiwt/mobiwt.sh | awk '{print $3}')wt_server_ip=$(grep "\-s" mobiwt/mobiwt.sh | awk '{print $7}')wt_server_port=$(grep "\-s" mobiwt/mobiwt.sh | awk '{print $9}') while truedo# enter mobilwt ipread -p "please enter wt_ip (example:127.0.0.1):" mobi_wt_ip# enter mobiwt portread -p "please enter wt_port (example:20001):" mobi_wt_port read -p "continue?(y/n)" tip if [ "$tip" = "y" ] || [ "x$tip" = "x" ] then break fidone if [ "x${mobi_wt_ip}" = "x" ] then sed -i "/wt1/ s/${wt_ip}/127.0.0.1/g" /etc/mobigw.conf else sed -i "/wt1/ s/${wt_ip}/${mobi_wt_ip}/g" /etc/mobigw.conffi if [ "x${mobi_wt_port}" = "x" ] then sed -i "s/${wt_port}/20001/g" /etc/mobigw.conf sed -i "s/${wt_my_id}/20001/g" mobiwt/mobiwt.sh sed -i "s/${wt_listen_port}/20001/g" mobiwt/mobiwt.shelse sed -i "s/${wt_port}/${mobi_wt_port}/g" /etc/mobigw.conf sed -i "s/${wt_my_id}/${mobi_wt_port}/g" mobiwt/mobiwt.sh sed -i "s/${wt_listen_port}/${mobi_wt_port}/g" mobiwt/mobiwt.shfi # --- mobiwt--remote--server ------- read -p "please enter remote wt server (example:2.2.2.2):" mobi_wt_server_ip while [ "x${mobi_wt_server_ip}" = "x" ]doread -p "please enter remote wt server (example:2.2.2.2):" mobi_wt_server_ipdonesed -i "s/${wt_server_ip}/${mobi_wt_server_ip}/g" mobiwt/mobiwt.sh read -p "please enter remote wt server port (example:8080):" mobi_wt_server_portwhile [ "x${mobi_wt_server_port}" = "x" ]doread -p "please enter remote wt server port (example:8080):" mobi_wt_server_portdonesed -i "s/${wt_server_port}/${mobi_wt_server_port}/g" mobiwt/mobiwt.sh # ---- mobihq ---------------- 脚本分割线 ----------------------- # mobihq iphq_ip=$(grep -v "^#" /etc/mobigw.conf | grep "H\:" | grep hq1 | awk -F ":" '{print $4}' | sed 's#\.#\\\.#g') # mobihq porthq_port=$( grep -v "^#" /etc/mobigw.conf | grep "H\:" | grep hq1 | awk -F ":" '{print $5}') hq_listen_port=$(grep "\-f" mobihq/mobihq.sh | awk '{print $5}')hq_my_id=$(grep "\-f" mobihq/mobihq.sh | awk '{print $3}') while truedo# enter mobilhq ipread -p "please enter hq_ip (example:127.0.0.1):" mobi_hq_ip # enter mobihq portread -p "please enter hq_port (example:10001):" mobi_hq_port read -p "continue?(y/n)" tip if [ "$tip" = "y" ] || [ "x$tip" = "x" ] then break fidone if [ "x${mobi_hq_ip}" = "x" ]then sed -i "/hq1/ s/${hq_ip}/127.0.0.1/g" /etc/mobigw.confelse sed -i "/hq1/ s/${hq_ip}/${mobi_hq_ip}/g" /etc/mobigw.conffi if [ "x${mobi_hq_port}" = "x" ]then sed -i "s/${hq_port}/10001/g" /etc/mobigw.conf sed -i "s/${hq_my_id}/10001/g" mobihq/mobihq.sh sed -i "s/${hq_listen_port}/10001/g" mobihq/mobihq.shelse sed -i "s/${hq_port}/${mobi_hq_port}/g" /etc/mobigw.conf sed -i "s/${hq_my_id}/${mobi_hq_port}/g" mobihq/mobihq.sh sed -i "s/${hq_listen_port}/${mobi_hq_port}/g" mobihq/mobihq.shfi # ------ config remote hq server ----- hq_server=$(grep "S:1" /etc/mobihq.conf | awk -F ":" '{print $4":"$5":"$6":"$7}')level2_server=$(grep "Level2" /etc/mobihq.conf | awk -F ":" '{print $4":"$5":"$6":"$7}') read -p "please enter remote hq_server and port example (server:port[:server2:port2]):" mobi_hq_server while [ "x${mobi_hq_server}" = "x" ]doread -p "please enter remote hq_server and port example (server:port[:server2:port2]):" mobi_hq_serverdonesed -i "s/${hq_server}/${mobi_hq_server}/g" /etc/mobihq.conf # ------ config level2 server ------- while truedoread -p "do you have level2 server (y/n)? :" yn if [ "$yn" = "y" ] then while true do read -p "please enter level2 server and port example (server:port [:server2:port2]):" mobi_level2_server read -p "are you sure(y/n)?" tip if [ "$tip" = "y" ] then break fi done sed -i "s/${level2_server}/${mobi_level2_server}/g" /etc/mobihq.conf break elif [ "$yn" = "n" ] then break else continue fi done # ---- authserv.txt ---------------- 脚本分割线 ----------------------- # modify authsev.txtwhile truedoread -p "please enter authserv port and ip (example 1.1.1.1:7000):" authservread -p "continue?(y/n)" tip if [ "$tip" = "y" ] then break fidone echo "${authserv}" > mobiauth/config/authserv/authserv.txt # ---- monitor ip or segment ---------------- 脚本分割线 ----------------------- # mobi_monitor_ip , usually router outbound mobi_monitor_ip=$(grep -v "127.0.0.1" /etc/mobigw.conf | grep "^M:" | awk -F ":" '{print $2}') # inter monitor segment while truedo read -p "please enter your monitor ip,example[ip/mask]:" monitor_ip read -p "continue?(y/n)" tip if [ "$tip" = "y" ] then break fidone sed -i "s#${mobi_monitor_ip}#${monitor_ip}#g" /etc/mobigw.conf # ------------------------------- THE END FOR MODULES ------------------- cat <<EOF ################################## ## Config is OK,Please recheck ! ## ################################## EOF sleep 2 echo "configure complete,please check again !!!"echo "please start service use $(pwd)/mobi.sh and check again"echo ""echo ""echo "" |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|