install 4

来源:互联网 发布:迈达斯待遇知乎 编辑:程序博客网 时间:2024/06/05 10:36

#####################################################################
#
#   FUNCTION :Check if quit
#   PARAMETER:1:string
# RETURN : 1: quit 0: continue
#####################################################################
function chkQuit()
{
    if [ "$1" = "q" -o "$1" = "Q" ]; then
        first=0;
        cConfirm="";
        while [ "$cConfirm" != "y" -a "$cConfirm" != "Y" ]  \
            && [ "$cConfirm" != "n" -a "$cConfirm" != "N" ]; do
            if [ $first -ne 0 ]; then
                echo "Wrong parameter,please try again."
                echo "Explanation:"
                echo "    The valid parameters are y,n. "
                echo "    The command cannot be processed."
                echo "User Response:"
                echo "    Re-enter the Choice and try it again or contact to Support Engineers"
                echo "    to get a support."
            fi;
            first=` expr $first + 1 `;
            warn
            echo -n "Are you sure to quit current installation[y,n]?"
            read cConfirm;

            if [ "$cConfirm" = "y" -o "$cConfirm" = "Y" ]; then
                echo ""
                echo "Breaking current installation successfully"
                stty echo
                return 1
            fi;
        done;
    fi;

    return 0
}

######################################################################
#
#   FUNCTION :Exit shell with error number 1
#   PARAMETER:error information string
#   OUT      :
######################################################################
die()
{
    echo "$@" >&2
    gLINENUM=${LINENO}
    echo " "
    echo "Failed to install RSAU !"
    echo " "
    gLINENUM=0;
    stty echo
    exit 1
}

######################################################################
#
#   FUNCTION :Warn
#   PARAMETER::Warning information string
#   OUT      :
######################################################################
warn()
{
    printf "\n\033[40;33mWARNING\033[0m\n"
    [ $# -gt 0 ] && printf " $@\n"
}

welcome()
{
        printf "It will install RSAU on your server, Please choose the application you want to install.\n\r"
        echo 'Installation list:'
        printf "RSAU install ......................................... \033[1m[1]\033[0m\n"
        printf "Exit the install ..................................... \033[1m[2]\033[0m\n"
        while [ 1 ]
        do
            printf "Please input your choice[1~2]:"
   read choice
            case $choice in
            1  )
                printf "  \n\r"
                printf "  \n\r"
                printf "  \n\r"
                break          
                ;;                  
            2  )
                exit
                ;;
            *  )
                echo "Invalid input !"
                continue
                ;;
            esac
        done
}


######################################################################
#
#   FUNCTION :chkNode
#   PARAMETER:nothing
#   INPUT    :0-9 number
#   OUT      :nothing
######################################################################
function chkNode()
{
    if [ $1 -lt 0 -o $1 -gt 255 ]; then
        echo "Invalid IP Address."
        targetbz=no
        return 1
    fi
    return 0
}
######################################################################
#
#   FUNCTION :chkIP
#   PARAMETER:nothing
#   INPUT    :ip address
#   OUT      :nothing
######################################################################
function chkIP()
{
    tmp=`echo $1 | grep -w "^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$"`
    if [ -z "$tmp" ]; then
        echo "Invalid IP Address"
        targetbz=no
        return 1
    else
        if ! chkNode `echo $1 | awk -F. '{print $1}'`; then
            return 1
        elif ! chkNode `echo $1 | awk -F. '{print $2}'`; then
            return 1
        elif ! chkNode `echo $1 | awk -F. '{print $3}'`; then
            return 1
        elif ! chkNode `echo $1 | awk -F. '{print $4}'`; then
            return 1
        fi
        targetbz=ok
    fi
    return 0
}
######################################################################
#   FUNCTION :excute_ip_opration
#   PARAMETER:nothing
#   INPUT    :ip address
#   OUT      :nothing
######################################################################
function qexcute_ip_opration()
{
  mv  $PACKAGE_PATH/cfg/sysconfig.xml   $PACKAGE_PATH/ >>/tmp/error  2>&1
  #删除影响判断的文件
  rm -rf $PACKAGE_PATH/cfg/sysconfig.log
  rm -rf $PACKAGE_PATH/cfg/sysconfig.xml
 
  printf "please input database ip address:\n\r"
  read ip
  chkIP $ip

  if [ "ok" == $targetbz ]
  then
    variableJH=nono
    #增加QWERTYUIOPLKqwertyuio xml修改标志,以便替换
    cat $PACKAGE_PATH/sysconfig.xml|awk '{if(/DBSid/){sub(/>[^<]*</,">QWERTYUIOPLKqwertyuio<")}print}' >>$PACKAGE_PATH/cfg/sysconfig.log  2>&1
    sleep 1s
    #将输入ip写入配置文件
    cat $PACKAGE_PATH/cfg/sysconfig.log|sed "s/QWERTYUIOPLKqwertyuio/$ip:1521\/chrdb/g"  >>$PACKAGE_PATH/cfg/sysconfig.xml  2>&1
    #配置文件赋予最大权限
    chmod 777 $PACKAGE_PATH/cfg/sysconfig.xml >>/tmp/error  2>&1
    sleep 1s
   
    rm -rf $PACKAGE_PATH/sysconfig.xml
    variableJH=yesyes
    else
    mv  $PACKAGE_PATH/sysconfig.xml   $PACKAGE_PATH/cfg/ >>/tmp/error  2>&1
  fi
}

