-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.bat
More file actions
606 lines (564 loc) · 22.9 KB
/
Copy pathsetup.bat
File metadata and controls
606 lines (564 loc) · 22.9 KB
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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
@echo off
setlocal enabledelayedexpansion
for %%i in ("%~dp0.") do SET "script_dir=%%~fi"
cd /d "%script_dir%" || echo "unable to cd to '%script_dir%'"&& exit /b 1
set "bc=%script_dir%\batcolors"
call "%bc%\echos_macros.bat"
%_info% "script_dir='%script_dir%', batdir='%batdir%'"
set "senv_dir=%script_dir%"
if not exist "%senv_dir%\..\setup" (
mkdir "%senv_dir%\..\setup"
if errorlevel 1 (
%_fatal% "Unable to create setup folder at '%senv_dir%/../setup'" 3
)
)
if not exist "%senv_dir%\..\dl" (
%_task% "Must create dl junction '%senv_dir%\..\dl' to '%USERPROFILE%\Downloads'"
mklink /J "%senv_dir%\..\dl" "%USERPROFILE%\Downloads"
if errorlevel 1 (
%_fatal% "Unable to create dl junction at '%senv_dir%/../dl' to '%USERPROFILE%\Downloads'" 5
)
%_ok% "dl junction '%senv_dir%\..\dl' created, linked to '%USERPROFILE%\Downloads'"
)
cd "%senv_dir%\..\setup"
if errorlevel 1 ( %_fatal% "Unable to access setup folder at '%senv_dir%/../setup'" 3 )
for /F "delims=" %%f in ('cd') do ( set setup_dir=%%f)
cd /d "%script_dir%"
if errorlevel 1 ( %_fatal% "unable to cd again to '%script_dir%'" 2 )
set profile=
set profil=
set script_dir_bin=
set setupsdir=
set setupsdirbat=
set "prgtoinstall=%~1"
set instlist="install.list"
if /i "%prgtoinstall:~0,1%"=="_" (
set profile=!prgtoinstall:~1!
set instlist=install_!profile!.list
set "prgtoinstall=%~2"
) else (
if exist "%script_dir%\custom\profile" (
for /f "delims=" %%x in (%script_dir%\custom\profile) do set profile=%%x
)
set instlist=install_!profile!.list
)
%_info% "profile='%profile%', instlist='%instlist%' prgtoinstall='%prgtoinstall%'"
if not exist custom\%instlist% (
%_fatal% "Installation instlist '%instlist%' does not exist in '%script_dir%\custom" 1
)
rem echo "prgtoinstall='%prgtoinstall%'"
rem cd setups
rem if errorlevel 1 %_fatal% "fatal!" && echo "nope." && exit /b 1
rem %_ok% "ok..."
rem goto:eof
REM https://stackoverflow.com/questions/132799/how-can-i-echo-a-newline-in-a-batch-file
set NLM=^
set NL=^^^%NLM%%NLM%^%NLM%%NLM%
if not exist custom (
mkdir custom
copy custom_example\* custom
)
if not "%HOME%"=="" (
if not "%PRGS%"=="" (
if not "%PROG%"=="" (
set senv_noconfirm=1
where grep >nul 2>&1
if "!ERRORLEVEL!"=="0" (
call check_migrate_home
)
)
)
)
if not exist custom\setup.ini.bat (
echo @echo off%NL%set PRGS=%NL%set HOME=%NL%> custom\setup.ini.bat
%_fatal% "Fill out first %script_dir%\custom\setup.ini.bat (PRGS, HOME, PROG)" 1
)
%_info% "senv_noconfirm='%senv_noconfirm%' '!senv_noconfirm!'"
call custom\setup.ini.bat
if errorlevel 1 %_fatal% "custom/setup.ini.bat error" 2
if "%PRGS%"=="" ( %_fatal% "PRGS (installation folder) must be defined in custom/setup.ini.bat" && exit /b 1 )
if "%HOME%"=="" ( %_fatal% "HOME must be defined in custom/setup.ini.bat" && exit /b 1 )
if "%PROG%"=="" ( %_fatal% "PROG (installation folder) must be defined in custom/setup.ini.bat" && exit /b 1 )
if "%REMOTE_HOME%"=="" ( %_fatal% "REMOTE_HOME (installation folder) must be defined in custom/setup.ini.bat" && exit /b 1 )
powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "$PSModuleAutoloadingPreference = 'None'; Import-Module Microsoft.PowerShell.Management; $templatePath = '%script_dir%\senv.user_profile.tpl.bat'; $targetPath = '%USERPROFILE%\senv.bat'; $content = Get-Content -LiteralPath $templatePath -Raw; [System.IO.File]::WriteAllText($targetPath, $content.Replace('_HOME_', '%HOME%'), [System.Text.UTF8Encoding]::new($false))"
if errorlevel 1 (
%_fatal% "Unable to write '%USERPROFILE%\senv.bat' from '%script_dir%\senv.user_profile.tpl.bat'" 24
)
echo @echo off%NL%call %HOME%\bin\gsenv.bat> "%USERPROFILE%\gsenv.bat"
echo @echo off%NL%call "%%USERPROFILE%%\senv.bat"> "%HOME%\senv.bat"
echo @echo off%NL%call "%%USERPROFILE%%\gsenv.bat"> "%HOME%\gsenv.bat"
REM useful when HOMEDRIVE is U: or other than C:
if not "%HOMEDRIVE%"=="C:" (
echo @echo off%NL%call "%%USERPROFILE%%\senv.bat"> "%HOMEDRIVE%\senv.bat"
echo @echo off%NL%call "%%USERPROFILE%%\gsenv.bat"> "%HOMEDRIVE%\gsenv.bat"
)
doskey senv=
%_info% "PRGS='%PRGS%'"
%_info% "HOME='%HOME%'"
%_info% "PROG='%PROG%'"
if not exist "%HOME%\bin" (
mkdir "%HOME%\bin"
)
%_task% "Must copy script_dir\bin '%script_dir%\bin\' to HOME\bin '%HOME%\bin'"
copy "%script_dir%\bin\*" "%HOME%\bin" 1>NUL:
if errorlevel 1 (
%_fatal% "Unable to copy '%script_dir%\bin\*' to '%HOME%\bin'" 231
)
%_ok% "script_dir\bin '%script_dir%\bin\' COPIED to HOME\bin '%HOME%\bin'"
%_task% "Must copy script_dir\custom\ custom-files '%script_dir%\custom\' to HOME\bin '%HOME%\bin'"
copy "%script_dir%\custom\*.custom.*" "%HOME%\bin" 1>NUL:
if errorlevel 1 (
%_fatal% "Unable to copy '%script_dir%\custom\*.custom.*' to '%HOME%\bin'" 231
)
%_ok% "'%script_dir%\custom\*.custom.*' COPIED to '%HOME%\bin'"
if not defined profile ( goto:skip_custom_cleanup)
%_task% "Must cleanup custom.[profile].[bat,doskey] files"
dir /B "%HOME%\bin\*.custom.*.bat" > "%script_dir%\setup_cleanup.tmp"
if errorlevel 1 (
%_fatal% "Unable to list custom bat files in %HOME%\bin" 51
)
dir /B "%HOME%\bin\*.custom.*.doskey" >> "%script_dir%\setup_cleanup.tmp"
if errorlevel 1 (
%_fatal% "Unable to list custom doskey files in %HOME%\bin" 52
)
findstr /R /V /C:".*custom\.%profile%\..*" /C:".*custom\.full\.%profile%\..*" "%script_dir%\setup_cleanup.tmp" > "%script_dir%\setup_cleanup_filtered.tmp"
if errorlevel 1 (
%_info% "No other profile than '%profile%' in '%script_dir%\setup_cleanup.tmp'"
)
for /f "delims=" %%a in ('type "%script_dir%\setup_cleanup_filtered.tmp"') do (
set "custom_file_to_delete=%%a"
rem echo Must delete '!custom_file_to_delete!'
del "%HOME%\bin\!custom_file_to_delete!"
if errorlevel 1 (
%_fatal% "Unable to delete custom file '!custom_file_to_delete!' in %HOME%\bin" 54
)
)
del "%script_dir%\setup_cleanup.tmp"
del "%script_dir%\setup_cleanup_filtered.tmp"
%_ok% "All custom file from different profiles than '%profile%' have been deleted from HOME\bin '%HOME%\bin'"
rem %_fatal% "stop for now" 22
:skip_custom_cleanup
if not exist "%HOME%\.config" ( mkdir "%HOME%\.config" )
if not exist "%HOME%\.config\git" ( mkdir "%HOME%\.config\git" )
if not exist "%HOME%\.config\git\config" ( copy "%script_dir%\.config.git.config" "%HOME%\.config\git\config" )
if exist "%script_dir%\custom\profile" (
%_task% "Copy/Update '%HOME%\bin\profile' with '%script_dir%\custom\profile'"
copy /Y "%script_dir%\custom\profile" "%HOME%\bin" 1>NUL:
if errorlevel 1 (
%_fatal% "Unable to copy '%script_dir%\custom\profile' to '%HOME%\bin'" 23
)
%_ok% "Profile custom aliases updated '%HOME%\bin\profile'"
)
if not exist "%script_dir%\custom\senv.custom.doskey" (
%_info% "No Custom alias file '%script_dir%\custom\senv.custom.doskey'"
) else (
%_task% "Copy/Update '%HOME%\bin\senv.custom.doskey' with '%script_dir%\custom\senv.custom.doskey'"
copy /Y "%script_dir%\custom\senv.custom.doskey" "%HOME%\bin" 1>NUL:
if errorlevel 1 (
%_fatal% "Unable to copy '%script_dir%\custom\senv.custom.doskey' to '%HOME%\bin'" 23
)
%_ok% "Profile custom aliases updated '%HOME%\bin\senv.custom.doskey'"
)
if not exist "%script_dir%\custom\senv.custom.%profile%.doskey" (
%_info% "No Custom alias file '%script_dir%\custom\senv.custom.%profile%.doskey'"
) else (
%_task% "Copy/Update '%HOME%\bin\senv.custom.%profile%.doskey' with '%script_dir%\custom\senv.custom.%profile%.doskey'"
copy /Y "%script_dir%\custom\senv.custom.%profile%.doskey" "%HOME%\bin" 1>NUL:
if errorlevel 1 (
%_fatal% "Unable to copy '%script_dir%\custom\senv.custom.%profile%.doskey' to '%HOME%\bin'" 23
)
%_ok% "Profile custom '%profile%' aliases updated '%HOME%\bin\senv.custom.%profile%.doskey'"
)
if not exist "%HOME%\bin\senv.local.bat" ( echo @echo off%NL%%NL%REM Custom settings go here> "%HOME%\bin\senv.local.bat")
if not exist "%HOME%\bin\senv.local.pre.bat" ( echo @echo off%NL%set "PRGS=%PRGS%"%NL%set "PROG=%PROG%"%NL%set "REMOTE_HOME=%REMOTE_HOME%"%NL%set "HOME=%HOME%"%NL%rem ---> "%HOME%\bin\senv.local.pre.bat" )
set "sslpb=%script_dir%\adm\custom\setup.senv.local.pre.bat"
if exist "%script_dir%\custom\setup.senv.local.pre.bat" ( set "sslpb=%script_dir%\custom\setup.senv.local.pre.bat" )
if not exist "%sslpb%" (
%_info% "No '%sslpb%' found"
) else (
%_info% "Call "%sslpb%"
call "%sslpb%"
)
if not exist "%HOME%\bin\senv.local.doskey" ( echo cdi=cd /d "%script_dir%"> "%HOME%\bin\senv.local.doskey" )
if not exist "%HOME%\bin\gsenv.local.bat" ( echo @echo off%NL%%NL%REM Custom gsenv settings go here> "%HOME%\bin\gsenv.local.bat")
if not exist "%HOME%\.gitconfig" ( copy "%script_dir%\.gitconfig" "%HOME%\.gitconfig" )
if not exist "%PROG%\git" ( mkdir "%PROG%\git" )
set "bc=%PROG%\git\batcolors"
if not exist "%PROG%\git\batcolors" ( mkdir "%bc%" )
if not exist "%bc%\echos_macros.bat" (copy "%script_dir%\batcolors\*" "%bc%" )
rem @echo on
set setupsdirbat="setupsdir.bat"
if not "%profile%"=="" (
set "setupsdirbat=setupsdir_%profile%.bat"
)
set "locald=%PROG%\senv_setups"
if "%setupsdir%"=="" (
if exist "%script_dir%\setups" (
set "setupsdir=%script_dir%\setups"
) else if exist "%script_dir%\custom\%setupsdirbat%" (
%_info% "call '%script_dir%\custom\%setupsdirbat%'"
call "%script_dir%\custom\%setupsdirbat%"
)
if "!setupsdir!"=="" (
%_fatal% "Define '%script_dir%\custom\%setupsdirbat%' with in it 'set setupsdir=/path/to/setups/archives'" && exit /b 1
)
)
%_info% "setupsdir='%setupsdir%'"
cd /d "%script_dir%"
if exist installs\python.install.bat (
%_task% "Must delete installs\python.install.bat in '%script_dir%'"
del installs\python.install.bat
if errorlevel 1 (
%_fatal% "Unable to delete installs\python.install.bat in '%script_dir%'" 165
)
%_ok% "installs\python.install.bat in '%script_dir%' deleted"
)
rem goto:alldone
findstr /i "peazips" "custom\%instlist%" >nul
if %errorlevel% equ 0 ( set "pattern=system" ) else ( set "pattern=peazip_portable-*" )
call:install "%pattern%" "peazips" || exit /b 1
set szdone="true"
cd /d "%script_dir%"
findstr /i "gits" "custom\%instlist%" >nul
if %errorlevel% equ 0 ( set "pattern=system" ) else ( set "pattern=PortableGit-*" )
call:install "%pattern%" "gits" || exit /b 1
if "%prgtoinstall%"=="" (
call:activate_git_path || exit /b 1
) else if /i "%prgtoinstall%"=="gits" (
call:activate_git_path || exit /b 1
) else if exist "%PRGS%\gits\current\bin\git.exe" (
call:activate_git_path || exit /b 1
)
if exist "%script_dir%\custom\senv.custom.full.%profile%.bat" (
%_info% "senv.custom.full.%profile%.bat present: sessions source it instead of senv.custom.bat"
)
cd /d "%script_dir%"
call:install "px-*" "pxs" || exit /b 1
if exist "%PRGS%\pxs\current\px.exe" (
call:activate_proxy_env || exit /b 1
)
call:install "VSCodeUserSetup-x64-*" "vscodes" "system-code" || exit /b 1
findstr /i "npps" "custom\%instlist%" >nul
if %errorlevel% equ 0 ( set "pattern=system" ) else ( set "pattern=npp.*.portable.x64.zip" )
call:install "%pattern%" "npps" || exit /b
call:install "gum_*_Windows_x86_64.zip" "gums" || exit /b 1
findstr /i "sysinternalsSuites" "custom\%instlist%" >nul
if %errorlevel% equ 0 ( set "pattern=system" ) else ( set "pattern=SysinternalsSuite-*.zip" )
call:install "%pattern%" "sysinternalsSuites" || exit /b 1
call:install "Microsoft.WindowsTerminal_*_x64.zip" "terminals" || exit /b 1
call:install "git-cliff-*-x86_64-pc-windows-msvc.zip" "git-cliffs" || exit /b 1
call:install "jq-*-win64.zip" "jqs" || exit /b 1
if not exist "%script_dir%\custom\%instlist%" (
goto:alldone
)
%_info% "=========="
%_info% "processing custom installation list '%instlist%'"
@echo off
for /f "tokens=1,2 delims= " %%a in ('type "%script_dir%\custom\%instlist%"') do (
set fnpl=%%a
set fl=%%b
set "cil_install=true"
if "!fl!"=="peazips" ( set "cil_install=false" )
if "!fl!"=="gits" ( set "cil_install=false" )
if "!fl!"=="vscodes" ( set "cil_install=false" )
if "!fl!"=="gums" ( set "cil_install=false" )
if "!fl!"=="pxs" ( set "cil_install=false" )
if "!fl!"=="sysinternalsSuites" ( set "cil_install=false" )
if "!fl!"=="npps" ( set "cil_install=false" )
if "!fl!"=="terminals" ( set "cil_install=false" )
if "!fl!"=="git-cliffs" ( set "cil_install=false" )
if "!fl!"=="jqs" ( set "cil_install=false" )
if "!cil_install!"=="true" (
call:install "!fnpl!" "!fl!" || exit /b 1
)
)
if not exist "%locald%\install.list" (
%_ok% "no local install list '%locald%\install.list', so no more list to process"
goto:alldone
)
set "setupsdir=%locald%\setups"
%_info% "=========="
%_info% "processing local installation list in '%locald%\install.list'"
for /f "tokens=1,2 delims= " %%a in ('type "%locald%\install.list"') do (
set fnpl=%%a
set fl=%%b
call:install "!fnpl!" "!fl!" || exit /b 1
)
:alldone
set "gcua_hosts_name="
if exist "%HOME%\bin\senv.custom.all_teams.gcua.list" ( set "gcua_hosts_name=senv.custom.all_teams.gcua.list" )
if not "%profile%"=="" if exist "%HOME%\bin\senv.custom.%profile%.gcua.list" ( set "gcua_hosts_name=senv.custom.%profile%.gcua.list" )
if defined gcua_hosts_name (
if exist "%PRGS%\gits\current\cmd\git.exe" (
%_task% "Must apply the team git identity, per %gcua_hosts_name%"
call "%HOME%\bin\gcua.bat"
if errorlevel 1 (
%_warning% "team git identity pass failed: run 'gcua' manually to diagnose"
) else (
%_ok% "team git identity pass done, per %gcua_hosts_name%"
)
)
)
set "gcua_hosts_name="
%_ok% "All done"
ENDLOCAL
for %%i in ("%~dp0.") do SET "script_dir=%%~fi"
cd /d "%script_dir%"
cd
call custom\setup.ini.bat "set"
set "err=%ERRORLEVEL%"
if not "%err%"=="0" (
%_fatal% "custom/setup.ini.bat still missing" %err%
)
echo HOME='%HOME%'
echo script_dir='%script_dir%'
rem set "script_dir=%cd%"
findstr /V "cdi= cdis=" "%HOME%\bin\senv.local.doskey" > "%script_dir%\tmp"
call "%script_dir%\bin\check_trailing_newline.bat" "%script_dir%\tmp"
if "%ERRORLEVEL%"=="2" ( echo.>> "%script_dir%\tmp" )
echo cdi=cd /d %script_dir%>> "%script_dir%\tmp"
for /f "delims=" %%x in (%script_dir%\custom\profile) do set profile=%%x
set "setupsdirbat=setupsdir_%profile%.bat"
call "%script_dir%\custom\%setupsdirbat%"
echo cdis=cd /d %setupsdir%>> "%script_dir%\tmp"
set "_sed="
if exist "%PRGS%\gits\current\usr\bin\sed.exe" (
set "_sed=%PRGS%\gits\current\usr\bin\sed.exe"
)
if defined _sed (
"%_sed%" -i "s/^\s\+[\r\n]*$//g" "%script_dir%\tmp"
)
rem sed writes LF endings: restore CRLF, or git flags senv.local.doskey
rem as modified against the eol=crlf attribute of the HOME repository
where unix2dos >NUL 2>NUL
if not errorlevel 1 ( unix2dos -q "%script_dir%\tmp" )
del "%HOME%\bin\senv.local.doskey"
move "%script_dir%\tmp" "%HOME%\bin\senv.local.doskey" >NUL
cd /d "%script_dir%"
rem del /F "%script_dir%\tmp" 2>NUL
set script_dir=
set profile=
set setupsdirbat=
set setupsdir=
echo calling senv.bat: You are good to go!
call "%HOME%\bin\senv.bat"
goto:eof
:install
set "p=%~1"
set "f=%~2"
set "sys=%~3"
if not "%prgtoinstall%"=="" (
if not "%prgtoinstall%"=="%f%" (
%_warning% "Skip '%f%' installation (for '%prgtoinstall%')"
rem @echo on
goto:eof
)
)
if "%p%"=="system" ( set "pname=system" && set "fname=" && goto:info )
rem echo Check path in setupsdir/p: '%setupsdir%'\'%p%'
set pname=
rem echo "p='%p%', f='%f%'"
rem http://steve-jansen.github.io/guides/windows-batch-scripting/part-2-variables.html
rem https://stackoverflow.com/questions/3215501/batch-remove-file-extension
if exist "%setupsdir%\%p%" (
for /F "usebackq" %%i in (`dir /OD /B "%setupsdir%\%p%"`) do set "fname=%%~nxi"&& set "pname=%%~ni"
)
rem echo fname='%fname%'
rem echo pname='%pname%'
if "%pname%"=="" (
if exist "%setupsdir%\_%f%" (
%_warning% "Skip '%f%' installation (test found) in '%setupsdir%\_%f%'"
goto:eof
)
%_warning% "No setup file found in '%setupsdir%' for '%f%', pattern '%p%'"
) else ( goto:info )
%_task% "Must check if '%f%', pattern '%p%' is in local setup dir '%setup_dir%'"
if exist "%setup_dir%\%p%" (
for /F "usebackq" %%i in (`dir /OD /B "%setup_dir%\%p%"`) do set "fname=%%~nxi"&& set "pname=%%~ni"
)
if "%pname%"=="" (
if exist "%setup_dir%\_%f%" (
%_warning% "Skip '%f%' installation (test found) in local '%setup_dir%\_%f%'"
goto:eof
)
%_fatal% "No setup file found in local '%setup_dir%' for '%f%', pattern '%p%'" 112
)
:info
%_info% "--------------"
%_info% "folder: '%f%': pattern '%pname%' system: '%sys%'"
%_info% "--------------"
set "sln="
if exist "%HOME%\.gitconfig" (
call "%script_dir%\installs\gits.config.utils.bat" :save_gitconfig Install '%f%': '%pname%'
)
set pre_ok=false
call :check_pre "%f%" "%fname%" "%pname%" || exit /b 1
%_info% "pname='%pname%', f='%f%', fname='%fname%' means sys='%sys%'"
if "%pre_ok%"=="true" (
call "%script_dir%\installs\check_symlink.bat" "%pname%" "%f%" "%sys%"
%_ok% "pre-check ok for %f%: nothing more to do"&& exit /b 0
)
set "tpath=%PRGS%\%f%\_%pname%"
if exist "%tpath%" (
%_ok% "Program '%pname%' already installed in '%PRGS%\%f%'"
call "%script_dir%\installs\check_symlink.bat" "%pname%" "%f%" "%sys%"
call:check_post "%f%" "!sln!" || exit /b 1
cd /d "%script_dir%"
goto:eof
)
set "tpath=%PRGS%\%f%\%pname%"
if exist "%tpath%" (
%_ok% "Program '%pname%' already installed2 in '%PRGS%\%f%', sln '%sys%'"
call "%script_dir%\installs\check_symlink.bat" "%pname%" "%f%" "%sys%"
call:check_post "%f%" "!sln!" || exit /b 1
cd /d "%script_dir%"
goto:eof
)
if not exist "%PRGS%\setup\" (
mkdir "%PRGS%\setup\"
)
if not exist "%PRGS%\setup\%fname%" (
%_info% "Copying '%fname%' from '%setupsdir%'"
(robocopy "%setupsdir%" "%PRGS%\setup" "%fname%" /Z /R:5 /W:5 /TBD /MT:16 /NJH /NJS) ^& IF %ERRORLEVEL% LSS 8 SET ERRORLEVEL = 0
if not "%ERRORLEVEL%"=="0" ( %_fatal% "Unable to copy '%setupsdir%\%fname%' to '%PRGS%\setup\'" && exit /b 1)
%_ok% "Setup '%fname%' copied locally"
)
set install_ok=false
call:check_install "%f%" "%fname%" "%pname%" || exit /b 1
if "%install_ok%"=="true" (
%_ok% "install ok for %f%: nothing more to do"&& exit /b 0
)
if "%install_ok%"=="check_symlink" (
call "%script_dir%\installs\check_symlink.bat" "%pname%" "%f%" "%sys%"
exit /b 0
)
if "%f%"=="vscodes" (
%_warning% "should not be here"&& exit /b 1
)
if not exist "%PRGS%\setup" ( mkdir "%PRGS%\setup")
if not exist "%PRGS%\%f%" ( mkdir "%PRGS%\%f%" )
if not "%pname:system=%"=="%pname%" (
goto:postinstall
)
rem https://stackoverflow.com/questions/17546016/how-can-you-zip-or-unzip-from-the-script-using-only-windows-built-in-capabiliti/26843122#26843122
rem powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('foo.zip', 'bar'); }"
if not exist "%PRGS%\peazips\current\res\7z\7z.exe" (
if "%szdone%"=="true" ( %fatal% "7z should be here" && exit /b 1 )
%_task% "Must uncompress with powershell '%fname%' to '%tpath%'"
rem https://stackoverflow.com/questions/33729801/returning-exit-code-from-a-batch-file-in-a-powershell-script-block#comment55261380_33730519
powershell.exe -nologo -noprofile -ExecutionPolicy UnRestricted; $var = "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('%PRGS%\setup\%fname%', '%tpath%'); $res=$?; Write-Host \"LASTEXITCODE='$res'\";if (-not $res) { return 1; }; return 0;}"; exit $var
if errorlevel 1 ( %_fatal% "Error on powershell uncompression"&& exit /b 1 )
%_ok% "'%fname%' uncompressed (powershell) to '%tpath%'"
call "%script_dir%\installs\check_symlink.bat" "%pname%" "%f%" "%sys%"
call:check_post "%f%" "!sln!" || exit /b 1
cd /d "%script_dir%"
goto:eof
)
set pz=%PRGS%\peazips\current
set sz=%pz%\res\7z\7z.exe
cd /d "%PRGS%\%f%"
%_task% "Must uncompress with 7z '%PRGS%\setup\%fname%' to '%tpath%'"
call "%HOME%\bin\pzxx.bat" "%PRGS%\setup\%fname%"
if errorlevel 1 (
rmdir /s /q "%tpath%"
%_fatal% "Error on 7z uncompression" 1
)
%_ok% "'%fname%' uncompressed (7z) to '%tpath%'"
:postinstall
call "%script_dir%\installs\check_symlink.bat" "%pname%" "%f%" "%sys%"
call:check_post "%f%" "!sln!" || exit /b 1
cd /d "%script_dir%"
goto:eof
:check_post
set "f=%~1"
set "sln=%~2"
if not defined sln (
%_fatal% "No symlink name defined for '%f%' check_post" 79
)
%_info% "check_post for '%f%' sln '%sln%'"
if exist "%script_dir%\installs\%f%.post.bat" (
call "%script_dir%\installs\%f%.post.bat" "%sln%" || exit /b 1
)
if /i "%f%"=="gits" (
call:activate_git_path || exit /b 1
)
if exist "%script_dir%\custom\%f%.post.bat" (
call "%script_dir%\custom\%f%.post.bat" "%sln%" || exit /b 1
)
if exist "%locald%\%f%.post.bat" (
call "%locald%\%f%.post.bat" "%sln%" || exit /b 1
)
goto:eof
:activate_git_path
if not defined PRGS (
%_fatal% "PRGS not defined: unable to activate Git PATH" 94
)
if not defined HOME (
%_fatal% "HOME not defined: unable to activate Git PATH" 95
)
set "GH=%PRGS%\gits\current"
if not exist "%GH%\bin\git.exe" (
%_fatal% "git.exe missing at '%GH%\bin': unable to activate Git PATH" 96
)
set "PATH=%HOME%\bin;%GH%\bin;%GH%\cmd;%GH%\usr\bin;%GH%\mingw64\bin;%GH%\mingw64\libexec\git-core;%PATH%"
where git >NUL 2>NUL
if errorlevel 1 (
%_fatal% "git.exe still not found on PATH after activating '%GH%'" 97
)
where awk >NUL 2>NUL
if errorlevel 1 (
%_fatal% "awk.exe still not found on PATH after activating '%GH%\usr\bin'" 98
)
%_ok% "Git PATH activated from '%GH%'"
goto:eof
:activate_proxy_env
if not defined HOME (
%_fatal% "HOME not defined: unable to activate proxy environment" 99
)
if not exist "%HOME%\bin\senv.custom.bat" (
%_fatal% "senv.custom.bat missing at '%HOME%\bin': unable to activate proxy environment" 100
)
call "%HOME%\bin\senv.custom.bat"
if not defined HTTP_PROXY (
%_fatal% "HTTP_PROXY not defined after calling '%HOME%\bin\senv.custom.bat'" 101
)
if not defined HTTPS_PROXY (
%_fatal% "HTTPS_PROXY not defined after calling '%HOME%\bin\senv.custom.bat'" 102
)
%_ok% "Proxy environment activated: HTTP_PROXY='%HTTP_PROXY%', HTTPS_PROXY='%HTTPS_PROXY%'"
goto:eof
:check_install
set "f=%~1"
set "fs=%~2"
set "pfs=%~3"
if exist "%script_dir%\installs\%f%.install.bat" (
call "%script_dir%\installs\%f%.install.bat" "%fs%" "%pfs%" || exit /b 1
)
if exist "%script_dir%\custom\%f%.install.bat" (
call "%script_dir%\custom\%f%.install.bat" "%fs%" "%pfs%" || exit /b 1
)
if exist "%locald%\%f%.install.bat" (
call "%locald%\%f%.install.bat" "%fs%" "%pfs%" || exit /b 1
)
goto:eof
:check_pre
set "f=%~1"
set "fs=%~2"
set "pfs=%~3"
if exist "%script_dir%\installs\%f%.pre.bat" (
call "%script_dir%\installs\%f%.pre.bat" "%fs%" "%pfs%" || exit /b 1
)
if exist "%script_dir%\custom\%f%.pre.bat" (
call "%script_dir%\custom\%f%.pre.bat" "%fs%" "%pfs%" || exit /b 1
)
if exist "%locald%\%f%.pre.bat" (
call "%locald%\%f%.pre.bat" "%fs%" "%pfs%" || exit /b 1
)
goto:eof
:call_echos_stack
if not defined ECHOS_STACK (
set "CURRENT_SCRIPT=%~nx0" & goto:eof
) else (
call "%batdir%\echos.bat" :stack %~nx0
)
goto:eof