]> git.openfabrics.org - ~shefty/rdma-win.git/commitdiff
[WinOF] WIX
authorstansmith <stansmith@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Fri, 15 Jun 2007 22:32:06 +0000 (22:32 +0000)
committerstansmith <stansmith@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Fri, 15 Jun 2007 22:32:06 +0000 (22:32 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1@702 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

branches/WinOF/WIX/CustomActions.vbs

index 7d231f10924676b103a1e3ed6e81f22457eae9a4..cc296562e28b2f40450e750ea97e3a1d528212d2 100644 (file)
@@ -91,31 +91,28 @@ Function FileDelete(filename)
     Set fso = CreateObject("Scripting.FileSystemObject")\r
     Err.clear\r
     If fso.FileExists(filename) Then\r
-         fso.DeleteFile(filename), True\r
-         If Err Then\r
-               msgbox "Could not delete: " & filename\r
-       ' Display error number and description if applicable\r
-       ShowError\r
-       Err.clear\r
-      End If \r
+           On Error Resume Next \r
+           fso.DeleteFile(filename),True\r
+           If (Err AND Err.Number <> 70) Then  ' tolerate protection errors\r
+                   ErrMsg ("Could not delete: " & filename)\r
+        End If \r
     End If\r
 End Function\r
 \r
+\r
 ' Move and then Delete a file. File is moved into %TEMP%\basename(filename)\r
 ' then deleted; pesky files in 'system32\drivers'.\r
 \r
 Function FileMDelete(filename)\r
     Dim fso\r
     Set fso = CreateObject("Scripting.FileSystemObject")\r
+       On Error Resume Next \r
     Err.clear\r
     If fso.FileExists(filename) Then\r
       Set WshShell = CreateObject("WScript.Shell")\r
       Return = WshShell.Run ("cmd.exe /c del /Q /F " & filename, 0, true)\r
       If Err Then\r
-               msgbox "Could not delete: " & filename\r
-       ' Display error number and description if applicable\r
-       ShowError\r
-       Err.clear\r
+               ErrMsg ("Could not delete: " & filename)\r
       End If \r
     End If\r
 End Function\r
@@ -123,13 +120,13 @@ End Function
 Function FileMove(filename,destination)\r
     Dim fso\r
     Set fso = CreateObject("Scripting.FileSystemObject")\r
+    On Error Resume Next \r
     If fso.FileExists(filename) Then\r
-      On Error Resume Next \r
-         fso.MoveFile filename,destination\r
-         'if err then msgbox "Could not move: " & filename\r
-      err.clear \r
+           fso.MoveFile filename,destination\r
+           If (Err AND Err.Number <> 70) then ' tolerate protection errors.\r
+            ErrMsg ("Could not move: " & filename & " to " & destination)\r
+        End if\r
     End If\r
-    ' Display error number and description if applicable\r
     If Err Then ShowError\r
 End Function\r
 \r
@@ -209,6 +206,7 @@ End if
     \r
     ' MTARCH=x86 SystemFolder = System32\r
     ' MTARCH=amd64 SystemFolder = Syswow64\r
+\r
        FileDelete(sSystemFolder & "ibal.dll")\r
        FileDelete(sSystemFolder & "ibald.dll")\r
        FileDelete(sSystemFolder & "complib.dll")\r
@@ -356,17 +354,16 @@ Function ChopChar(strString, strChar)
 End Function\r
 \r
 \r
-' Add [INSTALLDIR] to the system search path registry entry @\r
-' HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path\r
-' Called from a defered exection context.\r
+' Add specified path to the system search path registry entry @\r
+' 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path'\r
+' Generally the path is [INSTALLDIR]\r
+' Called from a defered exection context (aka, DriverInstall).\r
 \r
 Function SysPathAdd(InstallDir)\r
 \r
     Dim rc, result, sInstallDir, newPath\r
 \r
     ' On Error Resume Next\r
-    ' InstallDir = Session.Property("INSTALLDIR") for reference\r
-    ' sInstallDir = Left(InstallDir,Len(InstallDir) - 1)  ' remove trailing \\r
     sInstallDir = ChopChar(InstallDir,"\")\r
 \r
     result = ReadSysPath\r
@@ -394,6 +391,7 @@ Function SysPathAdd(InstallDir)
 End Function\r
 \r
 \r
+' Remove specified path from the system search path.\r
 \r
 Function SysPathRemove(InstallDir)\r
 \r
@@ -417,22 +415,14 @@ Function SysPathRemove(InstallDir)
         ' INSTALLDIR IS in the system search path\r
         ' remove INSTALLDIR from system search path\r
         s0 = Left(curPath,start-1)\r
-msgbox "target " & Len(sInstallDir) & vbCRLF & sInstallDir\r
-msgbox "cur " & Len(curPath) & vbCRLF & curPath\r
-msgbox "s0 " & Len(s0) & vbCRLF & s0\r
         s1 = Right(curPath,Len(curPath) - (start+Len(sInstallDir) - 1))\r
-msgbox "s1 " & Len(s1) & vbCRLF & s1\r
         NewPath = s0 & s1\r
-msgbox  "SPR: Reset-Path " & NewPath\r
         rc = WriteSysPath(NewPath)\r
         If rc <> 0 Then\r
             SysPathRemove = ShowErr2("SysPathRemove - WriteSysPath()")\r
         End if\r
     End if\r
 \r
-    curPath = ReadSysPath\r
-msgbox "SPR: Cur " & curPath\r
-\r
 End Function\r
 \r
 \r
@@ -550,11 +540,7 @@ Function DriverInstall()
 \r
        sInstalldir = PropArray(0)\r
        \r
-    ' xxx temp - Add INSTALLDIR to system search path.\r
-    'If SysPathAdd(sInstalldir) Then\r
-    '    DriverInstall=1\r
-    '    Exit Function\r
-    'End If\r
+    Uninstall_IB_Devices(sInstalldir) \r
 \r
        RemoveDriverFiles\r
    \r
@@ -569,7 +555,8 @@ Function DriverInstall()
     End if\r
 \r
     ' rescan system buses\r
-       Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir & "IBcore & devman.exe rescan", 0, true)\r
+       Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir & _\r
+                           "IBcore & devman.exe rescan", 0, true)\r
        ' Display error number and description if applicable\r
     If Err Then ShowError\r
     If Return <> 0 Then\r
