bootstrap-msys2.vbs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ' This Source Code Form is subject to the terms of the Mozilla Public
  2. ' License, v. 2.0. If a copy of the MPL was not distributed with this
  3. ' file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. ' This script downloads and install MSYS2 and the preferred terminal emulator ConEmu
  5. Sub Download(uri, path)
  6. Dim httpRequest, stream
  7. Set httpRequest = CreateObject("MSXML2.ServerXMLHTTP.6.0")
  8. Set stream = CreateObject("Adodb.Stream")
  9. httpRequest.Open "GET", uri, False
  10. httpRequest.Send
  11. With stream
  12. .type = 1
  13. .open
  14. .write httpRequest.responseBody
  15. .savetofile path, 2
  16. End With
  17. End Sub
  18. Function GetInstallPath()
  19. Dim message, prompt
  20. message = "When you click OK, we will download and extract a build environment to the directory specified. You should see various windows appear. Do NOT interact with them until one explicitly prompts you to continue." & vbCrLf & vbCrLf & "Installation Path:"
  21. title = "Select Installation Location"
  22. GetInstallPath = InputBox(message, title, "c:\mozdev")
  23. end Function
  24. Dim installPath, msysPath, conemuPath, conemuSettingsPath, conemuExecutable, bashExecutable
  25. Dim conemuSettingsURI, settingsFile, settingsText, fso, shell, msysArchive, appShell, errorCode
  26. Dim mingwExecutable
  27. ' Set up OS interaction like filesystem and shell
  28. Set fso = CreateObject("Scripting.FileSystemObject")
  29. Set shell = CreateObject("WScript.Shell")
  30. Set appShell = CreateObject("Shell.Application")
  31. ' Get where MSYS2 and ConEmu should be installed, create directories if necessary
  32. installPath = GetInstallPath()
  33. msysPath = fso.BuildPath(installPath, "msys64")
  34. conemuPath = fso.BuildPath(installPath, "ConEmu")
  35. If NOT fso.FolderExists(installPath) Then
  36. fso.CreateFolder(installPath)
  37. fso.CreateFolder(msysPath)
  38. End If
  39. If NOT fso.FolderExists(installPath) Then
  40. MsgBox("Failed to create folder. Do you have permission to install in this directory?")
  41. WScript.Quit 1
  42. End If
  43. On Error Resume Next
  44. ' Download and move MSYS2 into the right place
  45. Download "https://api.pub.build.mozilla.org/tooltool/sha512/f93a685c8a10abbd349cbef5306441ba235c4cbfba1cc000299e11b58f258e9953cbe23463515407925eeca94c3f5d8e5f637c95be387e620845efa43cdcb0c0", "msys2.zip"
  46. Set FilesInZip = appShell.NameSpace(fso.GetAbsolutePathName("msys2.zip")).Items()
  47. appShell.NameSpace(msysPath).CopyHere(FilesInZip)
  48. ' MSYS2 archive doesn't have tmp directory...
  49. fso.CreateFolder(fso.BuildPath(msysPath, "tmp"))
  50. fso.DeleteFile("msys2.zip")
  51. If Err.Number <> 0 Then
  52. MsgBox("Error downloading and installing MSYS2. Make sure you have internet connection. If you think this is a bug, please file one in Bugzilla https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=Build%20Config")
  53. WScript.Quit 1
  54. End If
  55. On Error GoTo 0
  56. ' Install ConEmu
  57. ' Download installer
  58. On Error Resume Next
  59. Download "https://conemu.github.io/install2.ps1", "install2.ps1"
  60. conemuSettingsURI = "https://api.pub.build.mozilla.org/tooltool/sha512/9aa384ecc8025a974999e913c83064b3b797e05d19806e62ef558c8300e4c3f72967e9464ace59759f76216fc2fc66f338a1e5cdea3b9aa264529487f091d929"
  61. ' Run installer
  62. errorCode = shell.Run("powershell.exe -NoProfile -ExecutionPolicy Unrestricted set dst '" & conemuPath & "'; set ver 'stable'; set lnk 'Mozilla Development Shell'; set xml '" & conemuSettingsURI & "'; set run $FALSE; .\install2.ps1", 0, true)
  63. ' Delete ConEmu installer
  64. fso.DeleteFile("install2.ps1")
  65. If Err.Number <> 0 Then
  66. MsgBox("Error downloading and installing ConEmu. Make sure you have internet connection and Powershell installed. If you think this is a bug, please file one in Bugzilla https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=Build%20Config")
  67. WScript.Quit 1
  68. End If
  69. On Error GoTo 0
  70. ' Replace paths in ConEmu settings file
  71. conemuSettingsPath = fso.BuildPath(conemuPath, "ConEmu.xml")
  72. Set settingsFile = fso.OpenTextFile(conemuSettingsPath, 1)
  73. settingsText = settingsFile.ReadAll
  74. settingsFile.Close
  75. settingsText = Replace(settingsText, "%MSYS2_PATH", msysPath)
  76. Set settingsFile = fso.OpenTextFile(conemuSettingsPath, 2)
  77. settingsFile.WriteLine settingsText
  78. settingsFile.Close
  79. ' Make MSYS2 Mozilla-ready
  80. bashExecutable = fso.BuildPath(msysPath, fso.BuildPath("usr", fso.BuildPath("bin", "bash.exe")))
  81. conemuExecutable = fso.BuildPath(conemuPath, "ConEmu.exe")
  82. ' There may be spaces in the paths to the executable, this ensures they're parsed correctly
  83. bashExecutable = """" & bashExecutable & """"
  84. conemuExecutable = """" & conemuExecutable & """"
  85. errorCode = shell.Run(bashExecutable & " -l -c 'logout", 1, true)
  86. If errorCode <> 0 Then
  87. MsgBox("MSYS2 initial setup failed. Make sure you have full access to the path you specified. If you think this is a bug, please file one in Bugzilla at https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=Build%20Config")
  88. WScript.Quit 1
  89. End If
  90. errorCode = shell.Run(bashExecutable & " -l -c 'pacman -Syu --noconfirm wget mingw-w64-x86_64-python2-pip && logout'", 1, true)
  91. If errorCode <> 0 Then
  92. MsgBox("Package update failed. Make sure you have internet access. If you think this is a bug, please file one in Bugzilla at https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=Build%20Config")
  93. WScript.Quit 1
  94. End If
  95. errorCode = shell.Run(conemuExecutable & " -run set CHERE_INVOKING=1 & set MSYSTEM=MINGW64 & " & bashExecutable & " -cil 'export MOZ_WINDOWS_BOOTSTRAP=1 && cd """ & installPath & """ && wget -q https://hg.mozilla.org/mozilla-central/raw-file/default/python/mozboot/bin/bootstrap.py -O /tmp/bootstrap.py && python /tmp/bootstrap.py'", 1, true)
  96. If errorCode <> 0 Then
  97. MsgBox("Bootstrap failed. Make sure you have internet access. If you think this is a bug, please file one in Bugzilla https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=Build%20Config")
  98. WScript.Quit 1
  99. End If