-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.ps1
1954 lines (1675 loc) · 89 KB
/
bootstrap.ps1
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
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
param (
[switch]$h = $false,
[switch]$help = $false,
[switch]$run = $false,
[switch]$conemu = $false,
[switch]$nopackages = $false,
[switch]$mingw = $false,
[switch]$ucrt = $false,
[switch]$clang = $false,
[switch]$nopython = $false,
[switch]$nopythonupdate = $false,
[switch]$nopythonpackages = $false,
[switch]$pythonuselatest = $false,
[string]$python,
[switch]$nojava = $false,
[string]$java = "21.35",
[switch]$nolangtool = $false,
[switch]$nosumatrapdf = $false,
[string]$sumatrapdf,
[switch]$nopandoc = $false,
[switch]$noplantuml = $false,
[switch]$uninstall = $false,
[switch]$force = $false,
[string]$psimacsbranch = "master",
[switch]$noprivatefile = $false,
[switch]$nopsimacsdocu = $false,
[string]$username = "YOUR NAME",
[string]$useremail = "YOUR EMAIL",
[string]$calendarlatitude = "0.0",
[string]$calendarlongitude = "0.0",
[string]$calendarlocation = "YOUR CITY, COUNTRY",
[switch]$nopackageversions = $false,
[switch]$nofontsinstall = $false,
[switch]$allnerdfonts = $false,
[switch]$noalltheicons = $false,
[switch]$nonerdicons = $false,
[switch]$noorgthemes = $false,
[switch]$nocontent = $false,
[switch]$nonpm = $false
)
if (-not $run)
{
$help = $true
}
if ($help -or $h)
{
echo "Usage: bootstrap.ps1 [options]"
echo ""
echo "This is the Psimacs bootstrap powershell script. Psimacs is special configuration"
echo "of Emacs for working on Microsoft Windows."
echo "environment."
echo "Psimacs uses the MSYS2 Emacs. All tools that are used for development are installed"
echo "by this bootstrap script. That is a lot of stuff and it takes at least 22 GByte of"
echo "free disk space on your 'HOME' directory. It does all its installation in the 'psimacs'"
echo "subfolder of the 'HOME'directory."
echo ""
echo "The following set of tools gets installed by this script:"
echo ""
echo " ConEmu : An optional terminal for windows. See option '-conemu'."
echo " Java : Java is needed for 'LanguageTool' and for 'PlantUML'. See options '-nojava' and '-java'."
echo " LanguageTool : This is a multi-lingual grammer and spell checker. See option 'nolangtool'."
echo " Msys2 : Unix environment for Windows. This is the backbone of the installation."
echo " You can install either MINGW64, UCRT64 or CLANG64 environments. Howerver, currently"
echo " only the MINGW64 environment works without hassle."
echo " See options '-mingw', '-ucrt', '-clang', or '-nopackages'."
echo " Pandoc : Pandoc is a universal document converter. See option '-nopandoc'."
echo " plantUML : PlantUML is a UML and diagram drawing tool. See option '-noplantuml'."
echo " Psimacs : This is the actual Psimacs Emacs configuration. The central peace of code."
echo " Python : Psimacs builds around of Windows Python instead of the MSYS2 Python version."
echo " Many tools are not compatible to the MSYS2 Python version."
echo " The bootstrapping operation installs the latest Python version and setup"
echo " a virtual Python environment into which many Python packages gets installed."
echo " The list of these packages can be found in the 'Requirements.txt' file found"
echo " Psimacs assets Python subdirectory."
echo " See options '-nopython', '-nopythonupdate', '-nopythonpackages', and '-python'."
echo " SumatraPDF : Psimacs uses the SumatryPDF viewer. See options 'nosumatrapdf' and 'sumatrapdf'."
echo " Ghostscript : Ghostscript is an interpreter for the PostScript® language and PDF files. Installed via MSYS2."
echo " GraphViz : GraphViz is graph visualization software. Installed via MSYS2."
echo " Cmake : Cmake is the de-facto standard for building C++. Installed via MSYS2."
echo " Doxygen : Doxygen is a documentation generator from source code. Installed via MSYS2."
echo " Hugo : Hugo is the world's fastest framework for building websites. Installed via MSYS2."
echo " Hunspell : Hunspell is a popular spell checking tool. Installed via MSYS2."
echo " ASpell : ASpell is another popular spell checking tool. Installed via MSYS2."
echo " 7zip : 7-Zip is a file archiver with a high compression ratio.Installed via MSYS2."
echo " AStyle : Artistic Style is a source code indenter, formatter, and beautifier for the C++"
echo " programming language. Installed via MSYS2."
echo " ripgrep : Ripgrep is a line-oriented search tool that recursively searches the current"
echo " directory for a regex pattern. Installed via MSYS2."
echo " SciTE : SciTE is an editor with facilities for building and running programs. Installed via MSYS2."
echo " fd : This is a simple, fast and user-friendly alternative to find. Installed via MSYS2."
echo " nerd-fonts : Iconic font aggregator, collection, and patcher. Psimacs uses the Hack fonts. Installed via MSYS2."
echo " texlive : Provides a comprehensive full TeX system. Installed via MSYS2."
echo " Gcc : The Gnu Compiler Collection. Installed via MSYS2."
echo " Clang : The Clang compiler. Installed via MSYS2."
echo ""
echo "Attention: This script does not perform any task withoud specification of the '-run' option!"
echo ""
echo "Important:"
echo " 1) A Git installation is expected to exists on the target machine."
echo " 2) Remove the MAX_PATH Limitation"
echo " Windows historically has limited path lengths to 260 characters."
echo " This meant that paths longer than this would not resolve and errors"
echo " would result."
echo " This limitation can be expanded to approximately 32,000 characters."
echo " Your administrator will need to activate the 'Enable Win32 long paths'"
echo " group policy, or set 'LongPathsEnabled' to 1 in the registry key"
echo " HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem."
echo ""
echo "Additionally, the script allows the complete deinstallation of the Psimacs envrironment. Python gets deinstalled"
echo "properly and the virtual Python environment as well as Psimacs itself are only removed on special request with the"
echo "'-force' option."
echo ""
echo "Options:"
echo " -h, -help : Show this help."
echo " -run : This script does nothing without setting the -run option!"
echo " MSYS2"
echo " -mingw : Install the MINGW64 MSYS2 environment. Recommended and the current default."
echo " -ucrt : Install the UCRT64 MSYS2 environment. The future, but but fails on Emacs's zmq package needed for jupyter."
echo " -clang : Install the CLANG64 MSYS2 environment. Same as UCRT64 environment."
echo " -nopackages : Do not install any MSYS2 packages. Mainly for development purpose."
echo " -allnerdfonts : Install all available nerd fonts. Otherwise only firacode, hack, and inconsolata nerd fonts gets installed."
echo " -nonpm : Do not install the Node.js package, providing command npm."
echo " -conemu : Additionally install the ConEmu terminal."
echo " Python"
echo " -nopython : Do not install Python."
echo " -pythonuselatest : Use the latest python version. Otherwise the version Python 3.11.5 is currently used."
echo " The latest Python version might not work. Not all package wheels are already available."
echo " -nopythonupdate : If Python is already installed, this options allows the suppression of Python updates."
echo " -nopythonpackages : Do not install the the Psimacs defined Python package requirements."
echo " -python : The Python version number in the format 'N.M.B' that should be installed. Default is latest"
echo " if flage 'pythonuselatest' is defined. Otherwise the Python 3.11.5 is currently used."
echo " Java"
echo " -nojava : Do not install OpenJDK JDK."
echo " -java : The Java version number and the revision: 'N.M'"
echo " Tools"
echo " -nolangtool : Do not install LangTool spell and grammar checker."
echo " -nosumatrapdf : Do not install the SumatraPDF viewer."
echo " -sumatrapdf : The SumatraPDF viewer version number in the format 'N.M.B' that should be installed. Default is latest."
echo " -nopandoc : Do not install the Pandoc document converter."
echo " -noplantuml : Do not install the PlantUML tool."
echo " Psimacs"
echo " -psimacsbranch : The specific branch, tag or commit to clone. Currently this is defaulted to branch"
echo " 'master' which is the Emacs 29 current branch of Psimacs."
echo " -noprivatefile : Do not create the 'private' directectory with an 'init-private.el' file."
echo " -nopsimacsdocu : Do not create desktop shortcuts to the HTML documentation files."
echo " -username : The user name written to the 'init-private.el' file."
echo " -useremail : The user email written to the 'init-private.el' file."
echo " -calendarlatitude : The user latitude used for the calender written to the 'init-private.el' file."
echo " -calendarlongitude : The user longitude used for the calender written to the 'init-private.el' file."
echo " -calendarlocation : The user place used for the calender location."
echo " -nopackageversions : Remove the 'straight/versions/default.el' file. In that case Psimacs installs the"
echo " most recent packages. Recommendet only for experts."
echo " -nofontsinstall : Do not install any fonts in the Windows system."
echo " -allnerdfonts : Install all of the Nerd fonts, instead of a subset."
echo " -noalltheicons : Do not install the 'all_the_icons' TTF fonts."
echo " -nonerdicons : Do not install the 'nonerdicons' TTF fonts."
echo " -noorgthemes : Do not install the org themes."
echo " -nocontent : Do not create the boilerplate content folder."
echo " Deinstallation"
echo " -uninstall : Uninstall all but the virtual Python environment and Psimacs itself."
echo " -force : Additionally uninstall the virtual Python environment and Psimacs itself. Also needs option '-uninstall'."
echo ""
echo "Examples:"
echo " bootstrap.ps1 -help"
echo " bootstrap.ps1 -run"
echo " bootstrap.ps1 -run -conemu -ucrt"
echo " bootstrap.ps1 -run -conemu -mingw -nopackages -python 3.11.4 -java 21.35"
echo ""
echo "Information:"
echo " In case that the powershell script does not run, two reasons may be involved:"
echo ""
echo " 1. Set a proper execution policy for powershell scripts with respect to the user profile."
echo " 2. Downloaded powershell scripts are not executed. They need to be unlocked."
echo ""
echo " The following steps might work for you:"
echo ' Get-ExecutionPolicy -list'
echo ' Set-ExecutionPolicy -ExecutionPolicy unrestricted -Scope CurrentUser'
echo ' Unblock-File -Path .\bootstrap.ps1'
echo ' .\bootstrap.ps1 -help'
echo ""
echo "ToDo:"
echo " Missing installation of font file Symbola.otf"
echo " https://dn-works.com/wp-content/uploads/2020/UFAS-Fonts/Symbola.zip"
return
}
#
# Are we running with Admin rights?
#
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$isAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
#
# Uninstallation
#
if ($uninstall)
{
echo "Uninstalling Psimacs ..."
#
# Test for HOME environment variable. If it does not exist
# we can't uninstall anything and we leave the script.
#
if (-not $env:HOME)
{
echo "No HOME environment variable defined. Prematurely leaving script!"
return
}
#
# Define the Psimacs directory
#
$psimacs = "$env:HOME\psimacs"
$psimacs = $psimacs.Replace('/', '\')
if ( ! (test-path -PathType container $psimacs) )
{
echo "No $psimacs directory found. Prematurely leaving script!"
return
}
#
# Deinstallation of Python
#
$dirs = Get-ChildItem "$psimacs\Python*" -Directory
foreach ($dir in $dirs)
{
if ($dir -match 'Python(?<major>\d)(?<minor>\d+)$')
{
$PyMajor = $Matches.major
$PyMinor = $Matches.minor
$python = "CPython-${PyMajor}.${PyMinor}"
echo "Found $python installation in $dir ..."
#
# Lookup the uninstaller for that Python version
#
$key = "registry::HKEY_CURRENT_USER\SOFTWARE\Classes\Installer\Dependencies\$python"
if (Test-Path -Path "$key")
{
$key = "registry::\HKEY_CURRENT_USER\SOFTWARE\Classes\Installer\Dependencies\$python\Dependents\*"
$subkeys = Get-ChildItem -Path "$key"
foreach ($subkey in $subkeys)
{
if ($subkey -match '^.*\\(?<hash_key>\{.+\})$')
{
$hash_key = $Matches.hash_key
$key = "registry::\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$hash_key"
if (Test-Path -Path "$key")
{
try {
$uninstall_cmd = (Get-ItemProperty -Path "$key" -Name "QuietUninstallString").QuietUninstallString
if ($uninstall_cmd -match '^"(?<cmd>.*)"\s+(?<args>.*)$')
{
$uninstall_cmd = $Matches.cmd
$uninstall_args = $Matches.args
echo "$uninstall_cmd"
echo "$uninstall_args"
Start-Process "$uninstall_cmd" -NoNewWindow -Wait -ArgumentList "$uninstall_args"
}
}
catch
{
echo "Uninstallation of $python failed!"
}
}
}
}
}
}
}
#
# Deinstallation of all tools but not the virtual Python environment and not Psimacs itself!
#
$dirs = Get-ChildItem "$psimacs\*" -Directory
foreach ($dir in $dirs)
{
if ($dir -match 'Python\d+_0|psimacs$')
{
if (-not $force)
{
echo "Excluding directory $dir from uninstallation..."
}
}
else
{
echo "Removing directory $dir recursively..."
Remove-Item -Recurse -Force "$dir"
}
}
if ( Test-Path "$psimacs\psimacs.cmd" -PathType Leaf )
{
Remove-Item -Force "$psimacs\psimacs.cmd"
}
#
# Deinstallation of the virtual Python environment and Psimacs itself.
#
if ($force)
{
$dirs = Get-ChildItem "$psimacs\*" -Directory
foreach ($dir in $dirs)
{
if ($dir -match 'Python\d+_0|psimacs$')
{
echo "Removing directory $dir recursively..."
Remove-Item -Recurse -Force "$dir"
}
}
if ( test-path -PathType container $psimacs )
{
echo "Finally removing root directory $psimacs ..."
Remove-Item -Recurse -Force "$psimacs"
}
}
#
# Remove shortcuts from desktop
#
$Shell = New-Object -comObject WScript.Shell
$Desktop = $Shell.SpecialFolders("Desktop")
$shortcuts = @()
$shortcuts += "$Desktop\Psimacs MSYS2 MINGW 64-bit.lnk"
$shortcuts += "$Desktop\Psimacs MSYS2 MINGW 64-bit.lnk"
$shortcuts += "$Desktop\Psimacs ConEmu MSYS2 MINGW 64-bit.lnk"
$shortcuts += "$Desktop\Psimacs MSYS2 UCRT 64-bit.lnk"
$shortcuts += "$Desktop\Psimacs MSYS2 UCRT 64-bit.lnk"
$shortcuts += "$Desktop\Psimacs ConEmu MSYS2 UCRT 64-bit.lnk"
$shortcuts += "$Desktop\Psimacs MSYS2 CLANG 64-bit.lnk"
$shortcuts += "$Desktop\Psimacs MSYS2 CLANG 64-bit.lnk"
$shortcuts += "$Desktop\Psimacs ConEmu MSYS2 CLANG 64-bit.lnk"
$shortcuts += "$Desktop\Psimacs Server.lnk"
$shortcuts += "$Desktop\Psimacs Client.lnk"
$shortcuts += "$Desktop\Psimacs Documentation.lnk"
$shortcuts += "$Desktop\Psimacs Key Bindings.lnk"
$shortcuts += "$Desktop\Psimacs Sorted Key Bindings.lnk"
foreach ($shortcut in $shortcuts)
{
if ( Test-Path "$shortcut" -PathType Leaf )
{
echo "Removing shortcut $shortcut ..."
Remove-Item -Force "$shortcut"
}
}
return
}
if ( -not ($mingw -OR $ucrt -OR $clang))
{
$mingw = $true
}
if ($mingw)
{
if ($ucrt -OR $clang)
{
echo "Only one MSYS2 environment is allowed! Use either -mingw, -ucrt or -clang."
return
}
echo "Working on MSYS2 environment MINGW64..."
}
if ($ucrt)
{
if ($mingw -OR $clang)
{
echo "Only one MSYS2 environment is allowed! Use either -mingw, -ucrt or -clang."
return
}
echo "Working on MSYS2 environment UCRT64..."
}
if ($clang)
{
if ($mingw -OR $ucrt)
{
echo "Only one MSYS2 environment is allowed! Use either -mingw, -ucrt or -clang."
return
}
echo "Working on MSYS2 environment CLANG64..."
}
#
# Precondition: check for windows git
#
# We do not install git into the msys64, because it does
# not work out of the box currently.
#
try
{
git | Out-Null
echo "Git is installed and accessible on the machine..."
}
catch [System.Management.Automation.CommandNotFoundException]
{
echo "Git is not accessible but required. Install a proper Windows Git"
echo "e.g. from https://git-scm.com/download/win"
echo "Provided that you have installed git to 'c:\utils\Git'"
echo "do add the 'c:\utils\Git\cmd' direcotry to your PATH variable!"
return
}
#
# Precondition check for Python version if requested Python
#
if (-not $nopython)
{
if ((-not $python) -and (-not $pythonuselatest))
{
$python = "3.11.5"
}
if ($python)
{
if ($python -match '(?<major>\d+)\.(?<minor>\d+)\.(?<build>\d+)')
{
$PyMajor = $Matches.major
$PyMinor = $Matches.minor
$PyBuild = $Matches.build
#
# Remark: Python on Windows allows not to install separate build numbers.
# We therefore use the 'PythonXY' directory as used by many people.
#
$python_dir = "Python${PyMajor}${PyMinor}"
}
else
{
echo "Invalid Python version given: RegExp format is '\d\.\d+\.\d+'."
return
}
}
else
{
$baseuri = 'https://www.python.org/downloads/windows'
try
{
$ProgressPreference = "silentlyContinue"
$response = Invoke-WebRequest -Uri $baseuri -UseBasicParsing
$ProgressPreference = 'Continue'
if ($response.Content -match '.*Latest Python \d+ Release - Python (?<major>\d+)\.(?<minor>\d+)\.(?<build>\d+).*')
{
$PyMajor = $Matches.major
$PyMinor = $Matches.minor
$PyBuild = $Matches.build
$python = "${PyMajor}.${PyMinor}.${PyBuild}"
#
# Remark: Python on Windows allows not to install separate build numbers.
# We therefore use the 'PythonXY' directory as used by many people.
#
$python_dir = "Python${PyMajor}${PyMinor}"
echo "Found latest stable Python release $python"
}
else
{
echo "No valid Python version could be determined. Please provide a version string"
echo "with option -python, like -python 3.11.5."
return
}
}
catch
{
echo "Could identify the latest Python version number. Check for another Python version. Prematurely leaving script!"
return
}
}
}
#
# Precondition Java
#
if (-not $nojava)
{
if ($java -match '(?<major>\d+)\.(?<revision>\d+)')
{
$JavaMajor = $Matches.major
$JavaRev = $Matches.revision
$java_url = "https://download.java.net/openjdk/jdk${JavaMajor}/ri/openjdk-${JavaMajor}+${JavaRev}_windows-x64_bin.zip"
$java_jdk = "jdk-$JavaMajor"
}
else
{
echo "Invalid Java OpenJDK version number: $java"
return
}
}
#
# Precondition check for SumatraPDF version if requested SumatryPDF
#
if (-not $nosumatrapdf)
{
if ($sumatrapdf)
{
if ($sumatrapdf -match '(?<major>\d+)\.(?<minor>\d+)\.(?<build>\d+)')
{
$SumatraMajor = $Matches.major
$SumatraMinor = $Matches.minor
$SumatraBuild = $Matches.build
}
else
{
echo "Invalid SumatraPDF version version given: RegExp format is '\d\.\d+\.\d+'"
return
}
}
else
{
$baseuri = 'https://www.sumatrapdfreader.org/download-free-pdf-viewer'
try
{
$ProgressPreference = "silentlyContinue"
$response = Invoke-WebRequest -Uri $baseuri -UseBasicParsing
$ProgressPreference = 'Continue'
if ($response.Content -match '.*SumatraPDF-(?<major>\d+)\.(?<minor>\d+)\.(?<build>\d+)-64.zip.*')
{
$SumatraMajor = $Matches.major
$SumatraMinor = $Matches.minor
$SumatraBuild = $Matches.build
$sumatrapdf = "${SumatraMajor}.${SumatraMinor}.${SumatraBuild}"
echo "Found latest stable SumatraPDF release $sumatrapdf"
}
else
{
echo "No valid SumatraPDF version could be determined. Please provide a version string"
echo "with option -sumatrapdf, like -sumatrapdf 3.4.6"
return
}
}
catch
{
echo "Could identify the latest SumatraPDF version number. Check for another SumatraPDF version. Prematurely leaving script!"
return
}
}
}
#
# Test for HOME environment variable. If it does not exist
# create it in c:\User\[Environment]::UserName
#
if (-not $env:HOME)
{
echo "Creating HOME environment variable..."
$user = [Environment]::UserName
echo $user
[Environment]::SetEnvironmentVariable('HOME', "c:\home\$user", 'User')
}
#
# Define the Psimacs directory
#
$psimacs = "$env:HOME\psimacs"
$psimacs = $psimacs.Replace('/', '\')
#
# Create the $enc:HOME\psimacs directory if it does not exist
#
if ( ! (test-path -PathType container $psimacs) )
{
echo "Creating $psimacs directory..."
New-Item -ItemType Directory -Path $psimacs
}
#
# Go to the psimacs directory for further working
#
Set-Location -Path "$psimacs"
#
# Bootstrap msys64 into psimacs dir: Install
#
$msys64 = "$psimacs\msys64"
$msys64_bin = "$msys64\usr\bin"
if ($mingw)
{
$package_prefix = "mingw-w64-x86_64"
$msys_env_bin = "$msys64\mingw64\bin"
$msys_env_share = "$msys64\mingw64\share"
$msys_env_name = "MINGW"
$msys_env_icon = "mingw64.ico"
$msys_env_arg = "mingw64"
}
if ($ucrt)
{
$package_prefix = "mingw-w64-ucrt-x86_64"
$msys_env_bin = "$msys64\ucrt64\bin"
$msys_env_share = "$msys64\ucrt64\share"
$msys_env_name = "UCRT"
$msys_env_icon = "ucrt64.ico"
$msys_env_arg = "ucrt64"
}
if ($clang)
{
$package_prefix = "mingw-w64-clang-x86_64"
$msys_env_bin = "$msys64\clang64\bin"
$msys_env_share = "$msys64\clang64\share"
$msys_env_name = "CLANG"
$msys_env_icon = "clang64.ico"
$msys_env_arg = "clang64"
}
if ( ! (Test-Path $msys64) )
{
echo "Installing MSYS2 in $msys64 directory..."
$msys64_installer = "msys2-base-x86_64-latest.sfx.exe"
#
# Download installer
#
if ( ! (Test-Path "$psimacs\$msys64_installer" -PathType Leaf) )
{
echo "Downloading $msys64_installer installer..."
$msys64_installer_url = "https://github.com/msys2/msys2-installer/releases/download/nightly-x86_64/$msys64_installer"
try
{
$ProgressPreference = "silentlyContinue"
Invoke-WebRequest -Uri $msys64_installer_url -UseBasicParsing -OutFile $msys64_installer
$ProgressPreference = 'Continue'
}
catch
{
echo "Downloading of MSYS2 installer failed. Prematurely leaving script!"
Set-Location -Path "$PSScriptRoot"
return
}
}
#
# Execute the msys64 installer
#
if ( Test-Path "$psimacs\$msys64_installer" -PathType Leaf )
{
echo "Running $msys64_installer installer..."
& "$psimacs\$msys64_installer"
Remove-Item "$psimacs\$msys64_installer"
}
}
#
# Check for msys64
#
if ( ! (Test-Path $msys64) )
{
echo "Expected path $msys64 could not be found. Leaving script!"
return
}
#
# Bootstrap msys64 into psimacs dir: setup environment
#
$bash_exe = "$msys64_bin\bash.exe"
$env:PATH = "$msys64_bin;$env:PATH"
$env:CHERE_INVOKING = 1
$env:MSYSTEM = "${msys_env_name}64"
$env:MSYS2_PATH_TYPE = 'inherit'
$env:CONTITLE = "MinGW ${msys_env_name} x64"
if ( ! $nopackages )
{
echo "Bootstrapping $msys64 ..."
#
# Bootstrap msys64 into psimacs dir: setup pacman
#
& $bash_exe --login -c "mkdir -p /var/cache/pacman/pkg"
#
# Bootstrap msys64 into psimacs dir: pacman update process
#
& $bash_exe --login -c "pacman -Syuu --noconfirm --needed --noprogressbar && ps -ef | grep 'dirmngr' | grep -v grep | awk '{print `$2}' | xargs -r kill -9 && ps -ef | grep 'gpg-agent' | grep -v grep | awk '{print `$2}' | xargs -r kill -9"
& $bash_exe --login -c "pacman -Syuu --noconfirm --needed --noprogressbar && ps -ef | grep 'gpg-agent' | grep -v grep | awk '{print `$2}' | xargs -r kill -9"
#
# Bootstrap msys64 into psimacs dir: install man pages
#
& $bash_exe --login -c "pacman --sync --noconfirm --needed man-db"
#
# Bootstrap msys64 into psimacs dir: install base development tools
#
& $bash_exe --login -c "pacman --sync --noconfirm --needed msys2-devel"
& $bash_exe --login -c "pacman --sync --noconfirm --needed base-devel"
& $bash_exe --login -c "pacman --sync --noconfirm --needed compression"
& $bash_exe --login -c "pacman --sync --noconfirm --needed Database"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-wget2"
& $bash_exe --login -c "pacman --sync --noconfirm --needed dos2unix"
& $bash_exe --login -c "pacman --sync --noconfirm --needed w3m"
#
# Bootstrap msys64 into psimacs dir: install git
#
#& $bash_exe --login -c "pacman --sync --noconfirm --needed git"
#& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-tools-git"
#& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-perl-doc"
#
# Bootstrap msys64 into psimacs dir: install emacs
#
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-emacs"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-giflib"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-libjpeg-turbo"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-libpng"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-librsvg"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-libtiff"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-libxml2"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-emacs-pdf-tools-server"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-imagemagick"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-imagemagick-docs"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-zeromq"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-winpty"
#
# Bootstrap msys64 into psimacs dir: install tools
#
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-ghostscript"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-graphviz"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-graphviz-docs"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-openexr"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-librsvg"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-libtiff"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-giflib"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-icu"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-cairo"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-ca-certificates"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-cmake"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-cmake-docs"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-doxygen"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-grep"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-hugo"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-hunspell"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-hyphen"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-hyphen-en"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-clang-analyzer"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-clang-tools-extra"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-7zip"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-antlr4-runtime-cpp"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-asciidoc"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-asciidoctor"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-aspell-de"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-aspell-en"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-astyle"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-iconv"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-ripgrep"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-scite"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-scite-defaults"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-fd"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-ffmpeg"
#
# Node.js and mermaid diagramm support
#
if (! $nonpm)
{
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-nodejs"
& $bash_exe --login -c "npm install -g @mermaid-js/mermaid-cli"
}
#
# Bootstrap msys64 into psimacs dir: install nerd fonts
#
if ($allnerdfonts)
{
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-nerd-fonts"
}
else
{
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-ttf-firacode-nerd"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-ttf-hack-nerd"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-ttf-inconsolata-nerd"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-ttf-sourcecodepro-nerd"
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-ttf-0xproto-nerd"
}
#
# Bootstrap msys64 into psimacs dir: install texlive
#
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-texlive-full"
#
# Bootstrap msys64 into psimacs dir: install development
#
& $bash_exe --login -c "pacman --sync --noconfirm --needed ${package_prefix}-toolchain"
}
#
# Create a shortcut for the MSYS2 Shell
#
$Shell = New-Object -comObject WScript.Shell
$Target = "$msys64\msys2_shell.cmd"
$Icon = "$msys64\$msys_env_icon"
$Args = "-${msys_env_arg} -use-full-path"
$Dest = $Shell.SpecialFolders("Desktop")
$Dest = "$Dest\Psimacs MSYS2 ${msys_env_name} 64-bit.lnk"
if (! (Test-Path "$Dest" -PathType Leaf) )
{
echo "Creating MSYS2 ${msys_env_name} 64-bit Dektop Shortcut..."
$Shortcut = $Shell.CreateShortcut($Dest)
$Shortcut.WindowStyle = 1
$Shortcut.IconLocation = $Icon
$Shortcut.TargetPath = $Target
$Shortcut.Arguments = $Args
$Shortcut.WorkingDirectory = $msys64
$ShortCut.Description = "MSYS2 Terminal Shell for Psimacs on ${msys_env_name} 64-bit"
$Shortcut.Save()
}
#
# Handle ConEmu on request
#
if ($conemu)
{
echo "Installing ConEmu..."
$conemu_dir = "$psimacs\ConEmu"
$conemu_7z = "conemu.7z"
if ( ! (Test-Path "$conemu_dir") )
{
try
{
$ProgressPreference = "silentlyContinue"
$githubLatestReleases = 'https://api.github.com/repos/Maximus5/ConEmu/releases/latest'
echo "$githubLatestReleases"
$githubLatestRelease = (((Invoke-WebRequest -Uri $gitHubLatestReleases -UseBasicParsing) | ConvertFrom-Json).assets.browser_download_url | select-string -Pattern '.7z').Line
echo "$githubLatestRelease"
Invoke-WebRequest -Uri $githubLatestRelease -UseBasicParsing -OutFile "$conemu_7z"
$ProgressPreference = 'Continue'
}
catch
{
echo "Downloading of ConEmu installer failed. Prematurely leaving script!"
Set-Location -Path "$PSScriptRoot"
return
}
}
#
# Extract the ConEmu console
#
if ( Test-Path "$psimacs\$conemu_7z" -PathType Leaf )
{
echo "Extracting ConEmu archive "$psimacs\$conemu_7z" ..."
& $bash_exe --login -c "cd $(cygpath --mixed $psimacs); 7z x -oConEmu conemu.7z"
Remove-Item "$psimacs\$conemu_7z"
}
$conemu_cmd = "$conemu_dir\msys2ConEmu.cmd"
if (! (Test-Path "$conemu_cmd" -PathType Leaf) )
{
echo "Writing command script $conemu_cmd ..."
"@echo off" | out-file -filepath $conemu_cmd -encoding ascii -width 200
"" | out-file -filepath $conemu_cmd -encoding ascii -width 200 -append
"set `"PATH=$msys64_bin;%PATH%`"" | out-file -filepath $conemu_cmd -encoding ascii -width 200 -append
"set CHERE_INVOKING=1" | out-file -filepath $conemu_cmd -encoding ascii -width 200 -append
"set MSYSTEM=${msys_env_name}64" | out-file -filepath $conemu_cmd -encoding ascii -width 200 -append
"set MSYS2_PATH_TYPE=inherit" | out-file -filepath $conemu_cmd -encoding ascii -width 200 -append
"" | out-file -filepath $conemu_cmd -encoding ascii -width 200 -append
"set `"CONTITLE=MinGW ${msys_env_name} x64`"" | out-file -filepath $conemu_cmd -encoding ascii -width 200 -append
"" | out-file -filepath $conemu_cmd -encoding ascii -width 200 -append
"start `"%CONTITLE%`" $conemu_dir\ConEmu64.exe /Here /Icon `"$msys64\$msys_env_icon`" /cmd `"$bash_exe`" --login -i" | out-file -filepath $conemu_cmd -encoding ascii -width 200 -append
}
$Shell = New-Object -comObject WScript.Shell
$Target = "$conemu_cmd"
$Icon = "$msys64\$msys_env_icon"
$Dest = $Shell.SpecialFolders("Desktop")
$Dest = "$Dest\Psimacs ConEmu MSYS2 ${msys_env_name} 64-bit.lnk"
if (! (Test-Path "$Dest" -PathType Leaf) )
{
echo "Creating MSYS2 ConEmu ${msys_env_name} 64-bit Dektop Shortcut..."
$Shortcut = $Shell.CreateShortcut($Dest)
$Shortcut.WindowStyle = 1
$Shortcut.IconLocation = $Icon
$Shortcut.TargetPath = $Target
$Shortcut.WorkingDirectory = $env:HOME
$ShortCut.Description = "MSYS2 ConEmu Shell for Psimacs on ${msys_env_name} 64-bit"
$Shortcut.Save()
}
}
#
# Install Python if requested
#
if (-not $nopython)
{
if ( (-not $nopythonupdate) -or (-not (test-path -PathType container $psimacs\$python_dir)) )
{
echo "Installing Python $python ..."
$python_installer = "python-${python}-amd64.exe"
#
# Download installer
#
if ( ! (Test-Path "$psimacs\$python_installer" -PathType Leaf) )
{
echo "Downloading $python_installer installer..."
try
{
$python_installer_url = "https://www.python.org/ftp/python/$python/$python_installer"
$ProgressPreference = "silentlyContinue"
Invoke-WebRequest -Uri $python_installer_url -UseBasicParsing -OutFile $python_installer
$ProgressPreference = 'Continue'
}
catch
{
echo "Downloading of Python $python failed. Check for another Python version. Prematurely leaving script!"
Set-Location -Path "$PSScriptRoot"
return
}
}
#
# Execute the python installer
#
if ( Test-Path "$psimacs\$python_installer" -PathType Leaf )
{
echo "Running $python_installer installer..."
Start-Process "$psimacs\$python_installer" -NoNewWindow -Wait -ArgumentList /quiet,Shortcuts=0,Include_launcher=0,AssociateFiles=0,InstallAllUsers=0,TargetDir="$psimacs\$python_dir",DefaultJustForMeTargetDir="$psimacs\$python_dir"
Remove-Item "$psimacs\$python_installer"
}
}
#
# Create a standard virtual environment from the basic Python installation
#
$python_venv_dir = "$psimacs\${python_dir}_0"
$python_venv_dir_unix = $python_venv_dir.Replace('\', '/')
if ( ! (test-path -PathType container $python_venv_dir) )
{
$python_exe = "$psimacs\$python_dir\python.exe"
& $python_exe -m venv $python_venv_dir/venv
}