@@ -580,7 +567,9 @@ Function DriverInstall()
        \r
                \r
     ' Install HCA Driver\r
-       Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir & "IBcore & devman.exe update mthca.inf PCI\VEN_15b3", 0, true)\r
+       Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir _\r
+                         & "IBcore & devman.exe update mthca.inf PCI\VEN_15b3",_\r
+                         0, true)\r
        ' Display error number and description if applicable\r
     If Err Then ShowError\r
 \r
@@ -591,9 +580,12 @@ Function DriverInstall()
     End if\r
        \r
     ' Check/install IPoIB driver\r
-    ' Only if InstallShield component 'net' is NOT tagged as containing a Device Driver    \r
+    ' Only if InstallShield component 'net' is NOT tagged as containing a\r
+    ' Device Driver    \r
     If fso.FileExists(sInstalldir & "net\netipoib.inf") Then\r
-       Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir & "net & ..\IBcore\devman.exe update netipoib.inf IBA\IPoIB", 0, true)\r
+       Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir _\r
+                 & "net & ..\IBcore\devman.exe update netipoib.inf IBA\IPoIB",_\r
+                 0, true)\r
        If Err Then ShowError\r
     End If\r
     \r
@@ -603,8 +595,10 @@ Function DriverInstall()
     If (MTARCH="amd64") Then\r
                Dim SYSWOW\r
        SYSWOW = PropArray(1)  \r
+\r
 ' following file copies relocated to .wxs file so they can be uninstalled \r
 ' correctly, as this way the files reamin when uninstalled.\r
+\r
 if False then\r
         msgbox "DriverInstall PA(1) " & SYSWOW & " PA(2) " & PropArray(2)\r
                if fso.FileExists(sInstalldir & "IBcore\cl32.dll") then\r
@@ -636,6 +630,7 @@ if False then
 \r
        err.clear \r
     DriverInstall=0\r
+\r
 End Function\r
 \r
 \r
@@ -715,33 +710,19 @@ End Function
 \r
 \r
 \r
