• 使用whiptail开发linux环境交互式对话框


    #!/bin/bash
    
    oem=$(/bin/cat /opt/jdwa/etc/oem)
    systype=$(/bin/cat /opt/jdwa/etc/systype)
    export select_ethname
    echo "oem:"$oem
    echo "systype:"$systype
    CheckIPAddress()
    {
        echo $1 |grep "^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$" > /dev/null
        if [ $? = 1 ];  then
            return 1
        else
            a=`echo $1 | awk -F. '{print $1}'`
            b=`echo $1 | awk -F. '{print $2}'`
            c=`echo $1 | awk -F. '{print $3}'`
            d=`echo $1 | awk -F. '{print $4}'`
            for loop in $a $b $c $d
            do
                if [ $loop -gt 255 ] || [ $loop -lt 0 ]; then
                    return 2
                fi
            done
        fi  
    }
    
    while((1)) 
    do
      if [ "$oem"x = "QIANZHI"x ]; then
        if [ "$systype"x = "int"x ]; then
            whiptail --title "Config network" --cancel-button "Quit" --menu "Select Config Network Device " 0 0 2 "man" "" "tun" "" "peer_tun" "" 2> data
        exitstatus=$?
            if [ $exitstatus != 0 ]; then
                break
            fi
            select_ethname=$(/bin/cat data)
            echo "Select Config Network Device:"$select_ethname
        fi
        if [ "$systype"x = "ext"x ]; then
            whiptail --title "Config network" --cancel-button "Quit" --menu "Select Config Network Device " 0 0 2 "tun" "" "peer_tun" "" 2>data
            exitstatus=$?
            if [ $exitstatus != 0 ]; then
                break
            fi
            select_ethname=$(/bin/cat data)
            echo "Select Config Network Device:"$select_ethname
        fi
      fi
      if [ "$oem"x = "COMPONENT"x ]; then
        if [ "$systype"x = "int"x ]; then
            whiptail --title "Config network" --cancel-button "Quit" --menu "Select Config Network Device " 0 0 2 "man" "" 2> data
            exitstatus=$?
            if [ $exitstatus != 0 ]; then
                break
            fi
            select_ethname=$(/bin/cat data)
            echo "Select Config Network Device:"$select_ethname
        fi
        if [ "$systype"x = "ext"x ]; then
            break
        fi
      fi
    
      if [ "$select_ethname"x = "man"x ] || [ "$select_ethname"x = "tun"x ]; then
          if [ "$select_ethname"x = "man"x ]; then    
              netinfo=$(/bin/cat /opt/jdwa/etc/man)
          else
              netinfo=$(/bin/cat /opt/jdwa/etc/tun0)
          fi
          IFS='/' arr=($netinfo)
          IPaddr=$(whiptail --inputbox "Please input interface "$select_ethname" IpAddr :" 10 60 ${arr[0]}  --title "Config NetWork" 3>&1 1>&2 2>&3)
          exitstatus=$?
          if [ $exitstatus != 0 ]; then
              continue
          fi
          Maskaddr=$(whiptail --inputbox "Please input interface "$select_ethname" MaskAddr :" 10 60 ${arr[1]}  --title "Config NetWork" 3>&1 1>&2 2>&3)
          exitstatus=$?
          if [ $exitstatus != 0 ]; then
              continue
          fi
          GateWay=$(whiptail --inputbox "Please input interface "$select_ethname" GateWay" 10 60 ${arr[2]}  --title "Config NetWork" 3>&1 1>&2 2>&3)
          exitstatus=$?
          if [ $exitstatus != 0 ]; then
              continue
          fi
          if [ "$IPaddr"x = ""x ] || [ "$Maskaddr"x = ""x ]; then
              whiptail  --title "Message Box" --msgbox "Incomplete input information, configuration failed!" 0 0
              continue
          fi
          CheckIPAddress $IPaddr
          if [ $? != 0 ]; then
              whiptail  --title "Message Box" --msgbox "IPaddr Error, configuration failed!" 0 0
              continue
          fi
          CheckIPAddress $Maskaddr
          if [ $? != 0 ]; then
              whiptail  --title "Message Box" --msgbox "Maskaddr Error, configuration failed!" 0 0
              continue
          fi
          if [ "$GateWay"x != ""x ]; then
              CheckIPAddress $GateWay
              if [ $? !=  ]; then
                  whiptail  --title "Message Box" --msgbox "GateWay Error, configuration failed!" 0 0
                  continue
              fi
          fi 
          if (whiptail --title "Config NetWork" --yesno "Please make sure to save the configuration.
              Devname : "$select_ethname"
              IpAddr  : "$IPaddr"
              MaskAddr: "$Maskaddr"
              GateWay : "$GateWay 0 0) then
              if [ "$select_ethname"x = "man"x ]; then
                  echo $IPaddr"/"$Maskaddr"/"$GateWay> /opt/jdwa/etc/man
              else
                  echo $IPaddr"/"$Maskaddr"/"$GateWay> /opt/jdwa/etc/tun0
              fi     
          else
              exitstatus=$?
              if [ $exitstatus != 0 ]; then
                  continue
              fi
          fi
      fi
      if [ "$select_ethname"x = "peer_tun"x ]; then
          compaddr=$(/bin/cat /opt/jdwa/etc/peer_tun0)
          IPaddr=$(whiptail --inputbox "Please input interface "$select_ethname" IpAddr :" 10 60 $compaddr  --title "Config network" 3>&1 1>&2 2>&3)
          exitstatus=$?
          if [ $exitstatus != 0 ]; then
              continue
          fi
          if [ "$compaddr"x != ""x]; then
              CheckIPAddress $compaddr
              if [ $? != 0 ]; then
                  whiptail  --title "Message Box" --msgbox "IPaddr Error, configuration failed!" 0 0
                  continue
              fi
          fi
          if (whiptail --title "Config NetWork" --yesno "Please make sure to save the configuration.
              Devname : "$select_ethname"
              IpAddr  : "$IPaddr 0 0) then
              echo $IPaddr> /opt/jdwa/etc/peer_tun0
          else
              exitstatus=$?
              if [ $exitstatus != 0 ]; then
                  continue
              fi
          fi
    
      fi
    done
  • 相关阅读:
    代码中引用res里的颜色、图片
    time.setToNow() 取当前时间,月份有误
    adb报错:The connection to adb is down, and a severe&nbs
    安卓下拉刷新、上拉加载数据显示
    4、安卓数据存储——sqlite
    3、安卓数据存储——缓存、内存管理
    2、安卓数据存储——本地文件
    1、安卓数据存储机制——sharedPreference
    一个异步任务接收两个url下载两个图片
    adb报错:The connection to adb is down, and a severe&nbs
  • 原文地址:https://www.cnblogs.com/dpf-10/p/8716842.html
Copyright © 2020-2023  润新知