######################################################################
#   FUNCTION :DIAOyong(输入IP)
#   PARAMETER:nothing
#   INPUT    :nothing
#   OUT      :nothing
######################################################################
function DIAOyong()
{
while [ 1 ]
do
  sleep 1s
  qexcute_ip_opration
  if [ $variableJH == "yesyes" ]
  then
     break
  fi
done

}

######################################################################
#
#   FUNCTION :encrypt arithmetic(jiamisuanfa)凯撒加密(位移)算法
#   PARAMETER:密码字符集(如变量All)
#   INPUT    :加密:Caesar "$All" 2 -e $variablesystem
#   OUT      :解密  Caesar "$All" 2 -d `Caesar "$All" 2 -e $variablesystem` 
######################################################################
Caesar()
{
  rawdata="$1"
  offset="$2"
  action="$3"
  text="$4"
  length=$(echo "$rawdata"|awk '{print length()}')

  for((i=1;i<=$length;i++))

  do

         [ $i -eq 1 ] && y=""

          x=$((i+offset))

         [ $x -gt $length ] && y="$y$(echo $rawdata|cut -b $((x-length)))" || y="$y$(echo -n $rawdata|cut -b $x)"

  done

  [ "$action" = "-e" ]&&echo "$text"|tr "$rawdata" "$y"

  [ "$action" = "-d" ]&&echo "$text"|tr "$y" "$rawdata"

}

######################################################################
#
#   FUNCTION :oracle_user_check 核对oracle用户是否存在
#   PARAMETER:nothing
#   OUT      :noting
######################################################################
function oracle_user_check()
{
  rm -rf /tmp/oracle_test.log
  su - oracle -c "exit" >>/tmp/oracle_test.log  2>&1
  find_oracle_check=`cat /tmp/oracle_test.log|grep "does not exist"`
  if [ "_" != _"$find_oracle_check" ]
  then
   printf " user oracle does not exist!\n\r"
   exit 
  fi
  printf "user oracle check ok!\n\r"
}

######################################################################
#
#   FUNCTION :database user validate
#   PARAMETER:nothing
#   OUT      :noting
######################################################################
function DB_user_password()
{
 #测试数据库启动否
 startDB
 echo ""
 
 #非数据库管理员用户(genex)
 mulu=/tmp/user_genex_password.log
 printf "\033[1mPlease input your $DBusergenex password: \033[0m\n"
 stty -echo
 read variablegenex
 stty echo
 printf "  \n\r"
 if [ -z $variablegenex ]
 then
    printf "Input $DBusergenex password error! Please reinstall!\n\r"
    printf "  \n\r"
    printf "  \n\r"
    exit
 fi
 #使用用户和密码登录并将返回信息写入文本
 rm -rf /tmp/DB_genex_login.log  2>&1

 su - $DBUSER -c "sqlplus $DBusergenex/$variablegenex <<EOF
      quit;
      EOF" >>/tmp/DB_genex_login.log  2>&1
 find_genex_check=`cat /tmp/DB_genex_login.log|grep "logon denied"`
 if [ "_" == _"$find_genex_check" ]
  then
      #保存输入的用户名密码
      rm -rf $mulu >/dev/null 2>&1
      variablegenex_serect=`Caesar "$All" 2 -e $variablegenex`
      printf "$DBusergenex:$variablegenex_serect\n\r" >>$mulu 2>&1
  else
      printf "Input $DBusergenex password error! Please reinstall!\n\r"
      printf "  \n\r"
      printf "  \n\r"
      exit 
  fi
   
  #数据库管理员用户(system)
  mulus=/tmp/user_system_password.log
  printf "\033[1mPlease input your $DBusersystem password: \033[0m\n"
  stty -echo
  read variablesystem
  stty echo
  printf "  \n\r"
  if [ -z $variablesystem ]
  then
     printf "Input $DBusersystem password error! Please reinstall!\n\r"
     printf "  \n\r"
     printf "  \n\r"
     exit 
  fi
  #使用用户和密码登录并将返回信息写入文本
  rm -rf /tmp/DB_system_login.log 2>&1

  su - $DBUSER -c "sqlplus $DBusersystem/$variablesystem  as sysdba <<EOF
       quit;
       EOF" >>/tmp/DB_system_login.log 2>&1
  find_system_check=`cat /tmp/DB_system_login.log|grep "logon denied"`
  if [ "_" == _"$find_system_check" ]
  then
      #保存输入的用户名密码
      rm -rf $mulus >/dev/null 2>&1
      variablesystem_serect=`Caesar "$All" 2 -e $variablesystem`
      printf "$DBusersystem:$variablesystem_serect\n\r" >>$mulus 2>&1
  else
      printf "Input $DBusersystem password error! Please reinstall!\n\r"
      printf "  \n\r"
      printf "  \n\r"
      exit
  fi
 
}