-''''''''''' Driver Uninstall ''''''''''''\r
-\r
-Sub DriverUninstall()  \r
-      Dim sInstalldir, WshShell, fso, devices\r
+Function Uninstall_IB_Devices(sInstalldir)\r
 \r
-      sInstalldir = Session.Property("INSTALLDIR")\r
+      Dim WshShell, fso, devices\r
 \r
       Set WshShell = CreateObject("WScript.Shell")\r
       Set fso = CreateObject("Scripting.FileSystemObject")\r
 \r
-      MTARCH = Architecture\r
-       \r
-      ' WSD doesn't work on XP and should NOT be installed; just in case.\r
-         ' if WSD installed, then it's enabled, shut down the service\r
-\r
-      If (Session.Property("VersionNT") <> 501) AND fso.FileExists(sInstalldir & "installsp.exe") Then\r
-         Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir & " & installsp.exe -r", 0, true)\r
-      End If\r
-      \r
-      ' stop the openSM service in case it was started.\r
-      Return = WshShell.Run ("cmd.exe /c sc.exe stop opensm", 0, true)\r
-\r
-      ' delete opensm service from regisry\r
-      Return = WshShell.Run ("cmd.exe /c sc.exe delete opensm", 0, true)\r
-      If Err Then ShowError\r
+      If (fso.FileExists(sInstalldir & "IBcore\devman.exe") = False) Then\r
+          Exit Function ' no reason to continue without the tool.\r
+      End if\r
 \r
       ' create a list of IBA\ devices via 'devcon findall'\r
+\r
       devices = FindDevices\r
       \r
       ' Remove IPoIB Adapter instances\r
@@ -749,7 +730,9 @@ Sub DriverUninstall()
                if (Instr(deviceCan,"IBA\IPOIB")) Then\r
                        device = split(deviceCan, " ")\r
                        ' Removing\r
-               Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir & "IBcore & devman.exe remove @" & device(0), 0, true)\r
+            'msgbox "RmDev " & device(0) ' XXX\r
+               Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir _\r
+                                               & "IBcore & devman.exe remove @" & device(0), 0, true)\r
                End if\r
          Next\r
 \r
@@ -758,7 +741,8 @@ Sub DriverUninstall()
                if (Instr(deviceCan,"InfiniBand I/O Unit")) Then\r
                        device = split(deviceCan, " ")\r
                        ' Removing I/O Unit of the SRP\r
-               Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir & "IBcore & devman.exe remove @" & device(0), 0, true)\r
+               Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir _\r
+                                               & "IBcore & devman.exe remove @" & device(0), 0, true)\r
                End if\r
          Next\r
          \r
@@ -767,37 +751,76 @@ Sub DriverUninstall()
                if (Instr(deviceCan,"SRP")) Then\r
                        device = split(deviceCan, " ")\r
                        ' Removing SRP\r
-                       Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir & "IBcore & devman.exe remove @" & device(0), 0, true)\r
+                       Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir _\r
+                                               & "IBcore & devman.exe remove @" & device(0), 0, true)\r
                End if\r
          Next\r
 \r
-      Set objWshScriptExec = wshShell.Exec("cmd.exe /c " & sInstalldir & "IBcore & devman.exe FindAll * | FIND ""IPOIB""")\r
+      Set objWshScriptExec = wshShell.Exec("cmd.exe /c " & sInstalldir _\r
+                                                       & "IBcore & devman.exe FindAll * | FIND ""IPOIB""")\r
       If Err Then ShowError\r
       Set objStdOut = objWshScriptExec.StdOut\r
 \r
       While Not objStdOut.AtEndOfStream\r
           strLine = objStdOut.ReadLine\r
           device = split(strLine, " ")\r
-          Return = wshShell.run("cmd.exe /c cd " & sInstallDir & "IBcore & devman.exe remove @" & device(0),0,true)\r
+          Return = wshShell.run("cmd.exe /c cd " & sInstallDir _\r
+                                                       & "IBcore & devman.exe remove @" & device(0),0,true)\r
       Wend\r
 \r
+      ' Remove HCAs\r
+      Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir _\r
+                                               & "IBcore & devman.exe remove PCI\VEN_15B3", 0, true)\r
+      If Err Then ShowError\r
+\r
       ' Remove InfiniBand Bus/Fabric class driver\r
 \r
-      Set objWshScriptExec = wshShell.Exec("cmd.exe /c cd " & sInstalldir & "IBcore & devman.exe FindAll * | FIND ""InfiniBand Fabric""")\r
+      Set objWshScriptExec = wshShell.Exec("cmd.exe /c cd " & sInstalldir _\r
+                       & "IBcore & devman.exe FindAll * | FIND ""InfiniBand Fabric"" ")\r
       If Err Then ShowError\r
+\r
       Set objStdOut = objWshScriptExec.StdOut\r
 \r
       While Not objStdOut.AtEndOfStream\r
           strLine = objStdOut.ReadLine\r
           device = split(strLine, " ")\r
-          Return = wshShell.Run("cmd.exe /c cd " & sInstalldir & "IBcore & devman.exe remove @" & device(0),0,true)\r
+          Return = wshShell.Run("cmd.exe /c cd " & sInstalldir _\r
+                                                       & "IBcore & devman.exe remove @" & device(0),0,true)\r
           If Err Then ShowError\r
       Wend\r
 \r
-      ' Remove HCAs\r
-      Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir & "IBcore & devman.exe remove PCI\VEN_15b3", 0, true)\r
+End Function\r
+\r
+\r
+\r
+''''''''''' Driver Uninstall ''''''''''''\r
+\r
+Sub DriverUninstall()  \r
+      Dim sInstalldir, WshShell, fso\r
+\r
+      sInstalldir = Session.Property("INSTALLDIR")\r
+\r
+      Set WshShell = CreateObject("WScript.Shell")\r
+      Set fso = CreateObject("Scripting.FileSystemObject")\r
+\r
+      ' WSD doesn't work on XP and should NOT be installed; just in case.\r
+         ' if WSD installed, then it's enabled, shut down the service\r
+\r
+      If (Session.Property("VersionNT") <> 501) AND _\r
+                               fso.FileExists(sInstalldir & "installsp.exe") Then\r
+         Return = WshShell.Run ("cmd.exe /c cd " & sInstalldir & _\r
+                                                                                       " & installsp.exe -r", 0, true)\r
+      End If\r
+      \r
+      ' stop the openSM service in case it was started.\r
+      Return = WshShell.Run ("cmd.exe /c sc.exe stop opensm", 0, true)\r
+\r
+      ' delete opensm service from registry\r
+      Return = WshShell.Run ("cmd.exe /c sc.exe delete opensm", 0, true)\r
       If Err Then ShowError\r
 \r
