' ------------------------------------------------------------ ' $Id$ ' ' TEST SCRIPT ' batchcomp ' Compile all MIBs in a given directory ' ' ------------------------------------------------------------ ' Common Objects Set Stdout = WScript.Stdout Set Stdin = WScript.Stdin Set WshShell = WScript.CreateObject("WScript.Shell") Dim AllSMIFiles(5000) Dim AllVOSMIFiles(5000) Dim AllModules(5000) Dim NumberOfModules Dim TotalPackageSize ' ----------------------- ' Check usage & arguments ' ----------------------- if WScript.Arguments.Count <> 2 then StdOut.WriteLine "batchcomp.vbs Compile an entire directory inplace" StdOut.WriteLine "Usage: batchcomp " StdOut.WriteLine "Example : batchcomp Netscreen *.mib" WScript.Quit end if ' ---------------------------- ' Create all require Objects ' ---------------------------- FolderName = WScript.Arguments.Item(0) Wildcard = WScript.Arguments.Item(1) If Left(Wildcard,1) = "*" Then Wildcard = Replace(Wildcard,"*",".*") End If Stdout.Write "Enter name of package : " MIBPackageName = Stdin.ReadLine MIBPackageName = Trim(MIBPackageName) If Len(MIBPackageName) = 0 Then MIBPackageName = "UntitledMibPackage" End If MIBPackageFileName = MIBPackageName & ".zip" Stdout.Write "Enter folder name (will appear in Unbrowse tree) : " MIBFolderName = Stdin.ReadLine Stdout.Write "Enter short package description : " MIBPackageDescription = Stdin.ReadLine NumberOfModules = 0 TotalPackageSize = 0 ProcessFolder FolderName CreateManifestFile FolderName DoZip FolderName '--------- ' Cleanup '--------- ' ------------------------------------------------------------- ' ProcessFolder - Compile Each File in the Specified folder ' ------------------------------------------------------------- Sub ProcessFolder(inputFolder) Dim fso , f Dim files , file Dim oldDir ' Open the Folder Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder(inputFolder) ' Move working directory to folder oldDir = WSHShell.CurrentDirectory WSHShell.CurrentDirectory = f.Path ' Wildcard processing Dim objRE Set objRE = New RegExp objRE.Pattern = WildCard objRE.IgnoreCase = True ' Process all files in the folder matching wildcard Set files = f.Files For Each file In files If objRE.Test(file.Name) = True Then CompileAddFile file.Name, f.Path End If Next Set objRE=Nothing ' Restore Working Directory WSHShell.CurrentDirectory = oldDir End Sub '''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Subroutine to Compile the MIB File & Add 2 Repository '''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub CompileAddFile(InputMibFile, WorkingDirPath) On Error Resume Next StdOut.WriteLine "Compiling .. " & InputMibFile Set Mibc = CreateObject("UnbrowseSNMP.MIBBrowser") With Mibc .AddPath("c:\program files\unleash networks\Unbrowse SNMP\mibs\smi\system") .AddPath("c:\program files\unleash networks\Unbrowse SNMP\mibs\smi") .AddPath(WorkingDirPath) .ErrorMessageSeverity = 1 .Strictness = 1 .EnableDeepSearch = True .Compile(InputMibFile) nErrors = .ErrorCount nWarnings = .WarningCount msgError = .ErrorText End With If nErrors+ nWarnings > 0 Then StdOut.WriteLine " --- Done --- " & InputMibFile & " Errors : " & nErrors & " Warnings : " & nWarnings & vbCrLf Else StdOut.WriteLine " --- Done --- " & InputMibFile & " 0 Errors, 0 Warnings" & vbCrLf End If '----------------------------------------- ' Save compiled module (only if no errors) '----------------------------------------- If nErrors = 0 Then Set Module = Mibc.CompiledModule ModName = Left(Module.Name,Len(Module.Name)-1) Set Module=Nothing CompiledFileName = ModName & ".vosmi" CompiledFilePath = WorkingDirPath & "\" & CompiledFileName Mibc.SaveAs CompiledFilePath AllSMIFiles(NumberOfModules) = InputMibFile AllVOSMIFiles(NumberOfModules) = CompiledFileName AllModules(NumberOfModules) = ModName ' ----------------------------------- ' Update modules and sizes ' ----------------------------------- NumberOfModules = NumberOfModules + 1 Set fso2 = CreateObject("Scripting.FileSystemObject") Set fSMI = fso2.GetFile(InputMibFile) Set fVOSMI = fso2.GetFile(CompiledFileName) TotalPackageSize = TotalPackageSize + fSMI.Size + fVOSMI.Size Set fso2 = Nothing End If Set Mibc = Nothing End Sub '''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Subroutine to create the XML Manifest file '''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub CreateManifestFile(workingFolder) Dim oldDir Dim fso Set fso = CreateObject("Scripting.FileSystemObject") ' Move working directory to folder Set f = fso.GetFolder(workingFolder) oldDir = WSHShell.CurrentDirectory WSHShell.CurrentDirectory = f.Path Set manif = fso.CreateTextFile ("MibPkManifest.xml") Set zipmanif = fso.CreateTextFile ("7ZipManifest.txt") zipmanif.WriteLine "MibPkManifest.xml" ' ------------------------------------ ' Write package section ' ------------------------------------ manif.WriteLine "" manif.WriteLine " "& MIBPackageName & "" manif.WriteLine " "& MIBFolderName & "" manif.WriteLine " " & Date() &"" manif.WriteLine " Unleash Networks " manif.WriteLine " v1.0" manif.WriteLine " " & MIBPackageDescription & "" manif.WriteLine " " & NumberOfModules & "" manif.WriteLine " " & TotalPackageSize & "" ' ------------------------------------ ' Write XML modules section ' ------------------------------------ manif.WriteLine vbTab & "" For I = 0 To NumberOfModules - 1 manif.WriteLine vbTab & vbTab &_ "" zipmanif.WriteLine AllVOSMIFiles(I) zipmanif.WriteLine AllSMIFiles(I) Next manif.WriteLine vbTab & "" ' ------------------------------------ ' End package section ' ------------------------------------ manif.WriteLine "" manif.Close() zipmanif.Close() StdOut.WriteLine "Wrote MIB Package manifest file MibPkManifest.xml" StdOut.WriteLine "Wrote 7-Zip manifest file 7ZipManifest.txt" ' Restore Working Directory WSHShell.CurrentDirectory = oldDir End Sub '''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Subroutine to create the XML Manifest file '''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub DoZip(workingFolder) Dim oldDir Dim fso ' Move working directory to folder Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder(workingFolder) oldDir = WSHShell.CurrentDirectory WSHShell.CurrentDirectory = f.Path ZipCommand = "7za.exe a -tzip " & MIBPackageFileName & " @7zipManifest.txt" WSHShell.Run ZipCommand, 1, True StdOut.WriteLine "Successfully created Unbrowse SNMP MIB Package " & MIBPackageFileName StdOut.WriteLine "Please verify by installing before publication" ' Restore Working Directory WSHShell.CurrentDirectory = oldDir End Sub