-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathSalt-Minion-Setup.nsi
1998 lines (1657 loc) · 73.5 KB
/
Salt-Minion-Setup.nsi
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
!define PRODUCT_NAME "Salt Minion"
!define PRODUCT_PUBLISHER "SaltStack, Inc"
!define PRODUCT_WEB_SITE "http://saltproject.io"
!define PRODUCT_CALL_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\salt-call.exe"
!define PRODUCT_CP_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\salt-cp.exe"
!define PRODUCT_KEY_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\salt-key.exe"
!define PRODUCT_MASTER_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\salt-master.exe"
!define PRODUCT_MINION_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\salt-minion.exe"
!define PRODUCT_RUN_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\salt-run.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define /date TIME_STAMP "%Y-%m-%d-%H-%M-%S"
# Request admin rights
RequestExecutionLevel admin
# Import Libraries
!include "FileFunc.nsh"
!include "LogicLib.nsh"
!include "MoveFileFolder.nsh"
!include "MUI2.nsh"
!include "nsDialogs.nsh"
!include "StrFunc.nsh"
!include "WinMessages.nsh"
!include "WinVer.nsh"
!include "x64.nsh"
${StrLoc}
${StrStrAdv}
# Required by MoveFileFolder.nsh
!insertmacro Locate
# Get salt version from CLI argument /DSaltVersion
!ifdef SaltVersion
!define PRODUCT_VERSION "${SaltVersion}"
!else
!define PRODUCT_VERSION "Undefined Version"
!endif
# Get architecture from CLI argument /DPythonArchitecture
# Should be x64, AMD64, or x86
!ifdef PythonArchitecture
!define PYTHON_ARCHITECTURE "${PythonArchitecture}"
!else
# Default
!define PYTHON_ARCHITECTURE "x64"
!endif
# Get Estimated Size from CLI argument /DEstimatedSize
!ifdef PythonArchitecture
!define ESTIMATED_SIZE "${EstimatedSize}"
!else
# Default
!define ESTIMATED_SIZE 0
!endif
# x64 and AMD64 are AMD64, all others are x86
!if "${PYTHON_ARCHITECTURE}" == "x64"
!define CPUARCH "AMD64"
!else if "${PYTHON_ARCHITECTURE}" == "AMD64"
!define CPUARCH "AMD64"
!else
!define CPUARCH "x86"
!endif
!define BUILD_TYPE "Python 3"
!define OUTFILE "Salt-Minion-${PRODUCT_VERSION}-Py3-${CPUARCH}-Setup.exe"
# Part of the Trim function for Strings
!define Trim "!insertmacro Trim"
!macro Trim ResultVar String
Push "${String}"
Call Trim
Pop "${ResultVar}"
!macroend
# Part of the Explode function for Strings
!define Explode "!insertmacro Explode"
!macro Explode Length Separator String
Push "${Separator}"
Push "${String}"
Call Explode
Pop "${Length}"
!macroend
# Part of the StrContains function for Strings
!define StrContains "!insertmacro StrContains"
!macro StrContains OUT NEEDLE HAYSTACK
Push "${HAYSTACK}"
Push "${NEEDLE}"
Call StrContains
Pop "${OUT}"
!macroend
###############################################################################
# Configure Pages, Ordering, and Configuration
###############################################################################
!define MUI_ABORTWARNING
!define MUI_ICON "salt.ico"
!define MUI_UNICON "salt.ico"
!define MUI_WELCOMEFINISHPAGE_BITMAP "panel.bmp"
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "panel.bmp"
# Welcome page
!insertmacro MUI_PAGE_WELCOME
# License page
!insertmacro MUI_PAGE_LICENSE "LICENSE.txt"
# Install location page
!define MUI_PAGE_CUSTOMFUNCTION_SHOW pageCheckExistingInstall
!insertmacro MUI_PAGE_DIRECTORY
# Configure Minion page
Page custom pageMinionConfig pageMinionConfig_Leave
# Instfiles page
!insertmacro MUI_PAGE_INSTFILES
# Finish page (Customized)
!define MUI_PAGE_CUSTOMFUNCTION_SHOW pageFinish_Show
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE pageFinish_Leave
!insertmacro MUI_PAGE_FINISH
# Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
# Language files
!insertmacro MUI_LANGUAGE "English"
###############################################################################
# Custom Dialog Box Variables
###############################################################################
Var Dialog
Var Label
Var MinionStart_ChkBox
Var MinionStartDelayed_ChkBox
Var MasterHost_Cfg
Var MasterHost_TxtBox
Var MasterHost
Var MinionName_Cfg
Var MinionName_TxtBox
Var MinionName
Var ExistingConfigFound
Var ConfigType_DropList
Var ConfigType
Var CustomConfig_TxtBox
Var CustomConfig_Btn
Var CustomConfig
Var CustomConfigWarning_Lbl
Var ExistingConfigWarning_Lbl
Var DefaultConfigWarning_Lbl
Var MoveExistingConfig_ChkBox
Var MoveExistingConfig
Var StartMinion
Var StartMinionDelayed
Var DeleteInstallDir
Var DeleteRootDir
Var ConfigWriteMinion
Var ConfigWriteMaster
# For new method installation
Var RegInstDir
Var RegRootDir
Var RootDir
Var SysDrive
Var ExistingInstallation
Var CustomLocation
###############################################################################
# Directory Picker Dialog Box
###############################################################################
Function pageCheckExistingInstall
# If this is an Existing Installation we want to disable the directory
# picker functionality
# https://nsis-dev.github.io/NSIS-Forums/html/t-166727.html
# Use the winspy tool (https://sourceforge.net/projects/winspyex/) to get
# the Control ID for the items you want to disable
# The Control ID is in the Details tab
# It is a Hex value that needs to be converted to an integer
${If} $ExistingInstallation == 1
# 32770 is Class name used by all NSIS dialog boxes
FindWindow $R0 "#32770" "" $HWNDPARENT
# 1019 is the Destination Folder text field (0x3FB)
GetDlgItem $R1 $R0 1019
EnableWindow $R1 0
# 1001 is the Browse button (0x3E9)
GetDlgItem $R1 $R0 1001
EnableWindow $R1 0
# Disabling the Location Picker causes the buttons to behave incorrectly
# Esc and Enter don't work. Nor can you use Alt+N and Alt+B. Setting
# the focus to the Next button seems to fix this
# Set focus on Next button (0x1)
# Next=1, cancel=2, back=3
GetDlgItem $R1 $HWNDPARENT 1
SendMessage $HWNDPARENT ${WM_NEXTDLGCTL} $R1 1
${EndIf}
FunctionEnd
###############################################################################
# Minion Settings Dialog Box
###############################################################################
Function pageMinionConfig
# Set Page Title and Description
!insertmacro MUI_HEADER_TEXT "Minion Settings" "Set the Minion Master and ID"
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
# Master IP or Hostname Dialog Control
${NSD_CreateLabel} 0 0 100% 9u "&Master IP or Hostname:"
Pop $Label
${NSD_CreateText} 0 10u 100% 12u $MasterHost
Pop $MasterHost_TxtBox
# Minion ID Dialog Control
${NSD_CreateLabel} 0 30u 100% 9u "Minion &Name:"
Pop $Label
${NSD_CreateText} 0 40u 100% 12u $MinionName
Pop $MinionName_TxtBox
# Config Drop List
${NSD_CreateDropList} 0 60u 25% 36u ""
Pop $ConfigType_DropList
${NSD_CB_AddString} $ConfigType_DropList "Default Config"
${NSD_CB_AddString} $ConfigType_DropList "Custom Config"
${NSD_OnChange} $ConfigType_DropList pageMinionConfig_OnChange
# Add Existing Config Warning Label
${NSD_CreateLabel} 0 75u 100% 50u \
"The values above are taken from an existing configuration found in \
`$RootDir\conf\minion`.$\n\
$\n\
Clicking `Install` will leave the existing config unchanged."
Pop $ExistingConfigWarning_Lbl
CreateFont $0 "Arial" 10 500 /ITALIC
SendMessage $ExistingConfigWarning_Lbl ${WM_SETFONT} $0 1
SetCtlColors $ExistingConfigWarning_Lbl 0xBB0000 transparent
# Add Checkbox to move root_dir
${NSD_CreateCheckBox} 0 125u 100% 10u \
"Move &existing root directory (C:\salt) to %ProgramData%\Salt."
Pop $MoveExistingConfig_ChkBox
CreateFont $0 "Arial" 10 500
SendMessage $MoveExistingConfig_ChkBox ${WM_SETFONT} $0 1
${If} $MoveExistingConfig == 1
${NSD_Check} $MoveExistingConfig_ChkBox
${EndIf}
# Add Default Config Warning Label
${NSD_CreateLabel} 0 75u 100% 60u "Clicking `Install` will backup the \
existing minion config file and minion.d directories. The values \
above will be used in the new default config.$\n\
$\n\
NOTE: If Master IP is set to `salt` and Minion Name is set to \
`hostname` no changes will be made."
Pop $DefaultConfigWarning_Lbl
CreateFont $0 "Arial" 10 500 /ITALIC
SendMessage $DefaultConfigWarning_Lbl ${WM_SETFONT} $0 1
SetCtlColors $DefaultConfigWarning_Lbl 0xBB0000 transparent
# Add Custom Config File Selector and Warning Label
${NSD_CreateText} 26% 60u 64% 12u $CustomConfig
Pop $CustomConfig_TxtBox
${NSD_CreateButton} 91% 60u 9% 12u "..."
Pop $CustomConfig_Btn
${NSD_OnClick} $CustomConfig_Btn pageCustomConfigBtn_OnClick
${If} $ExistingConfigFound == 0
${NSD_CreateLabel} 0 75u 100% 60u \
"Values entered above will be used in the custom config.$\n\
$\n\
NOTE: If Master IP is set to `salt` and Minion Name is set to \
`hostname` no changes will be made."
${Else}
${NSD_CreateLabel} 0 75u 100% 60u \
"Clicking `Install` will backup the existing minion config \
file and minion.d directories. The values above will be used in \
the custom config.$\n\
$\n\
NOTE: If Master IP is set to `salt` and Minion Name is set to \
`hostname` no changes will be made."
${Endif}
Pop $CustomConfigWarning_Lbl
CreateFont $0 "Arial" 10 500 /ITALIC
SendMessage $CustomConfigWarning_Lbl ${WM_SETFONT} $0 1
SetCtlColors $CustomConfigWarning_Lbl 0xBB0000 transparent
# If existing config found, add the Existing Config option to the Drop List
# If not, hide the Default Warning
${If} $ExistingConfigFound == 1
${NSD_CB_AddString} $ConfigType_DropList "Existing Config"
${Else}
ShowWindow $DefaultConfigWarning_Lbl ${SW_HIDE}
${Endif}
${NSD_CB_SelectString} $ConfigType_DropList $ConfigType
${NSD_SetText} $CustomConfig_TxtBox $CustomConfig
Call pageMinionConfig_OnChange
nsDialogs::Show
FunctionEnd
Function pageMinionConfig_OnChange
# You have to pop the top handle to keep the stack clean
Pop $R0
# Assign the current checkbox state to the variable
${NSD_GetText} $ConfigType_DropList $ConfigType
# Update Dialog
${Switch} $ConfigType
${Case} "Existing Config"
# Enable Master/Minion and set values
EnableWindow $MasterHost_TxtBox 0
EnableWindow $MinionName_TxtBox 0
${NSD_SetText} $MasterHost_TxtBox $MasterHost_Cfg
${NSD_SetText} $MinionName_TxtBox $MinionName_Cfg
# Hide Custom File Picker
ShowWindow $CustomConfig_TxtBox ${SW_HIDE}
ShowWindow $CustomConfig_Btn ${SW_HIDE}
# Hide Warnings
ShowWindow $DefaultConfigWarning_Lbl ${SW_HIDE}
ShowWindow $CustomConfigWarning_Lbl ${SW_HIDE}
# Show Existing Warning
ShowWindow $ExistingConfigWarning_Lbl ${SW_SHOW}
${If} $RootDir == "C:\salt"
ShowWindow $MoveExistingConfig_ChkBox ${SW_SHOW}
${Else}
ShowWindow $MoveExistingConfig_ChkBox ${SW_HIDE}
${EndIf}
${Break}
${Case} "Custom Config"
# Enable Master/Minion and set values
EnableWindow $MasterHost_TxtBox 1
EnableWindow $MinionName_TxtBox 1
${NSD_SetText} $MasterHost_TxtBox $MasterHost
${NSD_SetText} $MinionName_TxtBox $MinionName
# Show Custom File Picker
ShowWindow $CustomConfig_TxtBox ${SW_SHOW}
ShowWindow $CustomConfig_Btn ${SW_SHOW}
# Hide Warnings
ShowWindow $DefaultConfigWarning_Lbl ${SW_HIDE}
ShowWindow $ExistingConfigWarning_Lbl ${SW_HIDE}
ShowWindow $MoveExistingConfig_ChkBox ${SW_HIDE}
# Show Custom Warning
ShowWindow $CustomConfigWarning_Lbl ${SW_SHOW}
${Break}
${Case} "Default Config"
# Enable Master/Minion and set values
EnableWindow $MasterHost_TxtBox 1
EnableWindow $MinionName_TxtBox 1
${NSD_SetText} $MasterHost_TxtBox $MasterHost
${NSD_SetText} $MinionName_TxtBox $MinionName
# Hide Custom File Picker
ShowWindow $CustomConfig_TxtBox ${SW_HIDE}
ShowWindow $CustomConfig_Btn ${SW_HIDE}
# Hide Warnings
ShowWindow $ExistingConfigWarning_Lbl ${SW_HIDE}
ShowWindow $MoveExistingConfig_ChkBox ${SW_HIDE}
ShowWindow $CustomConfigWarning_Lbl ${SW_HIDE}
# Show Default Warning, if there is an existing config
${If} $ExistingConfigFound == 1
ShowWindow $DefaultConfigWarning_Lbl ${SW_SHOW}
${Endif}
${Break}
${EndSwitch}
FunctionEnd
# File Picker Definitions
!define OFN_FILEMUSTEXIST 0x00001000
!define OFN_DONTADDTOREC 0x02000000
!define OPENFILENAME_SIZE_VERSION_400 76
!define OPENFILENAME 'i,i,i,i,i,i,i,i,i,i,i,i,i,i,&i2,&i2,i,i,i,i'
Function pageCustomConfigBtn_OnClick
Pop $0
System::Call '*(&t${NSIS_MAX_STRLEN})i.s' # Allocate OPENFILENAME.lpstrFile buffer
System::Call '*(${OPENFILENAME})i.r0' # Allocate OPENFILENAME struct
System::Call '*$0(${OPENFILENAME})(${OPENFILENAME_SIZE_VERSION_400}, \
$hwndparent, , , , , , sr1, ${NSIS_MAX_STRLEN} , , , , \
t"Select Custom Config File", \
${OFN_FILEMUSTEXIST} | ${OFN_DONTADDTOREC})'
# Populate file name field
${NSD_GetText} $CustomConfig_TxtBox $2
System::Call "*$1(&t${NSIS_MAX_STRLEN}r2)" ; Set lpstrFile to the old path (if any)
# Open the dialog
System::Call 'COMDLG32::GetOpenFileName(ir0)i.r2'
# Get file name field
${If} $2 <> 0
System::Call "*$1(&t${NSIS_MAX_STRLEN}.r2)"
${NSD_SetText} $CustomConfig_TxtBox $2
${EndIf}
# Free resources
System::Free $1
System::Free $0
FunctionEnd
Function pageMinionConfig_Leave
# Save the State
${NSD_GetText} $MasterHost_TxtBox $MasterHost
${NSD_GetText} $MinionName_TxtBox $MinionName
${NSD_GetText} $ConfigType_DropList $ConfigType
${NSD_GetText} $CustomConfig_TxtBox $CustomConfig
${NSD_GetState} $MoveExistingConfig_ChkBox $MoveExistingConfig
# Abort if config file not found
${If} $ConfigType == "Custom Config"
IfFileExists "$CustomConfig" done 0
MessageBox MB_OK|MB_ICONEXCLAMATION \
"File not found: $CustomConfig" \
/SD IDOK
Abort
${EndIf}
${If} $MoveExistingConfig == 1
# This makes the $APPDATA variable point to the ProgramData folder
# instead of the current user's roaming AppData folder
SetShellVarContext all
# Get directory status
# We don't want to overwrite data in the new location, so it needs to
# either be empty or not found. Otherwise, warn and abort
${DirState} "$APPDATA\Salt Project\Salt" $R0 # 0=Empty, 1=full, -1=Not Found
StrCmp $R0 "1" 0 done # Move files if directory empty or missing
MessageBox MB_OKCANCEL \
"The $APPDATA\Salt Project\Salt directory is not empty.$\n\
These files will need to be moved manually." \
/SD IDOK IDCANCEL cancel
# OK: We're continuing without moving existing config
StrCpy $MoveExistingConfig 0
Goto done
cancel:
# Cancel: We're unchecking the checkbox and returning the user to
# the dialog box
# Abort just returns the user back to the dialog box
${NSD_UNCHECK} $MoveExistingConfig_ChkBox
Abort
${EndIf}
done:
FunctionEnd
###############################################################################
# Custom Finish Page
###############################################################################
Function pageFinish_Show
# Imports so the checkboxes will show up
!define SWP_NOSIZE 0x0001
!define SWP_NOMOVE 0x0002
!define HWND_TOP 0x0000
# Create Start Minion Checkbox
${NSD_CreateCheckbox} 120u 90u 100% 12u "&Start salt-minion"
Pop $MinionStart_ChkBox
SetCtlColors $MinionStart_ChkBox "" "ffffff"
# This command required to bring the checkbox to the front
System::Call "User32::SetWindowPos(i, i, i, i, i, i, i) b ($MinionStart_ChkBox, ${HWND_TOP}, 0, 0, 0, 0, ${SWP_NOSIZE}|${SWP_NOMOVE})"
# Create Start Minion Delayed ComboBox
${NSD_CreateCheckbox} 130u 102u 100% 12u "&Delayed Start"
Pop $MinionStartDelayed_ChkBox
SetCtlColors $MinionStartDelayed_ChkBox "" "ffffff"
# This command required to bring the checkbox to the front
System::Call "User32::SetWindowPos(i, i, i, i, i, i, i) b ($MinionStartDelayed_ChkBox, ${HWND_TOP}, 0, 0, 0, 0, ${SWP_NOSIZE}|${SWP_NOMOVE})"
# Load current settings for Minion
${If} $StartMinion == 1
${NSD_Check} $MinionStart_ChkBox
${EndIf}
# Load current settings for Minion Delayed
${If} $StartMinionDelayed == 1
${NSD_Check} $MinionStartDelayed_ChkBox
${EndIf}
FunctionEnd
Function pageFinish_Leave
# Assign the current checkbox states
${NSD_GetState} $MinionStart_ChkBox $StartMinion
${NSD_GetState} $MinionStartDelayed_ChkBox $StartMinionDelayed
FunctionEnd
###############################################################################
# Installation Settings
###############################################################################
Name "${PRODUCT_NAME} ${PRODUCT_VERSION} (${BUILD_TYPE})"
OutFile "${OutFile}"
InstallDir "C:\Program Files\Salt Project\Salt"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show
Section -copy_prereqs
# Copy prereqs to the Plugins Directory
# These files are downloaded by build_pkg.bat
# This directory gets removed upon completion
SetOutPath "$PLUGINSDIR\"
File /r "..\..\prereqs\"
SectionEnd
# Check and install Visual C++ redist 2022 packages
# Hidden section (-) to install VCRedist
Section -install_vcredist_2022
Var /GLOBAL VcRedistName
Var /GLOBAL VcRedistReg
# Only install 64bit VCRedist on 64bit machines
# Use RunningX64 here to get the Architecture for the system running the
# installer.
${If} ${RunningX64}
StrCpy $VcRedistName "vcredist_x64_2022"
StrCpy $VcRedistReg "SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x64"
${Else}
StrCpy $VcRedistName "vcredist_x86_2022"
StrCpy $VcRedistReg "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86"
${EndIf}
# Detecting VCRedist Installation
detailPrint "Checking for $VcRedistName..."
ReadRegDword $0 HKLM $VcRedistReg "Installed"
StrCmp $0 "1" +2 0
Call InstallVCRedist
SectionEnd
Function InstallVCRedist
detailPrint "System requires $VcRedistName"
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 \
"$VcRedistName is currently not installed. Would you like to \
install?" \
/SD IDYES IDYES InstallVcRedist
detailPrint "$VcRedistName not installed"
detailPrint ">>>Installation aborted by user<<<"
MessageBox MB_ICONEXCLAMATION \
"$VcRedistName not installed. Aborted by user.$\n$\n\
Installer will now close." \
/SD IDOK
Quit
InstallVcRedist:
# If an output variable is specified ($0 in the case below), ExecWait
# sets the variable with the exit code (and only sets the error flag if
# an error occurs; if an error occurs, the contents of the user
# variable are undefined).
# http://nsis.sourceforge.net/Reference/ExecWait
ClearErrors
detailPrint "Installing $VcRedistName..."
ExecWait '"$PLUGINSDIR\$VcRedistName.exe" /install /quiet /norestart' $0
IfErrors 0 CheckVcRedistErrorCode
detailPrint "An error occurred during installation of $VcRedistName"
MessageBox MB_OK|MB_ICONEXCLAMATION \
"$VcRedistName failed to install. Try installing the package \
manually.$\n$\n\
The installer will now close." \
/SD IDOK
Quit
CheckVcRedistErrorCode:
# Check for Reboot Error Code (3010)
${If} $0 == 3010
detailPrint "$VcRedistName installed but requires a restart to complete."
detailPrint "Reboot and run Salt install again"
MessageBox MB_OK|MB_ICONINFORMATION \
"$VcRedistName installed but requires a restart to complete." \
/SD IDOK
# Check for any other errors
${ElseIfNot} $0 == 0
detailPrint "An error occurred during installation of $VcRedistName"
detailPrint "Error: $0"
MessageBox MB_OK|MB_ICONEXCLAMATION \
"$VcRedistName failed to install. Try installing the package \
mnually.$\n\
ErrorCode: $0$\n\
The installer will now close." \
/SD IDOK
${EndIf}
FunctionEnd
Section "MainSection" SEC01
${If} $MoveExistingConfig == 1
# This makes the $APPDATA variable point to the ProgramData folder
# instead of the current user's roaming AppData folder
SetShellVarContext all
detailPrint "Moving existing config to $APPDATA\Salt Project\Salt"
# Make sure the target directory exists
nsExec::Exec "md $APPDATA\Salt Project\Salt"
# Take ownership of the C:\salt directory
detailPrint "Taking ownership: $RootDir"
nsExec::Exec "takeown /F $RootDir /R"
# Move the C:\salt directory to the new location
StrCpy $switch_overwrite 0
detailPrint "Moving $RootDir to $APPDATA"
IfFileExists "$RootDir\conf" 0 +2
!insertmacro MoveFolder "$RootDir\conf" "$APPDATA\Salt Project\Salt\conf" "*.*"
IfFileExists "$RootDir\srv" 0 +2
!insertmacro MoveFolder "$RootDir\srv" "$APPDATA\Salt Project\Salt\srv" "*.*"
IfFileExists "$RootDir\var" 0 +2
!insertmacro MoveFolder "$RootDir\var" "$APPDATA\Salt Project\Salt\var" "*.*"
# Make RootDir the new location
StrCpy $RootDir "$APPDATA\Salt Project\Salt"
${EndIf}
${If} $ConfigType != "Existing Config"
Call BackupExistingConfig
${EndIf}
# Install files to the Installation Directory
SetOutPath "$INSTDIR\"
SetOverwrite off
File /r "..\..\buildenv\"
# Set up Root Directory
CreateDirectory "$RootDir\conf\pki\minion"
CreateDirectory "$RootDir\conf\minion.d"
CreateDirectory "$RootDir\var\cache\salt\minion\extmods\grains"
CreateDirectory "$RootDir\var\cache\salt\minion\proc"
CreateDirectory "$RootDir\var\log\salt"
CreateDirectory "$RootDir\var\run"
nsExec::Exec 'icacls $RootDir /inheritance:r /grant:r "*S-1-5-32-544":(OI)(CI)F /grant:r "*S-1-5-18":(OI)(CI)F'
SectionEnd
Function .onInit
# This function gets executed before any other. This is where we will
# detect existing installations and config to be used by the installer
# Make sure we do not allow 32-bit Salt on 64-bit systems
# This is the system the installer is running on
${If} ${RunningX64}
# This is the Python architecture the installer was built with
${If} ${CPUARCH} == "x86"
MessageBox MB_OK|MB_ICONEXCLAMATION \
"Detected 64-bit Operating system.$\n$\n\
Please install the 64-bit version of Salt on this operating system." \
/SD IDOK
Abort
${EndIf}
${Else}
# This is the Python architecture the installer was built with
${If} ${CPUARCH} == "AMD64"
MessageBox MB_OK|MB_ICONEXCLAMATION \
"Detected 32-bit Operating system.$\n$\n\
Please install the 32-bit version of Salt on this operating system." \
/SD IDOK
Abort
${EndIf}
${EndIf}
InitPluginsDir
Call parseInstallerCommandLineSwitches
# Uninstall msi-installed salt
# Source: https://nsis-dev.github.io/NSIS-Forums/html/t-303468.html
# TODO: Add a message box here confirming the uninstall of the MSI
!define upgradecode {FC6FB3A2-65DE-41A9-AD91-D10A402BD641} # Salt upgrade code
StrCpy $0 0
loop:
System::Call 'MSI::MsiEnumRelatedProducts(t "${upgradecode}",i0,i r0,t.r1)i.r2'
${If} $2 = 0
# Now $1 contains the product code
DetailPrint product:$1
push $R0
StrCpy $R0 $1
Call UninstallMSI
pop $R0
IntOp $0 $0 + 1
goto loop
${Endif}
# If a custom config is passed on the CLI, verify its existence before
# continuing so we don't uninstall an existing installation and then fail
# NOTE: This handles custom config for silent installations where the
# NOTE: custom config is passed on the CLI. The GUI has its own checking
# NOTE: when the user selects a custom config.
${If} $ConfigType == "Custom Config"
IfFileExists "$CustomConfig" checkExistingInstallation 0
Abort
${EndIf}
checkExistingInstallation:
# Check for existing installation
# The NSIS installer is a 32bit application and will use the WOW6432Node
# in the registry by default. We need to look in the 64 bit location on
# 64 bit systems
${If} ${RunningX64}
# https://nsis.sourceforge.io/Docs/Chapter4.html#setregview
SetRegView 64 # View the 64 bit portion of the registry
${EndIf}
ReadRegStr $R0 HKLM \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
"UninstallString"
# Puts the nullsoft installer back to its default
SetRegView 32 # Set it back to the 32 bit portion of the registry
# If not found, look in 32 bit
${If} $R0 == ""
ReadRegStr $R0 HKLM \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
"UninstallString"
${EndIf}
# If it's empty it's not installed
StrCmp $R0 "" skipUninstall
# Set InstDir to the parent directory so that we can uninstall it
${GetParent} $R0 $INSTDIR
# Found existing installation, prompt to uninstall
MessageBox MB_OKCANCEL|MB_USERICON \
"${PRODUCT_NAME} is already installed.$\n$\n\
Click `OK` to remove the existing installation." \
/SD IDOK IDOK uninst
Abort
uninst:
# Get current Silent status
StrCpy $R0 0
${If} ${Silent}
StrCpy $R0 1
${EndIf}
# Turn on Silent mode
SetSilent silent
# Don't remove all directories when upgrading (old method)
StrCpy $DeleteInstallDir 0
# Don't remove RootDir when upgrading (new method)
StrCpy $DeleteRootDir 0
# Uninstall silently
Call uninstallSalt
# Set it back to Normal mode, if that's what it was before
${If} $R0 == 0
SetSilent normal
${EndIf}
skipUninstall:
Call getExistingInstallation
Call getExistingMinionConfig
${If} $ExistingConfigFound == 0
${AndIf} $ConfigType == "Existing Config"
StrCpy $ConfigType "Default Config"
${EndIf}
FunctionEnd
Function BackupExistingConfig
${If} $ExistingConfigFound == 1 # If existing config found
${AndIfNot} $ConfigType == "Existing Config" # If not using Existing Config
# Backup the minion config
Rename "$RootDir\conf\minion" "$RootDir\conf\minion-${TIME_STAMP}.bak"
IfFileExists "$RootDir\conf\minion.d" 0 +2
Rename "$RootDir\conf\minion.d" "$RootDir\conf\minion.d-${TIME_STAMP}.bak"
${EndIf}
# By this point there should be no existing config. It was either backed up
# or wasn't there to begin with
${If} $ConfigType == "Custom Config" # If we're using Custom Config
${AndIfNot} $CustomConfig == "" # If a custom config is passed
# Check for a file name
# Named file should be in the same directory as the installer
CreateDirectory "$RootDir\conf"
IfFileExists "$EXEDIR\$CustomConfig" 0 checkFullPath
CopyFiles /SILENT /FILESONLY "$EXEDIR\$CustomConfig" "$RootDir\conf\minion"
goto finished
# Maybe it was a full path to a file
checkFullPath:
IfFileExists "$CustomConfig" 0 finished
CopyFiles /SILENT /FILESONLY "$CustomConfig" "$RootDir\conf\minion"
finished:
${EndIf}
FunctionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
# The NSIS installer is a 32bit application and will use the WOW6432Node in
# the registry by default. We need to look in the 64 bit location on 64 bit
# systems
${If} ${RunningX64}
# https://nsis.sourceforge.io/Docs/Chapter4.html#setregview
SetRegView 64 # View 64 bit portion of the registry
${EndIf}
# Write Uninstall Registry Entries
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
"DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
"UninstallString" "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
"DisplayIcon" "$INSTDIR\salt.ico"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
"DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
"URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
"Publisher" "${PRODUCT_PUBLISHER}"
WriteRegStr HKLM "SYSTEM\CurrentControlSet\services\salt-minion" \
"DependOnService" "nsi"
# If ESTIMATED_SIZE is not set, calculated it
${If} ${ESTIMATED_SIZE} == 0
${GetSize} "$INSTDIR" "/S=OK" $0 $1 $2
${Else}
StrCpy $0 ${ESTIMATED_SIZE}
${Endif}
IntFmt $0 "0x%08X" $0
WriteRegDWORD ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
"EstimatedSize" "$0"
# Write Commandline Registry Entries
WriteRegStr HKLM "${PRODUCT_CALL_REGKEY}" "" "$INSTDIR\salt-call.exe"
WriteRegStr HKLM "${PRODUCT_CALL_REGKEY}" "Path" "$INSTDIR\"
WriteRegStr HKLM "${PRODUCT_MINION_REGKEY}" "" "$INSTDIR\salt-minion.exe"
WriteRegStr HKLM "${PRODUCT_MINION_REGKEY}" "Path" "$INSTDIR\"
# Write Salt Configuration Registry Entries
# We want to write EXPAND_SZ string types to allow us to use environment
# variables. It's OK to use EXPAND_SZ even if you don't use an environment
# variable so we'll just do that whether it's new location or old.
# Check for Program Files
# Set the current setting for INSTDIR... we'll only change it if it contains
# Program Files
StrCpy $RegInstDir $INSTDIR
# Program Files
# We want to use the environment variables instead of the hardcoded path
${StrContains} $0 "Program Files" $INSTDIR
StrCmp $0 "" +2 # If it's empty, skip the next line
StrCpy $RegInstDir "%ProgramFiles%\Salt Project\Salt"
# Check for ProgramData
# Set the current setting for RootDir. we'll only change it if it contains
# ProgramData
StrCpy $RegRootDir $RootDir
# We want to use the environment variables instead of the hardcoded path
${StrContains} $0 "ProgramData" $RootDir
StrCmp $0 "" +2 # If it's empty, skip the next line
StrCpy $RegRootDir "%ProgramData%\Salt Project\Salt"
WriteRegExpandStr HKLM "SOFTWARE\Salt Project\Salt" "install_dir" "$RegInstDir"
WriteRegExpandStr HKLM "SOFTWARE\Salt Project\Salt" "root_dir" "$RegRootDir"
# Puts the nullsoft installer back to its default
SetRegView 32 # Set it back to the 32 bit portion of the registry
# Register the Salt-Minion Service
nsExec::Exec `$INSTDIR\ssm.exe install salt-minion "$INSTDIR\salt-minion.exe" -c """$RootDir\conf""" -l quiet`
nsExec::Exec "$INSTDIR\ssm.exe set salt-minion Description Salt Minion from saltstack.com"
nsExec::Exec "$INSTDIR\ssm.exe set salt-minion Start SERVICE_AUTO_START"
nsExec::Exec "$INSTDIR\ssm.exe set salt-minion AppStopMethodConsole 24000"
nsExec::Exec "$INSTDIR\ssm.exe set salt-minion AppStopMethodWindow 2000"
nsExec::Exec "$INSTDIR\ssm.exe set salt-minion AppRestartDelay 60000"
# There is a default minion config laid down in the $INSTDIR directory
${Switch} $ConfigType
${Case} "Existing Config"
# If this is an Existing Config, we don't do anything
${Break}
${Case} "Custom Config"
# If this is a Custom Config, update the custom config
Call updateMinionConfig
${Break}
${Case} "Default Config"
# If this is the Default Config, we move it and update it
StrCpy $switch_overwrite 1
!insertmacro MoveFolder "$INSTDIR\configs" "$RootDir\conf" "*.*"
Call updateMinionConfig
${Break}
${EndSwitch}
# Delete the configs directory that came with the installer
RMDir /r "$INSTDIR\configs"
# Add $INSTDIR in the Path
EnVar::SetHKLM
EnVar::AddValue Path "$INSTDIR"
SectionEnd
Function .onInstSuccess
# If StartMinionDelayed is 1, then set the service to start delayed
${If} $StartMinionDelayed == 1
nsExec::Exec "$INSTDIR\ssm.exe set salt-minion Start SERVICE_DELAYED_AUTO_START"
${EndIf}
# If start-minion is 1, then start the service
${If} $StartMinion == 1
nsExec::Exec 'net start salt-minion'
${EndIf}
FunctionEnd
Function un.onInit
Call un.parseUninstallerCommandLineSwitches
MessageBox MB_USERICON|MB_YESNO|MB_DEFBUTTON1 \
"Are you sure you want to completely remove $(^Name) and all of its \
components?" \
/SD IDYES IDYES +2
Abort
FunctionEnd
Section Uninstall
Call un.uninstallSalt
# Remove $INSTDIR from the Path
EnVar::SetHKLM
EnVar::DeleteValue Path "$INSTDIR"
SectionEnd
!macro uninstallSalt un
Function ${un}uninstallSalt
# WARNING: Any changes made here need to be reflected in the MSI uninstaller
# Make sure we're in the right directory
${If} $INSTDIR == "c:\salt\Scripts"
StrCpy $INSTDIR "C:\salt"
${EndIf}