+      Uninstall_IB_Devices(sInstalldir)\r
+\r
       ' Remove Service entries from the registry\r
       \r
       DeleteRegKey "System\CurrentControlSet\Services\ibbus"\r
@@ -862,17 +885,21 @@ Sub ShowError()
     End if\r
        strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _\r
                 Err.Description & vbCrLf & vbCrLf\r
-       'Syntax\r
-       msgbox "ShowError - " & strMsg\r
+       msgbox strMsg\r
 End Sub\r
 \r
 \r
+Sub ErrMsg(msg)\r
+    If Err.Number <> 0 Then\r
+           msgbox msg & vbCrLf & "Err # " & Err.Number & vbCrLf & Err.Description\r
+       Err.clear\r
+    End if\r
+End Sub\r
+\r
 Function ShowErr2(msg)\r
-msgbox "Err # " & Err.Number\r
     If Err.Number <> 0 Then\r
            strMsg = vbCrLf & "Err # " & Err.Number & vbCrLf & _\r
-                    Err.Description & vbCrLf & vbCrLf\r
-           'Syntax\r
+                    Err.Description & vbCrLf\r
            msgbox msg & strMsg\r
     End if\r
     ShowErr2=Err.Number\r
@@ -920,8 +947,30 @@ Sub OpensmServiceEvent()
 End Sub\r
 \r
 \r
-' Determine if an existing WinOF or openib-window installation exists.\r
-' If existing, determined by registry entry for service/ibbus,\r
+Sub ScheduleReboot\r
+               \r
+       Set objWMILocator = CreateObject ("WbemScripting.SWbemLocator") \r
+         objWMILocator.Security_.Privileges.AddAsString "SeShutdownPrivilege",True \r
+       Set objWMIServices = objWMILocator.ConnectServer(strComputerName, _\r
+                                                                       cWMINameSpace, strUserID, strPassword)\r
+       Set objSystemSet = GetObject(_\r
+                       "winmgmts:{impersonationLevel=impersonate,(Shutdown)}")._\r
+                               InstancesOf("Win32_OperatingSystem")\r
+\r
+    ' Forced restart\r
+       For Each objSystem In objSystemSet\r
+                       objSystem.Win32Shutdown 2+4\r
+                       objSystem.Win32Shutdown 2+4\r
+                       objSystem.Win32Shutdown 2+4\r
+       Next\r
+               \r
+       'msgbox "Please wait while computer restart ...",0,"MellanoxWinIB32"\r
+\r
+End Sub\r
+\r
+\r
+' Determine if an existing WinOF or openib-window installation is present.\r
+' If previous install exists, determined by registry entry for service/ibbus,\r
 ' then uninstall and reboot.\r
 ' Called in immediate mode, condition: INSTALL=1\r
 \r
@@ -932,7 +981,7 @@ Function ChkInstallAndReboot()
     Const wshQuestionMark = 32\r
 \r
        Dim status ' check if ibbus.sys exists, if not the reboot won't happen\r
-       Dim fso\r
+       Dim fso, originalReboot\r
     Set fso = CreateObject("Scripting.FileSystemObject")    \r
     status = 0\r
     \r
@@ -940,32 +989,63 @@ Function ChkInstallAndReboot()
     Return = WshShell.Run ("reg.exe query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ibbus /v ImagePath", 0, true)\r
     If (Return = 0) And (Err.Number = 0) Then\r
        Status = Status + 1\r
-     End if\r
+    End if\r
     \r
+    originalReboot = Session.Property("REBOOT")\r
+\r
+    DriverUninstall\r
+\r
     ' if we can't find registry entry, then no need to uninstall/restart.\r
     ' Proceed with installation\r
     If status = 0 then\r
        ' msgbox "No existing InfiniBand installation detected"\r
+        Session.Property("REBOOT") = originalReboot \r
        Exit Function\r
     End if\r
        \r
+       Dim sys_folder, drv_folder\r
+       ' Idea here is to rename driver files to force a driver\r
+       ' load failure upon next reboot so ensuing install will\r
+       ' succeed.\r
+       sys_folder = Session.Property("WindowsFolder") & "system32"\r
+       drv_folder = sys_folder & "\drivers"\r
+       \r
+       If fso.FileExists(drv_folder & "\ibbus.sys") Then\r
+               FileMove drv_folder & "\ibbus.sys",drv_folder & "\ibbus.sy1"\r
+       End if\r
+       If fso.FileExists(drv_folder & "\mthca.sys") Then\r
+               FileMove drv_folder & "\mthca.sys",drv_folder & "\mthca.sy1"\r
+       End if  \r
+       If fso.FileExists(sys_folder & "\ibinstaller.dll") Then\r
+               FileMove sys_folder & "\ibinstaller.dll",sys_folder & "\ibinstaller1.dll"\r
+       End if\r
+       \r
     ' Notify the user an existing non WinOF IB installation was detected and\r
     ' the system will be rebooted.\r
     dim res\r
        \r
-    res = WshShell.Popup("Existing InfiniBand installation has been removed.",12,"WinOF - Existing InfiniBand installation Detected") \r
+    res = WshShell.Popup("Existing InfiniBand installation has been removed." _\r
+             & vbCRLF & vbCRLF & "Automatic REBOOT in 10 seconds."_\r
+             & vbCRLF & "Please re-install WinOF."_\r
+             ,15,"WinOF - Existing InfiniBand installation Detected")\r
\r
+    'run_once_cmd = Session.Property("SETUPEXEDIR") & "\setup.exe"\r
+    'RunAtReboot(run_once_cmd)\r
+    \r
+       ' the _Driver Uninstall call sets reboot=force. The ForceReboot action\r
+       ' following this CustomAction will fire when reboot is set =force.\r
+    ' The problem is we need to fail the installation so it cleans up, not\r
+    ' a partial install, and still reboots - So far IS-12 doesn;t support\r
+    ' this behavior.\r
 \r
-    ' proceed with Uninstall and reboot.\r
-    ' Upon system restart, WinOF installation needs to be restarted \r
-    ' consider a run-once invocation.\r
+    ScheduleReboot\r
 \r
-    DriverUninstall\r
+    ' Fail the install so cleanup occurs.\r
+       ' Upon system restart, WinOF installation needs to be restarted \r
+       ' consider a run-once invocation.\r
 \r
-    ChkInstallAndReboot = 0\r
+       ChkInstallAndReboot = 2 ' will force install cleanup.\r
 \r
-    ' the _Driver Uninstall call sets reboot=force. The ForceReboot action\r
-    ' following this CustomAction will fire when reboot is set =force.\r
-       \r
 End Function\r
 \r
 \r