Commit 13dc65e4 authored by Jondy Zhao's avatar Jondy Zhao

Fix add tap-driver in different locale problem

parent 48aabca1
...@@ -318,6 +318,36 @@ function format_interface_name() ...@@ -318,6 +318,36 @@ function format_interface_name()
fi fi
} }
# ======================================================================
# Routine: get_all_connections
# Return all connection names line by line, and replace space with '%'
# ======================================================================
function get_all_connections()
{
netsh interface ipv6 show interface | \
grep "^[ 0-9]\+ " | \
sed -e "s/^[ 0-9]\+[a-zA-Z]\+//" -e "s/^\s*//" -e "s/ /%/g"
} # === get_all_connections() === #
# ======================================================================
# Routine: get_new_connection
# Check all the connection names, and compare the original connection
# list, return the new connection name
#
# Note: If nothing found, return empty
# If more than one, return the first one
# ======================================================================
function get_new_connection()
{
original_connections=" $* "
current_connections=$(get_all_connections)
for name in $current_connections ; do
[[ ! "$original_connections" == *[\ ]$name[\ ]* ]] && \
echo ${name//%/ } && return 0
done
} # === get_new_connections() === #
# #
# Parameter: # Parameter:
# ifname: connection name # ifname: connection name
...@@ -330,8 +360,6 @@ function install_tap_driver() ...@@ -330,8 +360,6 @@ function install_tap_driver()
local FILENAME="/etc/slapos/driver/OemWin2k.inf" local FILENAME="/etc/slapos/driver/OemWin2k.inf"
local DEVFILE=$(cygpath -w $FILENAME) local DEVFILE=$(cygpath -w $FILENAME)
local HWID=tap0901 local HWID=tap0901
local CHECKSCRIPT=$(cygpath -m /etc/slapos/scripts/check_driver_signing_dialog.vbs)
local GETSCRIPT=$(cygpath -m /etc/slapos/scripts/get_last_connection.vbs)
# check if ifname has been installed # check if ifname has been installed
if [[ ! "$1" == "" ]] ; then if [[ ! "$1" == "" ]] ; then
...@@ -353,67 +381,17 @@ function install_tap_driver() ...@@ -353,67 +381,17 @@ function install_tap_driver()
return 1 return 1
fi fi
local CSCRIPT=$(which cscript.exe) original_connections=$(echo $(get_all_connections))
if [[ ! -x $CSCRIPT ]] ; then
echo "Error: no cscript.exe found"
return 1
fi
if ! [[ -f $CHECKSCRIPT ]] ; then
cat <<EOF > $CHECKSCRIPT
Set oShell = CreateObject("WScript.Shell")
Do
If oShell.AppActivate("Hardware Installation") Then
WScript.Sleep 1000
oShell.SendKeys "%C"
WScript.Sleep 2000
End If
WScript.Sleep 1000
Loop While True
EOF
fi
# install driver
$CSCRIPT $CHECKSCRIPT > /dev/null &
local sid=$!
$DEVCON install $DEVFILE $HWID $DEVCON install $DEVFILE $HWID
kill $sid
# rename the connection name # rename the connection name
if [[ ! "$1" == "" ]] ; then if [[ ! "$1" == "" ]] ; then
OLDNAME=$(get_new_connection $original_connections)
if [[ ! -f $GETSCRIPT ]] ; then if [[ -n $OLDNAME ]] ; then
cat <<EOF > $GETSCRIPT
strComputer = "."
strPrefix = "Local Area Connection"
Set objWMIService = GetObject("winmgmts:\\\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT NetConnectionID FROM Win32_NetworkAdapter WHERE " & _
"NetConnectionID Like '" & strPrefix & "%'", _
"WQL", 48)
strLastConnectionName = ""
i = -1
k = Len(strPrefix)
For Each objItem In colItems
s = Right(objItem.NetConnectionID, Len(objItem.NetConnectionID) - k)
If s = "" Then
j = 0
Else
j = Int(s)
End If
If j > i Then
strLastConnectionName = objItem.NetConnectionID
i = j
End If
Next
WScript.StdOut.Write(strLastConnectionName)
WScript.Quit(0)
EOF
fi
# nodosfilewarning
local OLDNAME=$($CSCRIPT //Nologo $GETSCRIPT)
if (( $? == 0 )) ; then
netsh interface set interface name="$OLDNAME" newname="$1" netsh interface set interface name="$OLDNAME" newname="$1"
else
echo Failed to get new connection name.
return 1
fi fi
fi fi
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment