Chinaunix首页 | 论坛 | 博客
  • 博客访问: 803244
  • 博文数量: 274
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 862
  • 用 户 组: 普通用户
  • 注册时间: 2015-10-24 15:31
个人简介

不合格的程序猿

文章分类

全部博文(274)

文章存档

2019年(3)

2018年(1)

2017年(4)

2016年(160)

2015年(106)

我的朋友

分类: 系统运维

2016-03-07 20:41:19

集环境搭建、环境重新搭建、分类代码编译、查看debug信息等功能于一体。


点击(此处)折叠或打开

  1. #! /bin/bash

  2. SVN_USER_NAME="XXXXXX"
  3. SVN_USER_PASSWORD="123"

  4. DEBUG_FLAG="/data/vpn4a_debug_flag"
  5. DEBUG_FILE="/tmp/vpn4a_debug_file"
  6. TOS_CONFIG_LOG="/data/tos_configd.log"

  7. NGTOS_VERSION="v2.0.42"
  8. WORKSPACE_DIR="/home/ngos/workspace"
  9. SHARED_DIR="/mnt/hgfs/shared"

  10. # get version for sv make from include/Makefile.sv
  11. MAKEFILE_SV="./include/Makefile.sv"
  12. echo -e "\$PWD = $PWD"
  13. if [ -f $MAKEFILE_SV ]; then
  14.     echo -e "$MAKEFILE_SV is exist"
  15.     NGTOS_VERSION=`grep "NGTOS_SV_VERSION=" $MAKEFILE_SV`
  16.     NGTOS_VERSION=`echo -e "${NGTOS_VERSION#*=}"`
  17. fi

  18. echo -e "NGTOS_VERSION = $NGTOS_VERSION"

  19. RUN_ENV_FILE="$NGTOS_VERSION-binary.tar.bz2"
  20. COMPILE_ENV_FILE="$NGTOS_VERSION-compile-env.tar.bz2"

  21. RUN_ENV_DEST="$SHARED_DIR/$NGTOS_VERSION/$RUN_ENV_FILE"
  22. COMPILE_ENV_DEST="$SHARED_DIR/$NGTOS_VERSION/$COMPILE_ENV_FILE"

  23. SE_DIR="$WORKSPACE_DIR/$NGTOS_VERSION/SE"
  24. SV_REPO_DIR="$SE_DIR/sv-repo"
  25. SV_LIB_DIR="$SE_DIR/sv-lib"
  26. SV_DIR="$SE_DIR/sv"
  27. AAAA_DIR="$SV_DIR/4a"
  28. MP_DIR="$SV_DIR/mp"
  29. RAMDISK_DIR="$SV_DIR/release/ramdisk"

  30. SO_DIR="$RAMDISK_DIR/lib"
  31. PERL_ENV_SRC_DIR="$SV_REPO_DIR/app"
  32. APACHE_DIR="$SV_REPO_DIR/app/apache/httpd-2.2.31"
  33. SAMBA_DIR="$SV_REPO_DIR/lib/samba"

  34. OPENLDAP_SRC_FILE="openldap.tgz"
  35. OPENLDAP_SHELL_FILE="openldap_start"
  36. OPENLDAP_SRC_DEST="$SV_REPO_DIR/app/$OPENLDAP_SRC_FILE"
  37. OPENLDAP_SHELL_DEST="$RAMDISK_DIR/bin/$OPENLDAP_SHELL_FILE"

  38. SVN_SV=""
  39. SVN_SV_LIB="-lib"
  40. SVN_SV_REPO="-repo"

  41. TOS_CFG_FILE="/tos/etc/cfg_rule/tos.cfg"

  42. NULL="/dev/null"
  43. NGTOS_LOG=$NULL
  44. ERROR_SUCCESS=0
  45. ERROR_CONTINUE=1

  46. SEARCH_STR="[XXXXXX]"
  47. OPERATION_DEST="4A"

  48. function PUSHD()
  49. {
  50.     echo $PWD
  51.     pushd $1 >> $NGTOS_LOG
  52.     
  53.     return 0
  54. }

  55. function POPD()
  56. {
  57.     popd >> $NGTOS_LOG

  58.     return 0
  59. }

  60. function SLEEP()
  61. {
  62.     sleep 1

  63.     return 0
  64. }

  65. function modify_tos_cfg()
  66. {
  67.     if [ $# -ge 2 ]; then
  68.         return 1
  69.     
  70.     fi

  71.     grep $1 $TOS_CFG_FILE > $NULL
  72.     if [ $? -eq 0 ]; then
  73.         return 0
  74.     fi

  75.     case $1 in
  76.         "aaaa")
  77.             flag=0
  78.             ;;
  79.         "sslvpn")
  80.             flag=0
  81.             ;;
  82.         *)
  83.             flag=1
  84.             echo "argv $1 is invalid. please input the agrv as \"aaaa\" or \"sslvpn\""
  85.             exit 1
  86.             ;;
  87.     esac

  88.     if [ $flag -eq 0 ]; then
  89.     echo -e "\ncmd_begin\n_obj_type_keyword = $1\n_file = $1.cfg\n_obj_meaning_c = $1\n_obj_meaning_e = $1 configure\ncmd_end" >> $TOS_CFG_FILE
  90.     fi

  91.     return $flag
  92. }

  93. function ln_ngtos_so()
  94. {
  95. #    ln -fs $SO_DIR/libvpn4a*.so /tos/so/
  96. #    ln -fs $SO_DIR/libpki.so /tos/so/
  97. #    ln -fs $SO_DIR/libdhcpc.so /tos/so/
  98. #    ln -fs $SO_DIR/libsv_graph.so /tos/so/

  99.     cp $SO_DIR/libapreq2.so $SO_DIR/libapreq2.so.3
  100.     ln -fs $SO_DIR/*.so* /tos/so >> $TOS_CONFIG_LOG

  101.     ln –fs /tftpboot/mod*.so /www/modules/
  102.     ldconfig
  103.     
  104.     return 0
  105. }

  106. function install_samba()
  107. {
  108.     PUSHD $SAMBA_DIR
  109.         tar -xzvf "samba-latest.tar.gz" >> $NGTOS_LOG
  110.         PUSHD "samba-4.2.3"
  111.             ./configure --without-ldap --without-ads
  112.             echo -e "make"
  113.             SLEEP
  114.             make > $NULL
  115.             if [ $? -ne 0 ]; then
  116.                 exit 1
  117.             fi
  118.             echo -e "make result: \$? = $?"
  119.             SLEEP
  120.             echo -e "make install"
  121.             make install > $NULL
  122.             if [ $? -ne 0 ]; then
  123.                 exit 1
  124.             fi
  125.             echo -e "make install result: \$? = $?"
  126.         POPD
  127.         rm -rf "samba-4.2.3"
  128.     POPD
  129.     
  130.     return 0
  131. }

  132. function init_ngtos_evn()
  133. {
  134.     if [ ! -d "/tftpboot" ]; then
  135.         mkdir -p /tftpboot
  136.     fi

  137.     if [ ! -d "/data/auth" ]; then
  138.         mkdir -p /data/auth
  139.     fi

  140.     if [ ! -d "/tmp/sv" ]; then
  141.         mkdir -p /tmp/sv
  142.     else
  143.         rm /tmp/sv/* -rf >> $NULL
  144.     fi
  145.     rm /tmp/cfg_init_flag_file 2> $NULL
  146.     
  147.     #install_samba

  148.     return 0
  149. }

  150. function install_perl_5_12_0()
  151. {
  152.     PUSHD $PERL_ENV_SRC_DIR
  153.         tar -xzvf "perl-env-src.tgz" >> $NGTOS_LOG
  154.         PUSHD "perl-env-src"
  155.             tar -xzvf "perl-5.12.0.tar.gz" >>$NGTOS_LOG
  156.             PUSHD "perl-5.12.0"
  157.                 CFLAGS='-m64 -mtune=nocona' ./Configure -des -A ccflags=-fPIC -Dusethreads -Dprefix=/tos_perl
  158.                 echo -e "make"
  159.                 SLEEP
  160.                 make > $NULL
  161.                 if [ $? -ne 0 ]; then
  162.                     exit 1
  163.                 fi
  164.                 echo -e "make result: \$? = $?"
  165.                 SLEEP
  166.                 echo -e "make install"
  167.                 make install > $NULL
  168.                 if [ $? -ne 0 ]; then
  169.                     exit 1
  170.                 fi
  171.                 echo -e "make install result: \$? = $?"
  172.             POPD
  173.         POPD
  174.         rm -rf perl-env-src >>$NGTOS_LOG
  175.     POPD

  176.     return 0
  177. }

  178. function compile_code_sv()
  179. {    
  180.     PUSHD $MP_DIR
  181.         echo -e "$PWD : make clean"
  182.         make clean 1>$NULL
  183.         SLEEP
  184.         echo -e "$PWD : make"
  185.         make 1> $NULL
  186.         if [ $? -ne 0 ]; then
  187.             exit 1
  188.         fi
  189.         SLEEP
  190.         echo -e "$PWD : make install"
  191.         make install 1> $NULL
  192.         SLEEP
  193.     POPD
  194.     
  195.     return 0
  196. }

  197. function compile_code_4a()
  198. {    
  199.     PUSHD $AAAA_DIR
  200.         echo -e "$PWD : make clean"
  201.         make clean 1>$NULL
  202.         SLEEP
  203.         echo -e "$PWD : make"
  204.         make 1> $NULL
  205.         if [ $? -ne 0 ]; then
  206.             exit 1
  207.         fi
  208.         SLEEP
  209.         echo -e "$PWD : make install"
  210.         make install 1> $NULL
  211.         SLEEP
  212.     POPD

  213.     return 0
  214. }

  215. function compile_code_apache()
  216. {
  217.     PUSHD $APACHE_DIR
  218.         export CFLAGS+="-DBIG_SECURITY_HOLE"
  219.         chmod -R u+x *
  220.         sh run.sh
  221.         SLEEP
  222.         make
  223.         SLEEP
  224.         make install
  225.         SLEEP
  226.         chmod 755 /www/bin/imagecode
  227.     POPD

  228.     return 0
  229. }

  230. function build_code_env()
  231. {
  232.     PUSHD $SE_DIR
  233.     svn --username=$SVN_USER_NAME --password=$SVN_USER_PASSWORD co $SVN_SV >> $NGTOS_LOG
  234.     if [ $? -ne 0 ]; then
  235.         exit 1
  236.     fi

  237.     svn --username=$SVN_USER_NAME --password=$SVN_USER_PASSWORD co $SVN_SV_LIB >> $NGTOS_LOG
  238.     if [ $? -ne 0 ]; then
  239.         exit 1
  240.     fi

  241.     svn --username=$SVN_USER_NAME --password=$SVN_USER_PASSWORD co $SVN_SV_REPO >> $NGTOS_LOG
  242.     if [ $? -ne 0 ]; then
  243.         exit 1
  244.     fi
  245.     POPD
  246.     
  247.     install_perl_5_12_0
  248.     SLEEP

  249.     compile_code_4a
  250.     SLEEP
  251.     compile_code_sv

  252.     return 0
  253. }

  254. function install_openldap()
  255. {
  256.     if [ ! -f $OPENLDAP_SRC_DEST ] || [ ! -f $OPENLDAP_SHELL_DEST ]; then
  257.         exit 1
  258.     fi

  259.     if [ ! -f "/tos/etc/$OPENLDAP_SRC_FILE" ]; then
  260.         cp $OPENLDAP_SRC_DEST /tos/etc/
  261.     fi

  262.     sh $OPENLDAP_SHELL_DEST "install"
  263.     if [ $? -ne 0 ]; then
  264.         exit 1
  265.     fi
  266.     rm /tos/etc/$OPENLDAP_SRC_FILE -f 2> $NULL

  267.     return 0
  268. }

  269. function install_ngtos_project()
  270. {
  271.     if [ -d "$WORKSPACE_DIR/$NGTOS_VERSION" ]; then
  272.         echo -e "the directory: $WORKSPACE_DIR/$NGTOS_VERSION has existed"
  273.         exit 0
  274.     fi
  275.     
  276.     #zero
  277.     echo -e "\n=================== init the ngtos environment ========================\n"
  278.     init_ngtos_evn    

  279.     #first
  280.     echo -e "\n=================== build the running environment =====================\n"
  281.     cp -rf $RUN_ENV_DEST / > $NULL
  282.     PUSHD /
  283.     tar -xjvf $RUN_ENV_FILE >> $NGTOS_LOG
  284.     rm -rf $RUN_ENV_FILE > $NULL
  285.     POPD
  286.     SLEEP

  287.     #second
  288.     echo -e "\n=================== build the compile environment =====================\n"
  289.     cp -rf $COMPILE_ENV_DEST $WORKSPACE_DIR/
  290.     PUSHD $WORKSPACE_DIR/
  291.     tar -xjvf $COMPILE_ENV_FILE >> $NGTOS_LOG
  292.     rm -rf $COMPILE_ENV_FILE > $NULL
  293.     POPD
  294.     SLEEP

  295.     #third
  296.     echo -e "\n=================== checkout the source code ==========================\n"
  297.     build_code_env
  298.     SLEEP

  299.     #fourth
  300.     echo -e "\n=================== modify the tos.cfg file ===========================\n"
  301.     modify_tos_cfg "aaaa"
  302.     modify_tos_cfg "sslvpn"
  303.     
  304.     #fifth
  305.     echo -e "\n=================== copy the cmd cfg file ==============================\n"
  306.     cp $RAMDIS_DIR/etc/cfg_rule/*.cfg /tos/etc/cfg_rule/

  307.     #sixth
  308.     echo -e "\n=================== create the soft link for ngtos so =================\n"
  309.     ln_ngtos_so
  310.     SLEEP
  311.     echo -e "\n=================== complie the code of the apache =================\n"
  312.     compile_code_apache

  313.     #seventh
  314.     echo -e "\n=================== build the openldap environment ====================\n"
  315.     install_openldap
  316.     SLEEP

  317.     #eighth
  318.     echo -e "\n=================== prepare for debug message =========================\n"
  319.     >$DEBUG_FILE > $NULL
  320.     touch $DEBUG_FLAG
  321.     #ninth
  322.     echo -e "\n=================== modify config file for ngvone =========================\n"
  323.     sh $RAMDISK_DIR/bin/modify_ngtos_for_ngvone
  324.     sh $RAMDISK_DIR/bin/modify_toscfg_for_ngvone
  325.     sh $RAMDISK_DIR/bin/modify_configd_for_ngvone

  326.     return 0
  327. }

  328. function uninstall_ngtos_project()
  329. {
  330. #    if [ -d "~/work" ]; then
  331. #        mkdir ~/work
  332. #    fi
  333. #    cd ~/work

  334.     echo -e "sh \$OPENLDAP_SHELL_DEST \"uninstall\""
  335.     if [ -f $OPENLDAP_SHELL_DEST ]; then
  336.         sh $OPENLDAP_SHELL_DEST "uninstall"
  337.     fi


  338.     echo -e "delete $WORKSPACE_DIR/$NGTOS_VERSION"
  339.     rm -rf $WORKSPACE_DIR/$NGTOS_VERSION > $NULL

  340.     echo -e "rm -rf $DEBUG_FLAG "
  341.     rm -rf $DEBUG_FLAG > $NULL

  342.     echo -e rm -rf $DEBUG_FILE ""
  343.     rm -rf $DEBUG_FILE > $NULL

  344.     echo -e "rm -rf $TOS_CONFIG_LOG"
  345.     rm -rf $TOS_CONFIG_LOG > $NULL

  346.     echo -e "rm -rf $OPENLDAP_SRC_FILE"
  347.     rm -rf /et/
  348.     
  349.     rm -rf /tmp/cfg_init_flag_file > $NULL
  350.     rm -rf /tmp/sv/* > $NULL
  351.     rm -rf /tftpboot/* 2> $NULL
  352.     rm -rf /se_mnt/*.ldif 2> $NULL
  353.     rm -rf /data/auth/* 2>$NULL
  354.     rm -rf /tmp/vpn4a_flag 2>$NULL
  355.     rm -rf /data/ngtos_calltrace.dbg* 2>$NULL
  356.     rm -rf /SE/core-* 2>$NULL

  357.     return 0
  358. }

  359. function help()
  360. {
  361.     echo -e "\t\t$1 [OPERATION DEST] OPERATIONS"
  362.     echo -e "OPERATION DEST:"
  363.     echo -e "\t4a | aaaa | 4A | AAAA\t---->\tthe code to be compiled is in $AAAA_DIR"
  364.     echo -e "\tsv | SV\t\t\t---->\tthe code to be compiled is in $MP_DIR"
  365.     echo -e "\tapache\t\t\t---->\tthe code to be compiled is in $APACHE_DIR"
  366.     echo -e "\tperl\t\t\t---->\tthe code to be compiled is in $PERL_ENV_SRC_DIR"
  367.     echo -e "\tsamba\t\t\t---->\tthe code to be compiled is in $SAMBA_DIR"
  368.     echo -e "OPERATIONS:"
  369.     echo -e "\tOperations about compile:"
  370.     echo -e "\tall\t\t---->\tmake clean; make; make install"
  371.     echo -e "\tclean\t\t---->\tmake clean"
  372.     echo -e "\tmake\t\t---->\tmake"
  373.     echo -e "\tinstall\t\t---->\tmake install\n"

  374.     echo -e "\tOperations about debug message:"
  375.     echo -e "\tshow\t\t---->\tcat ${DEBUG_FILE}"
  376.     echo -e "\tshow \"xxx\"\t---->\tcat ${DEBUG_FILE} | grep \"xxx\""
  377.     echo -e "\tclear\t\t---->\tdelete the debug file ${DEBUG_FILE}\n"

  378.     echo -e "\tOperations about ngtos environment:"
  379.     echo -e "\trestart\t\t---->\tngtos restart"
  380.     echo -e "\tldap\t\t---->\tstart ldap service"
  381.     echo -e "\tinit\t\t---->\tinit ngtos enevironment, such as shm and server_map\n"

  382.     echo -e "\tOperations about ngtos project:"
  383.     echo -e "\tbuild\t\t---->\tbuild the ngtos project"
  384.     echo -e "\trebuild\t\t---->\trebuild the ngtos project"

  385.     echo -e "EXAMPLES:"
  386.     echo -e "\tTo compile the code of 4a:"
  387.     echo -e "\t\t$1 aaaa all"
  388.     echo -e "\t\t$1 all\t\t\n"

  389.     echo -e "\tTo build a ngtos environment to compile in a dirty environment:"
  390.     echo -e "\t\t$1 rebuild\n"

  391.     echo -e "\tTo build a ngtos environment to compile in a neat environment:"
  392.     echo -e "\t\t$1 build\n"

  393.     return $ERROR_SUCCESS
  394. }

  395. function ngtos_operation()
  396. {
  397.     case $1 in
  398.         "all")
  399.             make clean
  400.             make
  401.             make install
  402.             ;;
  403.         "clean")
  404.             make clean
  405.             ;;
  406.         "install")
  407.             make install
  408.             ;;
  409.         "make")
  410.             make
  411.             ;;
  412.         "restart")
  413.             ngtos restart
  414.             ;;
  415.         "show")
  416. #     if [ $# -eq 2 ]; then
  417. #             cat $DEBUG_FILE | grep -F "${SEARCH_STR}" --color=auto
  418. #     else
  419. #             cat $DEBUG_FILE
  420. #     fi
  421.             cat $TOS_CONFIG_LOG
  422.             ;;
  423.         "clear")
  424.             > $DEBUG_FILE
  425.          > $TOS_CONFIG_LOG
  426.             ;;
  427.         "ldap")
  428.             PUSHD /tmp/ldap_tos/openldap/libexec
  429.             ./slapd
  430.             netstat -ntpl | grep 389 --color=auto
  431.             POPD
  432.             ;;
  433.         "init")
  434.             PUSHD init
  435.             ./vpn4a_shm_init
  436.             POPD
  437.             ;;
  438.         "build")
  439.             echo -e "one key to produce the project"
  440.             install_ngtos_project
  441.             ;;
  442.         "rebuild")
  443.             echo -e "one key to remove the project"
  444.             uninstall_ngtos_project
  445.             install_ngtos_project
  446.             ;;
  447.         *)
  448.             echo -e "the argv you input [ \$1 = $1 ] is unexpected!"
  449.             echo -e "please run it like $0 -e"
  450.             ;;
  451.     esac

  452.     return 0
  453. }

  454. function ngtos_process()
  455. {

  456.     echo -e "START:"
  457.     if [ -d $1 ]; then
  458.         PUSHD $1
  459.         if [ $1 = $APACHE_DIR ];then
  460.             make clean
  461.             compile_code_apache
  462.             exit 0
  463.         elif [ $1 = $PERL_ENV_SRC_DIR ]; then
  464.             install_perl_5_12_0
  465.             exit 0
  466.         elif [ $1 = $SAMBA_DIR ]; then
  467.             install_samba
  468.             exit 0
  469.         fi
  470.         ngtos_operation $2
  471.         POPD
  472.     else
  473.         ngtos_operation $2
  474.     fi
  475.     echo -e "END"

  476.     return 0
  477. }

  478. function ngtos_build()
  479. {
  480.     case $2 in
  481.         "show")
  482.             SEARCH_STR=$3
  483.             ;;
  484.         "4a" | "4A" | "aaaa" | "AAAA")
  485.             OPERATION_DEST=$AAAA_DIR
  486.             ;;
  487.         "SV" | "sv")
  488.             OPERATION_DEST=$MP_DIR
  489.             ;;
  490.         "apache")
  491.             OPERATION_DEST=$APACHE_DIR
  492.             ;;
  493.         "perl")
  494.             OPERATION_DEST=$PERL_ENV_SRC_DIR
  495.             ;;
  496.         "samba")
  497.             OPERATION_DEST=$SAMBA_DIR
  498.             ;;
  499.         *)
  500.             echo -e "Operation failed ! Please do it like: $1 -e"
  501.             exit 1
  502.             ;;
  503.     esac

  504.     ngtos_process $OPERATION_DEST $3

  505.     return $?
  506. }


  507. if [ $# -eq 0 ] || [ $# -ge 3 ]; then
  508.     echo -e "Operation failed ! Please do it like: $1 -e"
  509.     exit 0;
  510. elif [ $# -eq 2 ]; then
  511.     ngtos_build $0 $1 $2
  512. elif [ $# -eq 1 ] && [ $1 = "-e" ]; then
  513.     help $0 $1
  514. else
  515.     ngtos_build $0 $OPERATION_DEST $1
  516. fi

阅读(1140) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~