forked from Gnucash/gnucash-on-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap_win_dev.vbs
511 lines (449 loc) · 19.2 KB
/
bootstrap_win_dev.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
' bootstap_win_dev.vbs
'
' The goal of this script is to simplify setting up a development
' environment to develop for GnuCash on Windows.
' It will set up an absolute minimal environment from where
' the regular GnuCash Windows build system can take over.
' This minimal environment consists of
' - mingw-get: the mingw package installer tool
' - msys-base: a basic MSYS shell environment
' - git for windows, required for:-
' - the GnuCash source code repository, cloned from the github GnuCash repository
'
' The bootstrap script can also be run on top of an existing set up
' in which case the script will only do what is necessary to get
' the above items in place. For example, if git is already installed
' in the location pointed to by GIT_DIR below, it won't be installed
' again.
'
' IN CASE OF UNEXPECTED CLOSING OF THE CONSOLE
' Please open a console (cmd.exe) and run the script under cscript.exe as follows:
' cscript.exe <path-to-this-script>
' This will keep your console open, so you can read if there were errors
' Script start
' ------------
' Ensure we have a visible console to display output
CheckStartMode
' This regexp is used to "Windoize" path names when this script is called
' from inside an msys environment (like from the build_tags.sh script)
' It should be a noop when the script is called from a pure Windows cmd prompt
Set myRegExp = New RegExp
myRegExp.Global = True
myRegExp.Pattern = "/"
' Parameters than can be overridden on the command line
' -----------------------------------------------------
' Everything will be installed in the base directory specified below.
' If this path doesn't suit you, you can specify another path as a named
' variable on the command line like so:
' bootstrap_win_dev.vbs /GLOBAL_DIR:c:\soft
' Note: avoid paths with spaces or other special characters (like &).
' these can confuse msys/mingw or some of the tools depending on them.
' Any of the parameters set up below can be overridden in this way.
If WScript.Arguments.Named.Exists("GLOBAL_DIR") Then
GLOBAL_DIR = myRegExp.Replace (WScript.Arguments.Named.Item("GLOBAL_DIR"), "\")
Else
GLOBAL_DIR = "c:\gcdev"
End If
If WScript.Arguments.Named.Exists("MINGW_DIR") Then
MINGW_DIR = myRegExp.Replace (WScript.Arguments.Named.Item("MINGW_DIR"), "\")
Else
MINGW_DIR = GLOBAL_DIR & "\mingw"
End If
If WScript.Arguments.Named.Exists("TMP_DIR") Then
TMP_DIR = myRegExp.Replace (WScript.Arguments.Named.Item("TMP_DIR"), "\")
Else
TMP_DIR= GLOBAL_DIR & "\tmp"
End If
If WScript.Arguments.Named.Exists("DOWNLOAD_DIR") Then
DOWNLOAD_DIR = myRegExp.Replace (WScript.Arguments.Named.Item("DOWNLOAD_DIR"), "\")
Else
DOWNLOAD_DIR= GLOBAL_DIR & "\downloads"
End If
If WScript.Arguments.Named.Exists("GIT_PKG") Then
GIT_PKG = WScript.Arguments.Named.Item("GIT_PKG")
Else
GIT_PKG = "Git-1.9.4-preview20140611"
End If
If WScript.Arguments.Named.Exists("strGitBaseUrl") Then
strGitBaseUrl = WScript.Arguments.Named.Item("strGitBaseUrl")
Else
strGitBaseUrl = "https://github.com/msysgit/msysgit/releases/download/"
End If
If WScript.Arguments.Named.Exists("GIT_URL") Then
GIT_URL = WScript.Arguments.Named.Item("GIT_URL")
Else
GIT_URL = strGitBaseUrl & GIT_PKG & "/" & GIT_PKG & ".exe"
End If
If WScript.Arguments.Named.Exists("GIT_DIR") Then
GIT_DIR = myRegExp.Replace (WScript.Arguments.Named.Item("GIT_DIR"), "\")
Else
GIT_DIR = GLOBAL_DIR & "\git-1.9.4"
End If
If WScript.Arguments.Named.Exists("GC_WIN_REPOS_URL") Then
GC_WIN_REPOS_URL = WScript.Arguments.Named.Item("GC_WIN_REPOS_URL")
Else
GC_WIN_REPOS_URL = "git://github.com/Gnucash/gnucash-on-windows.git"
End If
If WScript.Arguments.Named.Exists("GC_WIN_REPOS_DIR") Then
GC_WIN_REPOS_DIR = myRegExp.Replace (WScript.Arguments.Named.Item("GC_WIN_REPOS_DIR"), "\")
Else
GC_WIN_REPOS_DIR = GLOBAL_DIR & "\gnucash-on-windows.git"
End If
If WScript.Arguments.Named.Exists("REPOS_URL") Then
REPOS_URL = WScript.Arguments.Named.Item("REPOS_URL")
Else
REPOS_URL = "git://github.com/Gnucash/gnucash.git"
End If
If WScript.Arguments.Named.Exists("REPOS_DIR") Then
REPOS_DIR = myRegExp.Replace (WScript.Arguments.Named.Item("REPOS_DIR"), "\")
Else
REPOS_DIR = GLOBAL_DIR & "\gnucash.git"
End If
' If you want the script to run without prompting the user,
' add the /silent:yes switch to the command line
' It will still print output though to help in locating errors
silent = False
If WScript.Arguments.Named.Exists("silent") Then
silent = True
End If
' Parameters that can't/shouldn't be overridden
'----------------------------------------------
' Global parameters for visual basic
Set objFso = CreateObject("Scripting.FileSystemObject")
Set stdout = objFso.GetStandardStream(1)
Set stdin = objFso.GetStandardStream(0)
Set objWsh = WScript.CreateObject ("WScript.Shell")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Welcome
' Create base directories if necessary
' ------------------------------------
If Not objFso.FolderExists(GLOBAL_DIR) Then
stdout.Write "Creating " & GLOBAL_DIR & "... "
objFso.CreateFolder(GLOBAL_DIR)
stdout.WriteLine "Ok"
End If
If Not objFso.FolderExists(MINGW_DIR) Then
stdout.Write "Creating " & MINGW_DIR & "... "
objFso.CreateFolder(MINGW_DIR)
stdout.WriteLine "Ok"
End If
If Not objFso.FolderExists(TMP_DIR) Then
stdout.Write "Creating " & TMP_DIR & "... "
objFso.CreateFolder(TMP_DIR)
stdout.WriteLine "Ok"
End If
If Not objFso.FolderExists(DOWNLOAD_DIR) Then
stdout.Write "Creating " & DOWNLOAD_DIR & "... "
objFso.CreateFolder(DOWNLOAD_DIR)
stdout.WriteLine "Ok"
End If
' Install mingw-get
' -----------------
strMingwGet = MINGW_DIR & "\bin\mingw-get.exe"
stdout.Write "Checking " & strMingwGet & "... "
If objFso.FileExists(strMingwGet) Then
stdout.WriteLine "Found, no need to install"
Else
stdout.WriteLine "Not found, will be installed"
strMingwGetZip = DOWNLOAD_DIR & "\mingw-get.zip"
If Not objFso.FileExists(strMingwGetZip) Then
stdout.Write "Downloading mingw-get.zip (slow!)... "
strMingwGetZipUrl = "https://github.com/Gnucash/gnucash-on-windows/raw/master/mingw-get.zip"
HTTPDownload strMingwGetZipUrl, strMingwGetZip
stdout.WriteLine "Success"
End If
' Extract mingw-get.zip into our MINGW_DIR
' using a detour via a temporary directory to deal with the
' cludgy way to detect when extracting is finished.
' I couldn't find a better way so far.
stdout.Write "Installing mingw-get... "
strMingwTmpDir = TMP_DIR & "\mingwtmp"
If objFso.FolderExists(strMingwTmpDir) Then
objFso.DeleteFolder strMingwTmpDir , True
End If
ExtractAll DOWNLOAD_DIR & "\mingw-get.zip", strMingwTmpDir
objFso.CopyFolder strMingwTmpDir & "\*", MINGW_DIR, True
objFso.DeleteFolder strMingwTmpDir , True
' Create a default profile for mingw-get to avoid constant warnings
objFso.CopyFile MINGW_DIR & "\var\lib\mingw-get\data\defaults.xml", MINGW_DIR & "\var\lib\mingw-get\data\profile.xml"
stdout.WriteLine "Success"
End If
' Instal Basic Msys (we need msys-wget to install git)
' ----------------------------------------------------
' Note: we don't check if these are installed already.
' mingw-get will do this for us automatically.
stdout.Write "Installing msys and wget... "
strMingwGet = MINGW_DIR & "\bin\mingw-get.exe"
objWsh.Run strMingwGet & " install mingw-get msys-base msys-wget msys-patch", 1, True
'Set objExec = objWsh.Exec (strMingwGet & " install msys-base msys-wget")
strWget = MINGW_DIR & "\msys\1.0\bin\wget.exe"
If Not objFso.FileExists(strWget) Then
stdout.WriteLine "Failed"
stdout.WriteBlankLines (1)
stdout.WriteLine "*** ERROR ***"
stdout.WriteLine "Msys/Wget installation failed."
stdout.WriteBlankLines (1)
stdout.WriteLine "Cannot continue until this has been resolved."
AbortScript
End If
stdout.WriteLine "Success"
' Install Git
' -----------
strGit = GIT_DIR & "\bin\git.exe"
stdout.Write "Checking " & strGit & "... "
If objFso.FileExists(strGit) Then
stdout.WriteLine "Found, no need to install"
Else
stdout.WriteLine "Not found, will be installed"
strGitPkg = DOWNLOAD_DIR & "\" & GIT_PKG & ".exe"
If Not objFso.FileExists(strGitPkg) Then
stdout.Write "Downloading git installer... "
objWsh.Run strWget & " -O" & strGitPkg & " --no-check-certificate " & GIT_URL, 1, true
If Not objFso.FileExists(strGitPkg) Then
stdout.WriteLine "Failed"
stdout.WriteBlankLines (1)
stdout.WriteLine "*** ERROR ***"
stdout.WriteLine "Download git installer failed."
stdout.WriteBlankLines (1)
stdout.WriteLine "Cannot continue until this has been resolved."
AbortScript
End If
stdout.WriteLine "Success"
End If
stdout.Write "Installing git... "
objWsh.Run strGitPkg & " /SP- /SILENT /DIR=" & GIT_DIR, 1, true
If Not objFso.FileExists(strGit) Then
stdout.WriteLine "Failed"
stdout.WriteBlankLines (1)
stdout.WriteLine "*** ERROR ***"
stdout.WriteLine "Git installation failed."
stdout.WriteBlankLines (1)
stdout.WriteLine "Cannot continue until this has been resolved."
AbortScript
End If
stdout.WriteLine "Sucess"
End If
' Set up gnucash-on-windows git repository
' ----------------------------------------
strBootstrap = GC_WIN_REPOS_DIR & "\bootstrap_win_dev.vbs"
stdout.WriteLine "Checking if " & GC_WIN_REPOS_DIR
stdout.Write " is a gnucash-on-windows git repository... "
If objFso.FolderExists(GC_WIN_REPOS_DIR & "\.git") And objFso.FileExists(strBootstrap) Then
stdout.WriteLine "Most likely ok, won't clone"
Else
stdout.WriteLine "Not found"
stdout.WriteLine "Set up gnucash-on-windows git repository... "
objWsh.Run strGit & " clone " & GC_WIN_REPOS_URL & " " & GC_WIN_REPOS_DIR, 1, true
If Not objFso.FileExists(strBootstrap) Then
stdout.WriteLine "Failed"
stdout.WriteBlankLines (1)
stdout.WriteLine "*** ERROR ***"
stdout.WriteLine "Failed to set up gnucash-on-windows git repository."
stdout.WriteBlankLines (1)
stdout.WriteLine "Cannot continue until this has been resolved."
AbortScript
End If
stdout.WriteLine "Ok"
End If
' Set up gnucash git repository
' -----------------------------
strGCbin = REPOS_DIR & "\src\bin\gnucash-bin.c"
stdout.WriteLine "Checking if " & REPOS_DIR
stdout.Write " is a GnuCash git repository... "
If objFso.FolderExists(REPOS_DIR & "\.git") And objFso.FileExists(strGCbin) Then
stdout.WriteLine "Most likely ok, won't clone"
Else
stdout.WriteLine "Not found"
stdout.WriteLine "Set up GnuCash git repository... "
objWsh.Run strGit & " clone " & REPOS_URL & " " & REPOS_DIR, 1, true
If Not objFso.FileExists(strGCbin) Then
stdout.WriteLine "Failed"
stdout.WriteBlankLines (1)
stdout.WriteLine "*** ERROR ***"
stdout.WriteLine "Failed to set up GnuCash git repository."
stdout.WriteBlankLines (1)
stdout.WriteLine "Cannot continue until this has been resolved."
AbortScript
End If
stdout.WriteLine "Ok"
End If
' Create custom.sh
' ----------------
strCustomSh = GC_WIN_REPOS_DIR & "\custom.sh"
bExistingCustomSh = False
If objFso.FileExists(strCustomSh) Then
stdout.WriteLine "Found existing custom.sh file"
bExistingCustomSh = True
Else
' Create a custom.sh file that matches the parameters set at the beginning of this script
' This ensures install.sh will find the development environment we set up
' Note: we're deliberately not storing versions of used components in the autogenerated custom.sh
' This allows install.sh to update to newer versions if deemed useful
stdout.Write "Autogenerating custom.sh file... "
Set myRegExp = New RegExp
myRegExp.Global = True
myRegExp.Pattern = "\\"
strGlobalDir = myRegExp.Replace (GLOBAL_DIR, "\\")
strMingwDir = myRegExp.Replace (MINGW_DIR, "\\")
strMsysDir = myRegExp.Replace (MINGW_DIR & "\msys\1.0", "\\")
strTmpDir = myRegExp.Replace (TMP_DIR, "\\")
strDownloadDir = myRegExp.Replace (DOWNLOAD_DIR, "\\")
strGitDir = myRegExp.Replace (GIT_DIR, "\\")
strGCWinReposDir = myRegExp.Replace (GC_WIN_REPOS_DIR, "\\")
strReposDir = myRegExp.Replace (REPOS_DIR, "\\")
Set objCustomSh = objFso.OpenTextFile( strCustomSh, ForWriting, True )
objCustomSh.WriteLine "# custom.sh, automatically created by bootstrap_win_dev.vbs"
objCustomSh.WriteLine "#"
objCustomSh.WriteLine "# The parameters set here match the parameters used by"
objCustomSh.WriteLine "# bootstrap_win_dev.vbs to set up the GnuCash development"
objCustomSh.WriteLine "# environment and should ensure the install.sh works out"
objCustomSh.WriteLine "# of the box."
objCustomSh.WriteLine "#"
objCustomSh.WriteLine "# You are free to modify these parameters to suit you,"
objCustomSh.WriteLine "# but keep in mind that if you ever want to run"
objCustomSh.WriteLine "# bootstrap_win_dev.vbs again you should make sure"
objCustomSh.WriteLine "# the parameters it uses match the ones you set here."
objCustomSh.WriteBlankLines 1
objCustomSh.WriteLine "GLOBAL_DIR=" & strGlobalDir
objCustomSh.WriteLine "MINGW_DIR=" & strMingwDir
objCustomSh.WriteLine "MSYS_DIR=" & strMsysDir
objCustomSh.WriteLine "TMP_DIR=" & strTmpDir
objCustomSh.WriteLine "DOWNLOAD_DIR=" & strDownloadDir
objCustomSh.WriteLine "GIT_DIR=" & strGitDir
objCustomSh.WriteLine "REPOS_TYPE=git" ' Bootstrap only works with a git repo
objCustomSh.WriteLine "GC_WIN_REPOS_URL=" & GC_WIN_REPOS_URL
objCustomSh.WriteLine "GC_WIN_REPOS_DIR=" & strGCWinReposDir
objCustomSh.WriteLine "REPOS_URL=" & REPOS_URL
objCustomSh.WriteLine "REPOS_DIR=" & strReposDir
objCustomSh.Close
stdout.WriteLine "Success"
End If
' End message
' -----------
stdout.WriteBlankLines 1
stdout.WriteLine "Bootstrap completed successfully !"
stdout.WriteBlankLines 1
stdout.WriteLine "You can now continue as follows"
stdout.WriteLine "- Use git to checkout the desired branch/tag in " & REPOS_DIR
stdout.WriteLine "- Open the msys shell"
stdout.WriteLine "- cd " & GC_WIN_REPOS_DIR
stdout.WriteLine "- Properly configure a custom.sh"
stdout.WriteLine " (if you changed any default path in the bootstrap script)"
stdout.WriteLine "- Run install.sh"
stdout.WriteBlankLines 1
stdout.WriteLine "Happy hacking !"
AbortScript
' Functions used in the script
' ----------------------------
' Initial message to user
Sub Welcome
If silent then
' Don't interact with user if in silent mode
stdout.WriteLine "Skipping intro because silent mode was set"
Exit Sub
End If
stdout.WriteLine "Boostrap GnuCash Development on Windows"
stdout.WriteLine "---------------------------------------"
stdout.WriteLine "This script is intended for people that wish to develop GnuCash on Windows"
stdout.WriteLine "It will download and install the minimal set of tools"
stdout.WriteLine "to run a first build of the GnuCash sources."
stdout.WriteLine "It will install"
stdout.WriteLine "- mingw-get, an msys shell and wget in " & MINGW_DIR
stdout.WriteLine "- git in " & GIT_DIR
stdout.WriteLine "- a gnucash-on-windows git repository cloned from"
stdout.WriteLine " " & GC_WIN_REPOS_URL
stdout.WriteLine " into " & GC_WIN_REPOS_DIR
stdout.WriteLine "- a GnuCash git repository cloned from"
stdout.WriteLine " " & REPOS_URL
stdout.WriteLine " into " & REPOS_DIR
stdout.WriteBlankLines 1
stdout.WriteLine "Notes:"
stdout.WriteLine "* Components already found in the given locations"
stdout.WriteLine " won't be touched. Instead the available versions"
stdout.WriteLine " will be used in that case."
stdout.WriteLine "* If the proposed locations don't suit you, you can"
stdout.WriteLine " pass alternate locations as named parameters to this script."
stdout.WriteLine " For example to use c:\soft as base directory you can run this script as"
stdout.WriteLine " bootstrap_win_dev.vbs /GLOBAL_DIR:c:\soft"
stdout.WriteLine " Which parameters you can modify can be found near the beginning of this script."
stdout.WriteBlankLines 1
stdout.Write "Continue with the set up (Y/N) ? "
chRead = stdin.ReadLine
If Not (UCase(Left(chRead,1)) = "Y") Then
stdout.WriteLine "Installation interrupted."
AbortScript
End If
End Sub
' Download a file over http
Sub HTTPDownload( myURL, myPath )
' This Sub downloads the FILE specified in myURL to the path specified in myPath.
'
' myURL must always end with a file name
' myPath may be a directory or a file name; in either case the directory must exist
'
' Based on a script written by Rob van der Woude
' http://www.robvanderwoude.com
' Standard housekeeping
Dim i, objFile, objHTTP, strFile, strMsg
' Check if the specified target file or folder exists,
' and build the fully qualified path of the target file
If objFso.FolderExists( myPath ) Then
strFile = objFso.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) )
ElseIf objFso.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then
strFile = myPath
Else
stdout.WriteLine "ERROR: Target folder not found."
AbortScript
End If
' Create or open the target file
Set objFile = objFso.OpenTextFile( strFile, ForWriting, True )
' Create an HTTP object
Set objHTTP = CreateObject( "MSXML2.ServerXMLHTTP" )
' Download the specified URL
objHTTP.Open "GET", myURL, False
objHTTP.Send
' Write the downloaded byte stream to the target file
For i = 1 To LenB( objHTTP.ResponseBody )
objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
Next
' Close the target file
objFile.Close( )
End Sub
' Extract a zip file strZipFile into strFolder
Function ExtractAll(strZipFile, strFolder)
Set objShell = CreateObject("Shell.Application")
If Not objFso.FolderExists(strFolder) Then
objFso.CreateFolder(strFolder)
End If
intCount = objShell.NameSpace(strFolder).Items.Count
Set colItems = objShell.NameSpace(strZipFile).Items
objShell.NameSpace(strFolder).CopyHere colItems, 256
Do Until objShell.NameSpace(strFolder).Items.Count = intCount + colItems.Count
WScript.Sleep 200
Loop
End Function
' Make sure we run in a console (so output is visible)
' Based on a code snipped found here
' http://ask.metafilter.com/79481/vbscript-printing-to-command-line
Sub CheckStartMode
' Returns the running executable as upper case from the last \ symbol
strStartExe = UCase( Mid( wscript.fullname, instrRev(wscript.fullname, "\") + 1 ) )
If Not strStartExe = "CSCRIPT.EXE" Then
' This wasn't launched with cscript.exe, so relaunch using cscript.exe explicitly!
' wscript.scriptfullname is the full path to the actual script
set oSh = CreateObject("wscript.shell")
oSh.Run "cscript.exe """ & wscript.scriptfullname & """"
wscript.quit
End If
End Sub
' Abort the script
Sub AbortScript
If silent then
' Don't interact with user if in silent mode
Exit Sub
End If
stdout.WriteBlankLines 1
stdout.Write "Pres enter to continue... "
chRead = stdin.Read (1)
WScript.Quit
End Sub