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

时间:2022-04-10 15:58:43
#!/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 $ |grep "^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$" > /dev/null
if [ $? = ]; then
return
else
a=`echo $ | awk -F. '{print $1}'`
b=`echo $ | awk -F. '{print $2}'`
c=`echo $ | awk -F. '{print $3}'`
d=`echo $ | awk -F. '{print $4}'`
for loop in $a $b $c $d
do
if [ $loop -gt ] || [ $loop -lt ]; then
return
fi
done
fi
} while(())
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 " "man" "" "tun" "" "peer_tun" "" > data
exitstatus=$?
if [ $exitstatus != ]; 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 " "tun" "" "peer_tun" "" >data
exitstatus=$?
if [ $exitstatus != ]; 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 " "man" "" > data
exitstatus=$?
if [ $exitstatus != ]; 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 :" ${arr[]} --title "Config NetWork" >& >& >&)
exitstatus=$?
if [ $exitstatus != ]; then
continue
fi
Maskaddr=$(whiptail --inputbox "Please input interface "$select_ethname" MaskAddr :" ${arr[]} --title "Config NetWork" >& >& >&)
exitstatus=$?
if [ $exitstatus != ]; then
continue
fi
GateWay=$(whiptail --inputbox "Please input interface "$select_ethname" GateWay" ${arr[]} --title "Config NetWork" >& >& >&)
exitstatus=$?
if [ $exitstatus != ]; then
continue
fi
if [ "$IPaddr"x = ""x ] || [ "$Maskaddr"x = ""x ]; then
whiptail --title "Message Box" --msgbox "Incomplete input information, configuration failed!"
continue
fi
CheckIPAddress $IPaddr
if [ $? != ]; then
whiptail --title "Message Box" --msgbox "IPaddr Error, configuration failed!"
continue
fi
CheckIPAddress $Maskaddr
if [ $? != ]; then
whiptail --title "Message Box" --msgbox "Maskaddr Error, configuration failed!"
continue
fi
if [ "$GateWay"x != ""x ]; then
CheckIPAddress $GateWay
if [ $? != ]; then
whiptail --title "Message Box" --msgbox "GateWay Error, configuration failed!"
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 != ]; 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 :" $compaddr --title "Config network" >& >& >&)
exitstatus=$?
if [ $exitstatus != ]; then
continue
fi
if [ "$compaddr"x != ""x]; then
CheckIPAddress $compaddr
if [ $? != ]; then
whiptail --title "Message Box" --msgbox "IPaddr Error, configuration failed!"
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 != ]; then
continue
fi
fi fi
done