Salt-Minion-Setup.nsi 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  1. !define PRODUCT_NAME "Salt Minion"
  2. !define PRODUCT_NAME_OTHER "Salt"
  3. !define PRODUCT_PUBLISHER "SaltStack, Inc"
  4. !define PRODUCT_WEB_SITE "http://saltstack.org"
  5. !define PRODUCT_CALL_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\salt-call.exe"
  6. !define PRODUCT_CP_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\salt-cp.exe"
  7. !define PRODUCT_KEY_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\salt-key.exe"
  8. !define PRODUCT_MASTER_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\salt-master.exe"
  9. !define PRODUCT_MINION_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\salt-minion.exe"
  10. !define PRODUCT_RUN_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\salt-run.exe"
  11. !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
  12. !define PRODUCT_UNINST_KEY_OTHER "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME_OTHER}"
  13. !define PRODUCT_UNINST_ROOT_KEY "HKLM"
  14. !define OUTFILE "Salt-Minion-${PRODUCT_VERSION}-Py${PYTHON_VERSION}-${CPUARCH}-Setup.exe"
  15. # Import Libraries
  16. !include "MUI2.nsh"
  17. !include "nsDialogs.nsh"
  18. !include "LogicLib.nsh"
  19. !include "FileFunc.nsh"
  20. !include "StrFunc.nsh"
  21. !include "x64.nsh"
  22. !include "WinMessages.nsh"
  23. !include "WinVer.nsh"
  24. ${StrLoc}
  25. ${StrStrAdv}
  26. !ifdef SaltVersion
  27. !define PRODUCT_VERSION "${SaltVersion}"
  28. !else
  29. !define PRODUCT_VERSION "Undefined Version"
  30. !endif
  31. !ifdef PythonVersion
  32. !define PYTHON_VERSION "${PythonVersion}"
  33. !else
  34. !define PYTHON_VERSION "3"
  35. !endif
  36. !if "$%PROCESSOR_ARCHITECTURE%" == "AMD64"
  37. !define CPUARCH "AMD64"
  38. !else if "$%PROCESSOR_ARCHITEW6432%" == "AMD64"
  39. !define CPUARCH "AMD64"
  40. !else
  41. !define CPUARCH "x86"
  42. !endif
  43. # Part of the Trim function for Strings
  44. !define Trim "!insertmacro Trim"
  45. !macro Trim ResultVar String
  46. Push "${String}"
  47. Call Trim
  48. Pop "${ResultVar}"
  49. !macroend
  50. # Part of the Explode function for Strings
  51. !define Explode "!insertmacro Explode"
  52. !macro Explode Length Separator String
  53. Push `${Separator}`
  54. Push `${String}`
  55. Call Explode
  56. Pop `${Length}`
  57. !macroend
  58. ###############################################################################
  59. # Configure Pages, Ordering, and Configuration
  60. ###############################################################################
  61. !define MUI_ABORTWARNING
  62. !define MUI_ICON "salt.ico"
  63. !define MUI_UNICON "salt.ico"
  64. !define MUI_WELCOMEFINISHPAGE_BITMAP "panel.bmp"
  65. !define MUI_UNWELCOMEFINISHPAGE_BITMAP "panel.bmp"
  66. # Welcome page
  67. !insertmacro MUI_PAGE_WELCOME
  68. # License page
  69. !insertmacro MUI_PAGE_LICENSE "LICENSE.txt"
  70. # Configure Minion page
  71. Page custom pageMinionConfig pageMinionConfig_Leave
  72. # Instfiles page
  73. !insertmacro MUI_PAGE_INSTFILES
  74. # Finish page (Customized)
  75. !define MUI_PAGE_CUSTOMFUNCTION_SHOW pageFinish_Show
  76. !define MUI_PAGE_CUSTOMFUNCTION_LEAVE pageFinish_Leave
  77. !insertmacro MUI_PAGE_FINISH
  78. # Uninstaller pages
  79. !insertmacro MUI_UNPAGE_INSTFILES
  80. # Language files
  81. !insertmacro MUI_LANGUAGE "English"
  82. ###############################################################################
  83. # Custom Dialog Box Variables
  84. ###############################################################################
  85. Var Dialog
  86. Var Label
  87. Var CheckBox_Minion_Start
  88. Var CheckBox_Minion_Start_Delayed
  89. Var ConfigMasterHost
  90. Var MasterHost
  91. Var MasterHost_State
  92. Var ConfigMinionName
  93. Var MinionName
  94. Var MinionName_State
  95. Var ExistingConfigFound
  96. Var ConfigType
  97. Var ConfigType_State
  98. Var CustomConfig
  99. Var CustomConfig_btn
  100. Var CustomConfig_State
  101. Var WarningCustomConfig
  102. Var WarningExistingConfig
  103. Var WarningDefaultConfig
  104. Var StartMinion
  105. Var StartMinionDelayed
  106. Var DeleteInstallDir
  107. Var ConfigWriteMinion
  108. Var ConfigWriteMaster
  109. ###############################################################################
  110. # Minion Settings Dialog Box
  111. ###############################################################################
  112. Function pageMinionConfig
  113. # Set Page Title and Description
  114. !insertmacro MUI_HEADER_TEXT "Minion Settings" "Set the Minion Master and ID"
  115. nsDialogs::Create 1018
  116. Pop $Dialog
  117. ${If} $Dialog == error
  118. Abort
  119. ${EndIf}
  120. # Master IP or Hostname Dialog Control
  121. ${NSD_CreateLabel} 0 0 100% 12u "Master IP or Hostname:"
  122. Pop $Label
  123. ${NSD_CreateText} 0 13u 100% 12u $MasterHost_State
  124. Pop $MasterHost
  125. # Minion ID Dialog Control
  126. ${NSD_CreateLabel} 0 30u 100% 12u "Minion Name:"
  127. Pop $Label
  128. ${NSD_CreateText} 0 43u 100% 12u $MinionName_State
  129. Pop $MinionName
  130. # Config Drop List
  131. ${NSD_CreateDropList} 0 65u 25% 36u ""
  132. Pop $ConfigType
  133. ${NSD_CB_AddString} $ConfigType "Default Config"
  134. ${NSD_CB_AddString} $ConfigType "Custom Config"
  135. ${NSD_OnChange} $ConfigType pageMinionConfig_OnChange
  136. # Add Existing Config Warning Label
  137. ${NSD_CreateLabel} 0 80u 100% 60u "The values above are taken from an \
  138. existing configuration found in `c:\salt\conf\minion`. Configuration \
  139. settings defined in the `minion.d` directories, if they exist, are not \
  140. shown here.$\r$\n\
  141. $\r$\n\
  142. Clicking `Install` will leave the existing config unchanged."
  143. Pop $WarningExistingConfig
  144. CreateFont $0 "Arial" 10 500 /ITALIC
  145. SendMessage $WarningExistingConfig ${WM_SETFONT} $0 1
  146. SetCtlColors $WarningExistingConfig 0xBB0000 transparent
  147. # Add Default Config Warning Label
  148. ${NSD_CreateLabel} 0 80u 100% 60u "Clicking `Install` will backup the \
  149. the existing minion config file and minion.d directories. The values \
  150. above will be used in the new default config.$\r$\n\
  151. $\r$\n\
  152. NOTE: If Master IP is set to `salt` and Minion Name is set to \
  153. `hostname` no changes will be made."
  154. Pop $WarningDefaultConfig
  155. CreateFont $0 "Arial" 10 500 /ITALIC
  156. SendMessage $WarningDefaultConfig ${WM_SETFONT} $0 1
  157. SetCtlColors $WarningDefaultConfig 0xBB0000 transparent
  158. # Add Custom Config File Selector and Warning Label
  159. ${NSD_CreateText} 26% 65u 64% 12u $CustomConfig_State
  160. Pop $CustomConfig
  161. ${NSD_CreateButton} 91% 65u 9% 12u "..."
  162. Pop $CustomConfig_btn
  163. ${NSD_OnClick} $CustomConfig_btn pageCustomConfigBtn_OnClick
  164. ${If} $ExistingConfigFound == 0
  165. ${NSD_CreateLabel} 0 80u 100% 60u "Values entered above will be used \
  166. in the custom config.$\r$\n\
  167. $\r$\n\
  168. NOTE: If Master IP is set to `salt` and Minion Name is set to \
  169. `hostname` no changes will be made."
  170. ${Else}
  171. ${NSD_CreateLabel} 0 80u 100% 60u "Clicking `Install` will backup the \
  172. the existing minion config file and minion.d directories. The \
  173. values above will be used in the custom config.$\r$\n\
  174. $\r$\n\
  175. NOTE: If Master IP is set to `salt` and Minion Name is set to \
  176. `hostname` no changes will be made."
  177. ${Endif}
  178. Pop $WarningCustomConfig
  179. CreateFont $0 "Arial" 10 500 /ITALIC
  180. SendMessage $WarningCustomConfig ${WM_SETFONT} $0 1
  181. SetCtlColors $WarningCustomConfig 0xBB0000 transparent
  182. # If existing config found, add the Existing Config option to the Drop List
  183. # If not, hide the Default Warning
  184. ${If} $ExistingConfigFound == 1
  185. ${NSD_CB_AddString} $ConfigType "Existing Config"
  186. ${Else}
  187. ShowWindow $WarningDefaultConfig ${SW_HIDE}
  188. ${Endif}
  189. ${NSD_CB_SelectString} $ConfigType $ConfigType_State
  190. ${NSD_SetText} $CustomConfig $CustomConfig_State
  191. Call pageMinionConfig_OnChange
  192. nsDialogs::Show
  193. FunctionEnd
  194. Function pageMinionConfig_OnChange
  195. # You have to pop the top handle to keep the stack clean
  196. Pop $R0
  197. # Assign the current checkbox state to the variable
  198. ${NSD_GetText} $ConfigType $ConfigType_State
  199. # Update Dialog
  200. ${Switch} $ConfigType_State
  201. ${Case} "Existing Config"
  202. # Enable Master/Minion and set values
  203. EnableWindow $MasterHost 0
  204. EnableWindow $MinionName 0
  205. ${NSD_SetText} $MasterHost $ConfigMasterHost
  206. ${NSD_SetText} $MinionName $ConfigMinionName
  207. # Hide Custom File Picker
  208. ShowWindow $CustomConfig ${SW_HIDE}
  209. ShowWindow $CustomConfig_btn ${SW_HIDE}
  210. # Hide Warnings
  211. ShowWindow $WarningDefaultConfig ${SW_HIDE}
  212. ShowWindow $WarningCustomConfig ${SW_HIDE}
  213. # Show Existing Warning
  214. ShowWindow $WarningExistingConfig ${SW_SHOW}
  215. ${Break}
  216. ${Case} "Custom Config"
  217. # Enable Master/Minion and set values
  218. EnableWindow $MasterHost 1
  219. EnableWindow $MinionName 1
  220. ${NSD_SetText} $MasterHost $MasterHost_State
  221. ${NSD_SetText} $MinionName $MinionName_State
  222. # Show Custom File Picker
  223. ShowWindow $CustomConfig ${SW_SHOW}
  224. ShowWindow $CustomConfig_btn ${SW_SHOW}
  225. # Hide Warnings
  226. ShowWindow $WarningDefaultConfig ${SW_HIDE}
  227. ShowWindow $WarningExistingConfig ${SW_HIDE}
  228. # Show Custom Warning
  229. ShowWindow $WarningCustomConfig ${SW_SHOW}
  230. ${Break}
  231. ${Case} "Default Config"
  232. # Enable Master/Minion and set values
  233. EnableWindow $MasterHost 1
  234. EnableWindow $MinionName 1
  235. ${NSD_SetText} $MasterHost $MasterHost_State
  236. ${NSD_SetText} $MinionName $MinionName_State
  237. # Hide Custom File Picker
  238. ShowWindow $CustomConfig ${SW_HIDE}
  239. ShowWindow $CustomConfig_btn ${SW_HIDE}
  240. # Hide Warnings
  241. ShowWindow $WarningExistingConfig ${SW_HIDE}
  242. ShowWindow $WarningCustomConfig ${SW_HIDE}
  243. # Show Default Warning, if there is an existing config
  244. ${If} $ExistingConfigFound == 1
  245. ShowWindow $WarningDefaultConfig ${SW_SHOW}
  246. ${Endif}
  247. ${Break}
  248. ${EndSwitch}
  249. FunctionEnd
  250. # File Picker Definitions
  251. !define OFN_FILEMUSTEXIST 0x00001000
  252. !define OFN_DONTADDTOREC 0x02000000
  253. !define OPENFILENAME_SIZE_VERSION_400 76
  254. !define OPENFILENAME 'i,i,i,i,i,i,i,i,i,i,i,i,i,i,&i2,&i2,i,i,i,i'
  255. Function pageCustomConfigBtn_OnClick
  256. Pop $0
  257. System::Call '*(&t${NSIS_MAX_STRLEN})i.s' # Allocate OPENFILENAME.lpstrFile buffer
  258. System::Call '*(${OPENFILENAME})i.r0' # Allocate OPENFILENAME struct
  259. System::Call '*$0(${OPENFILENAME})(${OPENFILENAME_SIZE_VERSION_400}, \
  260. $hwndparent, , , , , , sr1, ${NSIS_MAX_STRLEN} , , , , \
  261. t"Select Custom Config File", \
  262. ${OFN_FILEMUSTEXIST} | ${OFN_DONTADDTOREC})'
  263. # Populate file name field
  264. ${NSD_GetText} $CustomConfig $2
  265. System::Call "*$1(&t${NSIS_MAX_STRLEN}r2)" ; Set lpstrFile to the old path (if any)
  266. # Open the dialog
  267. System::Call 'COMDLG32::GetOpenFileName(ir0)i.r2'
  268. # Get file name field
  269. ${If} $2 <> 0
  270. System::Call "*$1(&t${NSIS_MAX_STRLEN}.r2)"
  271. ${NSD_SetText} $CustomConfig $2
  272. ${EndIf}
  273. # Free resources
  274. System::Free $1
  275. System::Free $0
  276. FunctionEnd
  277. Function pageMinionConfig_Leave
  278. # Save the State
  279. ${NSD_GetText} $MasterHost $MasterHost_State
  280. ${NSD_GetText} $MinionName $MinionName_State
  281. ${NSD_GetText} $ConfigType $ConfigType_State
  282. ${NSD_GetText} $CustomConfig $CustomConfig_State
  283. # Abort if config file not found
  284. ${If} $ConfigType_State == "Custom Config"
  285. IfFileExists "$CustomConfig_State" continue 0
  286. MessageBox MB_OK "File not found: $CustomConfig_State" /SD IDOK
  287. Abort
  288. ${EndIf}
  289. continue:
  290. Call BackupExistingConfig
  291. FunctionEnd
  292. ###############################################################################
  293. # Custom Finish Page
  294. ###############################################################################
  295. Function pageFinish_Show
  296. # Imports so the checkboxes will show up
  297. !define SWP_NOSIZE 0x0001
  298. !define SWP_NOMOVE 0x0002
  299. !define HWND_TOP 0x0000
  300. # Create Start Minion Checkbox
  301. ${NSD_CreateCheckbox} 120u 90u 100% 12u "&Start salt-minion"
  302. Pop $CheckBox_Minion_Start
  303. SetCtlColors $CheckBox_Minion_Start "" "ffffff"
  304. # This command required to bring the checkbox to the front
  305. System::Call "User32::SetWindowPos(i, i, i, i, i, i, i) b ($CheckBox_Minion_Start, ${HWND_TOP}, 0, 0, 0, 0, ${SWP_NOSIZE}|${SWP_NOMOVE})"
  306. # Create Start Minion Delayed ComboBox
  307. ${NSD_CreateCheckbox} 130u 102u 100% 12u "&Delayed Start"
  308. Pop $CheckBox_Minion_Start_Delayed
  309. SetCtlColors $CheckBox_Minion_Start_Delayed "" "ffffff"
  310. # This command required to bring the checkbox to the front
  311. System::Call "User32::SetWindowPos(i, i, i, i, i, i, i) b ($CheckBox_Minion_Start_Delayed, ${HWND_TOP}, 0, 0, 0, 0, ${SWP_NOSIZE}|${SWP_NOMOVE})"
  312. # Load current settings for Minion
  313. ${If} $StartMinion == 1
  314. ${NSD_Check} $CheckBox_Minion_Start
  315. ${EndIf}
  316. # Load current settings for Minion Delayed
  317. ${If} $StartMinionDelayed == 1
  318. ${NSD_Check} $CheckBox_Minion_Start_Delayed
  319. ${EndIf}
  320. FunctionEnd
  321. Function pageFinish_Leave
  322. # Assign the current checkbox states
  323. ${NSD_GetState} $CheckBox_Minion_Start $StartMinion
  324. ${NSD_GetState} $CheckBox_Minion_Start_Delayed $StartMinionDelayed
  325. FunctionEnd
  326. ###############################################################################
  327. # Installation Settings
  328. ###############################################################################
  329. Name "${PRODUCT_NAME} ${PRODUCT_VERSION} (Python ${PYTHON_VERSION})"
  330. OutFile "${OutFile}"
  331. InstallDir "c:\salt"
  332. InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
  333. ShowInstDetails show
  334. ShowUnInstDetails show
  335. Section -copy_prereqs
  336. # Copy prereqs to the Plugins Directory
  337. # These files are downloaded by build_pkg.bat
  338. # This directory gets removed upon completion
  339. SetOutPath "$PLUGINSDIR\"
  340. File /r "..\prereqs\"
  341. SectionEnd
  342. # Check if the Windows 10 Universal C Runtime (KB2999226) is installed
  343. # Python 3 needs the updated ucrt on Windows 8.1 / 2012R2 and lower
  344. # They are installed via KB2999226, but we're not going to patch the system here
  345. # Instead, we're going to copy the .dll files to the \salt\bin directory
  346. Section -install_ucrt
  347. Var /GLOBAL UcrtFileName
  348. # Get the Major.Minor version Number
  349. # Windows 10 introduced CurrentMajorVersionNumber
  350. ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" \
  351. CurrentMajorVersionNumber
  352. # Windows 10/2016 will return a value here, skip to the end if returned
  353. StrCmp $R0 '' lbl_needs_ucrt 0
  354. # Found Windows 10
  355. detailPrint "KB2999226 does not apply to this machine"
  356. goto lbl_done
  357. lbl_needs_ucrt:
  358. # UCRT only needed on Windows Server 2012R2/Windows 8.1 and below
  359. # The first ReadRegStr command above should have skipped to lbl_done if on
  360. # Windows 10 box
  361. # Is the update already installed
  362. ClearErrors
  363. # Use WMI to check if it's installed
  364. detailPrint "Checking for existing UCRT (KB2999226) installation"
  365. nsExec::ExecToStack 'cmd /q /c wmic qfe get hotfixid | findstr "^KB2999226"'
  366. # Clean up the stack
  367. Pop $R0 # Gets the ErrorCode
  368. Pop $R1 # Gets the stdout, which should be KB2999226 if it's installed
  369. # If it returned KB2999226 it's already installed
  370. StrCmp $R1 'KB2999226' lbl_done
  371. detailPrint "UCRT (KB2999226) not found"
  372. # Use RunningX64 here to get the Architecture for the system running the installer
  373. # CPUARCH is defined when the installer is built and is based on the machine that
  374. # built the installer, not the target system as we need here.
  375. ${If} ${RunningX64}
  376. StrCpy $UcrtFileName "ucrt_x64.zip"
  377. ${Else}
  378. StrCpy $UcrtFileName "ucrt_x86.zip"
  379. ${EndIf}
  380. ClearErrors
  381. detailPrint "Unzipping UCRT dll files to $INSTDIR\bin"
  382. CreateDirectory $INSTDIR\bin
  383. nsisunz::UnzipToLog "$PLUGINSDIR\$UcrtFileName" "$INSTDIR\bin"
  384. # Clean up the stack
  385. Pop $R0 # Get Error
  386. ${IfNot} $R0 == "success"
  387. detailPrint "error: $R0"
  388. Sleep 3000
  389. ${Else}
  390. detailPrint "UCRT dll files copied successfully"
  391. ${EndIf}
  392. lbl_done:
  393. SectionEnd
  394. # Check and install Visual C++ redist 2013 packages
  395. # Hidden section (-) to install VCRedist
  396. Section -install_vcredist_2013
  397. Var /GLOBAL VcRedistName
  398. Var /GLOBAL VcRedistGuid
  399. Var /GLOBAL NeedVcRedist
  400. # GUIDs can be found by installing them and then running the following command:
  401. # wmic product where "Name like '%2013%minimum runtime%'" get Name, Version, IdentifyingNumber
  402. !define VCREDIST_X86_NAME "vcredist_x86_2013"
  403. !define VCREDIST_X86_GUID "{8122DAB1-ED4D-3676-BB0A-CA368196543E}"
  404. !define VCREDIST_X64_NAME "vcredist_x64_2013"
  405. !define VCREDIST_X64_GUID "{53CF6934-A98D-3D84-9146-FC4EDF3D5641}"
  406. # Only install 64bit VCRedist on 64bit machines
  407. ${If} ${CPUARCH} == "AMD64"
  408. StrCpy $VcRedistName ${VCREDIST_X64_NAME}
  409. StrCpy $VcRedistGuid ${VCREDIST_X64_GUID}
  410. Call InstallVCRedist
  411. ${Else}
  412. # Install 32bit VCRedist on all machines
  413. StrCpy $VcRedistName ${VCREDIST_X86_NAME}
  414. StrCpy $VcRedistGuid ${VCREDIST_X86_GUID}
  415. Call InstallVCRedist
  416. ${EndIf}
  417. SectionEnd
  418. Function InstallVCRedist
  419. # Check to see if it's already installed
  420. Call MsiQueryProductState
  421. ${If} $NeedVcRedist == "True"
  422. detailPrint "System requires $VcRedistName"
  423. MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 \
  424. "$VcRedistName is currently not installed. Would you like to install?" \
  425. /SD IDYES IDNO endVCRedist
  426. # If an output variable is specified ($0 in the case below),
  427. # ExecWait sets the variable with the exit code (and only sets the
  428. # error flag if an error occurs; if an error occurs, the contents
  429. # of the user variable are undefined).
  430. # http://nsis.sourceforge.net/Reference/ExecWait
  431. ClearErrors
  432. detailPrint "Installing $VcRedistName..."
  433. ExecWait '"$PLUGINSDIR\$VcRedistName.exe" /install /quiet /norestart' $0
  434. IfErrors 0 CheckVcRedistErrorCode
  435. MessageBox MB_OK \
  436. "$VcRedistName failed to install. Try installing the package manually." \
  437. /SD IDOK
  438. detailPrint "An error occurred during installation of $VcRedistName"
  439. CheckVcRedistErrorCode:
  440. # Check for Reboot Error Code (3010)
  441. ${If} $0 == 3010
  442. MessageBox MB_OK \
  443. "$VcRedistName installed but requires a restart to complete." \
  444. /SD IDOK
  445. detailPrint "Reboot and run Salt install again"
  446. # Check for any other errors
  447. ${ElseIfNot} $0 == 0
  448. MessageBox MB_OK \
  449. "$VcRedistName failed with ErrorCode: $0. Try installing the package manually." \
  450. /SD IDOK
  451. detailPrint "An error occurred during installation of $VcRedistName"
  452. detailPrint "Error: $0"
  453. ${EndIf}
  454. endVCRedist:
  455. ${EndIf}
  456. FunctionEnd
  457. Section "MainSection" SEC01
  458. SetOutPath "$INSTDIR\"
  459. SetOverwrite off
  460. CreateDirectory $INSTDIR\conf\pki\minion
  461. CreateDirectory $INSTDIR\conf\minion.d
  462. File /r "..\buildenv\"
  463. nsExec::Exec 'icacls c:\salt /inheritance:r /grant:r "*S-1-5-32-544":(OI)(CI)F /grant:r "*S-1-5-18":(OI)(CI)F'
  464. SectionEnd
  465. Function .onInit
  466. InitPluginsDir
  467. Call parseCommandLineSwitches
  468. # Uninstall msi-installed salt
  469. # Source https://nsis-dev.github.io/NSIS-Forums/html/t-303468.html
  470. !define upgradecode {FC6FB3A2-65DE-41A9-AD91-D10A402BD641} ;Salt upgrade code
  471. StrCpy $0 0
  472. loop:
  473. System::Call 'MSI::MsiEnumRelatedProducts(t "${upgradecode}",i0,i r0,t.r1)i.r2'
  474. ${If} $2 = 0
  475. # Now $1 contains the product code
  476. DetailPrint product:$1
  477. push $R0
  478. StrCpy $R0 $1
  479. Call UninstallMSI
  480. pop $R0
  481. IntOp $0 $0 + 1
  482. goto loop
  483. ${Endif}
  484. # If custom config passed, verify its existence before continuing so we
  485. # don't uninstall an existing installation and then fail
  486. ${If} $ConfigType_State == "Custom Config"
  487. IfFileExists "$CustomConfig_State" customConfigExists 0
  488. Abort
  489. ${EndIf}
  490. customConfigExists:
  491. # Check for existing installation
  492. ReadRegStr $R0 HKLM \
  493. "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  494. "UninstallString"
  495. StrCmp $R0 "" checkOther
  496. # Found existing installation, prompt to uninstall
  497. MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
  498. "${PRODUCT_NAME} is already installed.$\n$\n\
  499. Click `OK` to remove the existing installation." \
  500. /SD IDOK IDOK uninst
  501. Abort
  502. checkOther:
  503. # Check for existing installation of full salt
  504. ReadRegStr $R0 HKLM \
  505. "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME_OTHER}" \
  506. "UninstallString"
  507. StrCmp $R0 "" skipUninstall
  508. # Found existing installation, prompt to uninstall
  509. MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
  510. "${PRODUCT_NAME_OTHER} is already installed.$\n$\n\
  511. Click `OK` to remove the existing installation." \
  512. /SD IDOK IDOK uninst
  513. Abort
  514. uninst:
  515. # Get current Silent status
  516. StrCpy $R0 0
  517. ${If} ${Silent}
  518. StrCpy $R0 1
  519. ${EndIf}
  520. # Turn on Silent mode
  521. SetSilent silent
  522. # Don't remove all directories
  523. StrCpy $DeleteInstallDir 0
  524. # Uninstall silently
  525. Call uninstallSalt
  526. # Set it back to Normal mode, if that's what it was before
  527. ${If} $R0 == 0
  528. SetSilent normal
  529. ${EndIf}
  530. skipUninstall:
  531. Call getExistingMinionConfig
  532. ${If} $ExistingConfigFound == 0
  533. ${AndIf} $ConfigType_State == "Existing Config"
  534. StrCpy $ConfigType_State "Default Config"
  535. ${EndIf}
  536. IfSilent 0 +2
  537. Call BackupExistingConfig
  538. FunctionEnd
  539. # Time Stamp Definition
  540. !define /date TIME_STAMP "%Y-%m-%d-%H-%M-%S"
  541. Function BackupExistingConfig
  542. ${If} $ExistingConfigFound == 1 # If existing config found
  543. ${AndIfNot} $ConfigType_State == "Existing Config" # If not using Existing Config
  544. # Backup the minion config
  545. Rename "$INSTDIR\conf\minion" "$INSTDIR\conf\minion-${TIME_STAMP}.bak"
  546. IfFileExists "$INSTDIR\conf\minion.d" 0 +2
  547. Rename "$INSTDIR\conf\minion.d" "$INSTDIR\conf\minion.d-${TIME_STAMP}.bak"
  548. ${EndIf}
  549. # By this point there should be no existing config
  550. # It was either backed up or wasn't there to begin with
  551. ${If} $ConfigType_State == "Custom Config" # If we're using Custom Config
  552. ${AndIfNot} $CustomConfig_State == "" # If a custom config is passed
  553. # Check for a file name
  554. # Named file should be in the same directory as the installer
  555. CreateDirectory "$INSTDIR\conf"
  556. IfFileExists "$EXEDIR\$CustomConfig_State" 0 checkFullPath
  557. CopyFiles /SILENT /FILESONLY "$EXEDIR\$CustomConfig_State" "$INSTDIR\conf\minion"
  558. goto finished
  559. # Maybe it was a full path to a file
  560. checkFullPath:
  561. IfFileExists "$CustomConfig_State" 0 finished
  562. CopyFiles /SILENT /FILESONLY "$CustomConfig_State" "$INSTDIR\conf\minion"
  563. finished:
  564. ${EndIf}
  565. FunctionEnd
  566. Section -Post
  567. WriteUninstaller "$INSTDIR\uninst.exe"
  568. # Uninstall Registry Entries
  569. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
  570. "DisplayName" "$(^Name)"
  571. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
  572. "UninstallString" "$INSTDIR\uninst.exe"
  573. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
  574. "DisplayIcon" "$INSTDIR\salt.ico"
  575. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
  576. "DisplayVersion" "${PRODUCT_VERSION}"
  577. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
  578. "URLInfoAbout" "${PRODUCT_WEB_SITE}"
  579. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
  580. "Publisher" "${PRODUCT_PUBLISHER}"
  581. WriteRegStr HKLM "SYSTEM\CurrentControlSet\services\salt-minion" \
  582. "DependOnService" "nsi"
  583. # Set the estimated size
  584. ${GetSize} "$INSTDIR\bin" "/S=OK" $0 $1 $2
  585. IntFmt $0 "0x%08X" $0
  586. WriteRegDWORD ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
  587. "EstimatedSize" "$0"
  588. # Commandline Registry Entries
  589. WriteRegStr HKLM "${PRODUCT_CALL_REGKEY}" "" "$INSTDIR\salt-call.bat"
  590. WriteRegStr HKLM "${PRODUCT_CALL_REGKEY}" "Path" "$INSTDIR\bin\"
  591. WriteRegStr HKLM "${PRODUCT_MINION_REGKEY}" "" "$INSTDIR\salt-minion.bat"
  592. WriteRegStr HKLM "${PRODUCT_MINION_REGKEY}" "Path" "$INSTDIR\bin\"
  593. # Register the Salt-Minion Service
  594. nsExec::Exec "$INSTDIR\bin\ssm.exe install salt-minion $INSTDIR\bin\python.exe -E -s $INSTDIR\bin\Scripts\salt-minion -c $INSTDIR\conf -l quiet"
  595. nsExec::Exec "$INSTDIR\bin\ssm.exe set salt-minion Description Salt Minion from saltstack.com"
  596. nsExec::Exec "$INSTDIR\bin\ssm.exe set salt-minion Start SERVICE_AUTO_START"
  597. nsExec::Exec "$INSTDIR\bin\ssm.exe set salt-minion AppStopMethodConsole 24000"
  598. nsExec::Exec "$INSTDIR\bin\ssm.exe set salt-minion AppStopMethodWindow 2000"
  599. ${IfNot} $ConfigType_State == "Existing Config" # If not using Existing Config
  600. Call updateMinionConfig
  601. ${EndIf}
  602. # Add $INSTDIR in the Path
  603. EnVar::SetHKLM
  604. EnVar::AddValue Path "$INSTDIR"
  605. SectionEnd
  606. Function .onInstSuccess
  607. # If StartMinionDelayed is 1, then set the service to start delayed
  608. ${If} $StartMinionDelayed == 1
  609. nsExec::Exec "$INSTDIR\bin\ssm.exe set salt-minion Start SERVICE_DELAYED_AUTO_START"
  610. ${EndIf}
  611. # If start-minion is 1, then start the service
  612. ${If} $StartMinion == 1
  613. nsExec::Exec 'net start salt-minion'
  614. ${EndIf}
  615. FunctionEnd
  616. Function un.onInit
  617. # Load the parameters
  618. ${GetParameters} $R0
  619. # Uninstaller: Remove Installation Directory
  620. ClearErrors
  621. ${GetOptions} $R0 "/delete-install-dir" $R1
  622. IfErrors delete_install_dir_not_found
  623. StrCpy $DeleteInstallDir 1
  624. delete_install_dir_not_found:
  625. MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 \
  626. "Are you sure you want to completely remove $(^Name) and all of its components?" \
  627. /SD IDYES IDYES +2
  628. Abort
  629. FunctionEnd
  630. Section Uninstall
  631. Call un.uninstallSalt
  632. # Remove $INSTDIR from the Path
  633. EnVar::SetHKLM
  634. EnVar::DeleteValue Path "$INSTDIR"
  635. SectionEnd
  636. !macro uninstallSalt un
  637. Function ${un}uninstallSalt
  638. # Make sure we're in the right directory
  639. ${If} $INSTDIR == "c:\salt\bin\Scripts"
  640. StrCpy $INSTDIR "C:\salt"
  641. ${EndIf}
  642. # Stop and Remove salt-minion service
  643. nsExec::Exec 'net stop salt-minion'
  644. nsExec::Exec 'sc delete salt-minion'
  645. # Stop and remove the salt-master service
  646. nsExec::Exec 'net stop salt-master'
  647. nsExec::Exec 'sc delete salt-master'
  648. # Remove files
  649. Delete "$INSTDIR\uninst.exe"
  650. Delete "$INSTDIR\ssm.exe"
  651. Delete "$INSTDIR\salt*"
  652. Delete "$INSTDIR\vcredist.exe"
  653. RMDir /r "$INSTDIR\bin"
  654. # Remove Registry entries
  655. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  656. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY_OTHER}"
  657. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_CALL_REGKEY}"
  658. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_CP_REGKEY}"
  659. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_KEY_REGKEY}"
  660. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_MASTER_REGKEY}"
  661. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_MINION_REGKEY}"
  662. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_RUN_REGKEY}"
  663. # Automatically close when finished
  664. SetAutoClose true
  665. # Prompt to remove the Installation directory
  666. ${IfNot} $DeleteInstallDir == 1
  667. MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 \
  668. "Would you like to completely remove $INSTDIR and all of its contents?" \
  669. /SD IDNO IDNO finished
  670. ${EndIf}
  671. # Make sure you're not removing Program Files
  672. ${If} $INSTDIR != 'Program Files'
  673. ${AndIf} $INSTDIR != 'Program Files (x86)'
  674. RMDir /r "$INSTDIR"
  675. ${EndIf}
  676. finished:
  677. FunctionEnd
  678. !macroend
  679. !insertmacro uninstallSalt ""
  680. !insertmacro uninstallSalt "un."
  681. Function un.onUninstSuccess
  682. HideWindow
  683. MessageBox MB_ICONINFORMATION|MB_OK \
  684. "$(^Name) was successfully removed from your computer." \
  685. /SD IDOK
  686. FunctionEnd
  687. ###############################################################################
  688. # Helper Functions
  689. ###############################################################################
  690. Function MsiQueryProductState
  691. # Used for detecting VCRedist Installation
  692. !define INSTALLSTATE_DEFAULT "5"
  693. StrCpy $NeedVcRedist "False"
  694. System::Call "msi::MsiQueryProductStateA(t '$VcRedistGuid') i.r0"
  695. StrCmp $0 ${INSTALLSTATE_DEFAULT} +2 0
  696. StrCpy $NeedVcRedist "True"
  697. FunctionEnd
  698. #------------------------------------------------------------------------------
  699. # Trim Function
  700. # - Trim whitespace from the beginning and end of a string
  701. # - Trims spaces, \r, \n, \t
  702. #
  703. # Usage:
  704. # Push " some string " ; String to Trim
  705. # Call Trim
  706. # Pop $0 ; Trimmed String: "some string"
  707. #
  708. # or
  709. #
  710. # ${Trim} $0 $1 ; Trimmed String, String to Trim
  711. #------------------------------------------------------------------------------
  712. Function Trim
  713. Exch $R1 # Original string
  714. Push $R2
  715. Loop:
  716. StrCpy $R2 "$R1" 1
  717. StrCmp "$R2" " " TrimLeft
  718. StrCmp "$R2" "$\r" TrimLeft
  719. StrCmp "$R2" "$\n" TrimLeft
  720. StrCmp "$R2" "$\t" TrimLeft
  721. GoTo Loop2
  722. TrimLeft:
  723. StrCpy $R1 "$R1" "" 1
  724. Goto Loop
  725. Loop2:
  726. StrCpy $R2 "$R1" 1 -1
  727. StrCmp "$R2" " " TrimRight
  728. StrCmp "$R2" "$\r" TrimRight
  729. StrCmp "$R2" "$\n" TrimRight
  730. StrCmp "$R2" "$\t" TrimRight
  731. GoTo Done
  732. TrimRight:
  733. StrCpy $R1 "$R1" -1
  734. Goto Loop2
  735. Done:
  736. Pop $R2
  737. Exch $R1
  738. FunctionEnd
  739. #------------------------------------------------------------------------------
  740. # Explode Function
  741. # - Splits a string based off the passed separator
  742. # - Each item in the string is pushed to the stack
  743. # - The last item pushed to the stack is the length of the array
  744. #
  745. # Usage:
  746. # Push "," ; Separator
  747. # Push "string,to,separate" ; String to explode
  748. # Call Explode
  749. # Pop $0 ; Number of items in the array
  750. #
  751. # or
  752. #
  753. # ${Explode} $0 $1 $2 ; Length, Separator, String
  754. #------------------------------------------------------------------------------
  755. Function Explode
  756. # Initialize variables
  757. Var /GLOBAL explString
  758. Var /GLOBAL explSeparator
  759. Var /GLOBAL explStrLen
  760. Var /GLOBAL explSepLen
  761. Var /GLOBAL explOffset
  762. Var /GLOBAL explTmp
  763. Var /GLOBAL explTmp2
  764. Var /GLOBAL explTmp3
  765. Var /GLOBAL explArrCount
  766. # Get input from user
  767. Pop $explString
  768. Pop $explSeparator
  769. # Calculates initial values
  770. StrLen $explStrLen $explString
  771. StrLen $explSepLen $explSeparator
  772. StrCpy $explArrCount 1
  773. ${If} $explStrLen <= 1 # If we got a single character
  774. ${OrIf} $explSepLen > $explStrLen # or separator is larger than the string,
  775. Push $explString # then we return initial string with no change
  776. Push 1 # and set array's length to 1
  777. Return
  778. ${EndIf}
  779. # Set offset to the last symbol of the string
  780. StrCpy $explOffset $explStrLen
  781. IntOp $explOffset $explOffset - 1
  782. # Clear temp string to exclude the possibility of appearance of occasional data
  783. StrCpy $explTmp ""
  784. StrCpy $explTmp2 ""
  785. StrCpy $explTmp3 ""
  786. # Loop until the offset becomes negative
  787. ${Do}
  788. # If offset becomes negative, it is time to leave the function
  789. ${IfThen} $explOffset == -1 ${|} ${ExitDo} ${|}
  790. # Remove everything before and after the searched part ("TempStr")
  791. StrCpy $explTmp $explString $explSepLen $explOffset
  792. ${If} $explTmp == $explSeparator
  793. # Calculating offset to start copy from
  794. IntOp $explTmp2 $explOffset + $explSepLen # Offset equals to the current offset plus length of separator
  795. StrCpy $explTmp3 $explString "" $explTmp2
  796. Push $explTmp3 # Throwing array item to the stack
  797. IntOp $explArrCount $explArrCount + 1 # Increasing array's counter
  798. StrCpy $explString $explString $explOffset 0 # Cutting all characters beginning with the separator entry
  799. StrLen $explStrLen $explString
  800. ${EndIf}
  801. ${If} $explOffset = 0 # If the beginning of the line met and there is no separator,
  802. # copying the rest of the string
  803. ${If} $explSeparator == "" # Fix for the empty separator
  804. IntOp $explArrCount $explArrCount - 1
  805. ${Else}
  806. Push $explString
  807. ${EndIf}
  808. ${EndIf}
  809. IntOp $explOffset $explOffset - 1
  810. ${Loop}
  811. Push $explArrCount
  812. FunctionEnd
  813. #------------------------------------------------------------------------------
  814. # UninstallMSI Function
  815. # - Uninstalls MSI by product code
  816. #
  817. # Usage:
  818. # Push product code
  819. # Call UninstallMSI
  820. #
  821. # Source:
  822. # https://nsis.sourceforge.io/Uninstalling_a_previous_MSI_(Windows_installer_package)
  823. #------------------------------------------------------------------------------
  824. Function UninstallMSI
  825. ; $R0 === product code
  826. MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
  827. "${PRODUCT_NAME} is already installed via MSI.$\n$\n\
  828. Click `OK` to remove the existing installation." \
  829. /SD IDOK IDOK UninstallMSI
  830. Abort
  831. UninstallMSI:
  832. ExecWait '"msiexec.exe" /x $R0 /qb /quiet /norestart'
  833. FunctionEnd
  834. ###############################################################################
  835. # Specialty Functions
  836. ###############################################################################
  837. Function getExistingMinionConfig
  838. # Set Config Found Default Value
  839. StrCpy $ExistingConfigFound 0
  840. confFind:
  841. IfFileExists "$INSTDIR\conf\minion" confFound confNotFound
  842. confNotFound:
  843. ${If} $INSTDIR == "c:\salt\bin\Scripts"
  844. StrCpy $INSTDIR "C:\salt"
  845. goto confFind
  846. ${Else}
  847. goto confReallyNotFound
  848. ${EndIf}
  849. confFound:
  850. StrCpy $ExistingConfigFound 1
  851. FileOpen $0 "$INSTDIR\conf\minion" r
  852. confLoop:
  853. ClearErrors # clear Errors
  854. FileRead $0 $1 # read the next line
  855. IfErrors EndOfFile # error is probably EOF
  856. ${StrLoc} $2 $1 "master:" ">" # find `master:` starting at the beginning
  857. ${If} $2 == 0 # if it found it in the first position, then it is defined
  858. ${StrStrAdv} $2 $1 "master: " ">" ">" "0" "0" "0" # read everything after `master: `
  859. ${Trim} $2 $2 # trim white space
  860. ${If} $2 == "" # if it's empty, it's probably a list of masters
  861. masterLoop:
  862. ClearErrors # clear Errors
  863. FileRead $0 $1 # read the next line
  864. IfErrors EndOfFile # error is probably EOF
  865. ${StrStrAdv} $2 $1 "- " ">" ">" "0" "0" "0" # read everything after `- `
  866. ${Trim} $2 $2 # trim white space
  867. ${IfNot} $2 == "" # if the line is not empty, we found something
  868. ${If} $ConfigMasterHost == "" # if the config setting is empty
  869. StrCpy $ConfigMasterHost $2 # make the first item the new entry
  870. ${Else}
  871. StrCpy $ConfigMasterHost "$ConfigMasterHost,$2" # Append the new master, comma separated
  872. ${EndIf}
  873. Goto masterLoop # check the next one
  874. ${EndIf}
  875. ${Else}
  876. StrCpy $ConfigMasterHost $2 # a single master entry
  877. ${EndIf}
  878. ${EndIf}
  879. ${StrLoc} $2 $1 "id:" ">"
  880. ${If} $2 == 0
  881. ${StrStrAdv} $2 $1 "id: " ">" ">" "0" "0" "0"
  882. ${Trim} $2 $2
  883. StrCpy $ConfigMinionName $2
  884. ${EndIf}
  885. Goto confLoop
  886. EndOfFile:
  887. FileClose $0
  888. confReallyNotFound:
  889. # Set Default Config Values if not found
  890. ${If} $ConfigMasterHost == ""
  891. StrCpy $ConfigMasterHost "salt"
  892. ${EndIf}
  893. ${If} $ConfigMinionName == ""
  894. StrCpy $ConfigMinionName "hostname"
  895. ${EndIf}
  896. FunctionEnd
  897. Var cfg_line
  898. Var chk_line
  899. Var lst_check
  900. Function updateMinionConfig
  901. ClearErrors
  902. FileOpen $0 "$INSTDIR\conf\minion" "r" # open target file for reading
  903. GetTempFileName $R0 # get new temp file name
  904. FileOpen $1 $R0 "w" # open temp file for writing
  905. StrCpy $ConfigWriteMaster 1 # write the master config value
  906. StrCpy $ConfigWriteMinion 1 # write the minion config value
  907. loop: # loop through each line
  908. FileRead $0 $cfg_line # read line from target file
  909. IfErrors done # end if errors are encountered (end of line)
  910. loop_after_read:
  911. StrCpy $lst_check 0 # list check not performed
  912. ${If} $MasterHost_State == "" # if master is empty
  913. ${OrIf} $MasterHost_State == "salt" # or if master is 'salt'
  914. StrCpy $ConfigWriteMaster 0 # no need to write master config
  915. ${EndIf} # close if statement
  916. ${If} $MinionName_State == "" # if minion is empty
  917. ${OrIf} $MinionName_State == "hostname" # and if minion is not 'hostname'
  918. StrCpy $ConfigWriteMinion 0 # no need to write minion config
  919. ${EndIf} # close if statement
  920. ${If} $ConfigWriteMaster == 1 # if we need to write master config
  921. ${StrLoc} $3 $cfg_line "master:" ">" # where is 'master:' in this line
  922. ${If} $3 == 0 # is it in the first...
  923. ${OrIf} $3 == 1 # or second position (account for comments)
  924. ${Explode} $9 "," $MasterHost_state # Split the hostname on commas, $9 is the number of items found
  925. ${If} $9 == 1 # 1 means only a single master was passed
  926. StrCpy $cfg_line "master: $MasterHost_State$\r$\n" # write the master
  927. ${Else} # make a multi-master entry
  928. StrCpy $cfg_line "master:" # make the first line "master:"
  929. loop_explode: # start a loop to go through the list in the config
  930. pop $8 # pop the next item off the stack
  931. ${Trim} $8 $8 # trim any whitespace
  932. StrCpy $cfg_line "$cfg_line$\r$\n - $8" # add it to the master variable ($2)
  933. IntOp $9 $9 - 1 # decrement the list count
  934. ${If} $9 >= 1 # if it's not 0
  935. Goto loop_explode # do it again
  936. ${EndIf} # close if statement
  937. StrCpy $cfg_line "$cfg_line$\r$\n" # Make sure there's a new line at the end
  938. # Remove remaining items in list
  939. ${While} $lst_check == 0 # while list item found
  940. FileRead $0 $chk_line # read line from target file
  941. IfErrors done # end if errors are encountered (end of line)
  942. ${StrLoc} $3 $chk_line " - " ">" # where is 'master:' in this line
  943. ${If} $3 == "" # is it in the first...
  944. StrCpy $lst_check 1 # list check performed and finished
  945. ${EndIf}
  946. ${EndWhile}
  947. ${EndIf} # close if statement
  948. StrCpy $ConfigWriteMaster 0 # master value written to config
  949. ${EndIf} # close if statement
  950. ${EndIf} # close if statement
  951. ${If} $ConfigWriteMinion == 1 # if we need to write minion config
  952. ${StrLoc} $3 $cfg_line "id:" ">" # where is 'id:' in this line
  953. ${If} $3 == 0 # is it in the first...
  954. ${OrIf} $3 == 1 # or the second position (account for comments)
  955. StrCpy $cfg_line "id: $MinionName_State$\r$\n" # write the minion config setting
  956. StrCpy $ConfigWriteMinion 0 # minion value written to config
  957. ${EndIf} # close if statement
  958. ${EndIf} # close if statement
  959. FileWrite $1 $cfg_line # write changed or unchanged line to temp file
  960. ${If} $lst_check == 1 # master not written to the config
  961. StrCpy $cfg_line $chk_line
  962. Goto loop_after_read # A loop was performed, skip the next read
  963. ${EndIf} # close if statement
  964. Goto loop # check the next line in the config file
  965. done:
  966. ClearErrors
  967. # Does master config still need to be written
  968. ${If} $ConfigWriteMaster == 1 # master not written to the config
  969. ${Explode} $9 "," $MasterHost_state # split the hostname on commas, $9 is the number of items found
  970. ${If} $9 == 1 # 1 means only a single master was passed
  971. StrCpy $cfg_line "master: $MasterHost_State" # write the master
  972. ${Else} # make a multi-master entry
  973. StrCpy $cfg_line "master:" # make the first line "master:"
  974. loop_explode_2: # start a loop to go through the list in the config
  975. pop $8 # pop the next item off the stack
  976. ${Trim} $8 $8 # trim any whitespace
  977. StrCpy $cfg_line "$cfg_line$\r$\n - $8" # add it to the master variable ($2)
  978. IntOp $9 $9 - 1 # decrement the list count
  979. ${If} $9 >= 1 # if it's not 0
  980. Goto loop_explode_2 # do it again
  981. ${EndIf} # close if statement
  982. ${EndIf} # close if statement
  983. FileWrite $1 $cfg_line # write changed or unchanged line to temp file
  984. ${EndIf} # close if statement
  985. ${If} $ConfigWriteMinion == 1 # minion ID not written to the config
  986. StrCpy $cfg_line "$\r$\nid: $MinionName_State" # write the minion config setting
  987. FileWrite $1 $cfg_line # write changed or unchanged line to temp file
  988. ${EndIf} # close if statement
  989. FileClose $0 # close target file
  990. FileClose $1 # close temp file
  991. Delete "$INSTDIR\conf\minion" # delete target file
  992. CopyFiles /SILENT $R0 "$INSTDIR\conf\minion" # copy temp file to target file
  993. Delete $R0 # delete temp file
  994. FunctionEnd
  995. Function parseCommandLineSwitches
  996. # Load the parameters
  997. ${GetParameters} $R0
  998. # Display Help
  999. ClearErrors
  1000. ${GetOptions} $R0 "/?" $R1
  1001. IfErrors display_help_not_found
  1002. System::Call 'kernel32::GetStdHandle(i -11)i.r0'
  1003. System::Call 'kernel32::AttachConsole(i -1)i.r1'
  1004. ${If} $0 = 0
  1005. ${OrIf} $1 = 0
  1006. System::Call 'kernel32::AllocConsole()'
  1007. System::Call 'kernel32::GetStdHandle(i -11)i.r0'
  1008. ${EndIf}
  1009. FileWrite $0 "$\n"
  1010. FileWrite $0 "$\n"
  1011. FileWrite $0 "Help for Salt Minion installation$\n"
  1012. FileWrite $0 "===============================================================================$\n"
  1013. FileWrite $0 "$\n"
  1014. FileWrite $0 "/minion-name=$\t$\tA string value to set the minion name. Default value is$\n"
  1015. FileWrite $0 "$\t$\t$\t'hostname'. Setting the minion name causes the installer$\n"
  1016. FileWrite $0 "$\t$\t$\tto use the default config or a custom config if defined$\n"
  1017. FileWrite $0 "$\n"
  1018. FileWrite $0 "/master=$\t$\tA string value to set the IP address or hostname of the$\n"
  1019. FileWrite $0 "$\t$\t$\tmaster. Default value is 'salt'. You may pass a single$\n"
  1020. FileWrite $0 "$\t$\t$\tmaster or a comma-separated list of masters. Setting$\n"
  1021. FileWrite $0 "$\t$\t$\tthe master will cause the installer to use the default$\n"
  1022. FileWrite $0 "$\t$\t$\tconfig or a custom config if defined$\n"
  1023. FileWrite $0 "$\n"
  1024. FileWrite $0 "/start-minion=$\t$\t1 will start the minion service, 0 will not.$\n"
  1025. FileWrite $0 "$\t$\t$\tDefault is 1$\n"
  1026. FileWrite $0 "$\n"
  1027. FileWrite $0 "/start-minion-delayed$\tSet the minion start type to 'Automatic (Delayed Start)'$\n"
  1028. FileWrite $0 "$\n"
  1029. FileWrite $0 "/default-config$\t$\tOverwrite the existing config if present with the$\n"
  1030. FileWrite $0 "$\t$\t$\tdefault config for salt. Default is to use the existing$\n"
  1031. FileWrite $0 "$\t$\t$\tconfig if present. If /master and/or /minion-name is$\n"
  1032. FileWrite $0 "$\t$\t$\tpassed, those values will be used to update the new$\n"
  1033. FileWrite $0 "$\t$\t$\tdefault config$\n"
  1034. FileWrite $0 "$\n"
  1035. FileWrite $0 "$\t$\t$\tAny existing config will be backed up by appending$\n"
  1036. FileWrite $0 "$\t$\t$\ta timestamp and a .bak extension. That includes\n"
  1037. FileWrite $0 "$\t$\t$\tthe minion file and the minion.d directory$\n"
  1038. FileWrite $0 "$\n"
  1039. FileWrite $0 "/custom-config=$\t$\tA string value specifying the name of a custom config$\n"
  1040. FileWrite $0 "$\t$\t$\tfile in the same path as the installer or the full path$\n"
  1041. FileWrite $0 "$\t$\t$\tto a custom config file. If /master and/or /minion-name$\n"
  1042. FileWrite $0 "$\t$\t$\tis passed, those values will be used to update the new$\n"
  1043. FileWrite $0 "$\t$\t$\tcustom config$\n"
  1044. FileWrite $0 "$\n"
  1045. FileWrite $0 "$\t$\t$\tAny existing config will be backed up by appending$\n"
  1046. FileWrite $0 "$\t$\t$\ta timestamp and a .bak extension. That includes\n"
  1047. FileWrite $0 "$\t$\t$\tthe minion file and the minion.d directory$\n"
  1048. FileWrite $0 "$\n"
  1049. FileWrite $0 "/S$\t$\t$\tInstall Salt silently$\n"
  1050. FileWrite $0 "$\n"
  1051. FileWrite $0 "/?$\t$\t$\tDisplay this help screen$\n"
  1052. FileWrite $0 "$\n"
  1053. FileWrite $0 "-------------------------------------------------------------------------------$\n"
  1054. FileWrite $0 "$\n"
  1055. FileWrite $0 "Examples:$\n"
  1056. FileWrite $0 "$\n"
  1057. FileWrite $0 "${OutFile} /S$\n"
  1058. FileWrite $0 "$\n"
  1059. FileWrite $0 "${OutFile} /S /minion-name=myminion /master=master.mydomain.com /start-minion-delayed$\n"
  1060. FileWrite $0 "$\n"
  1061. FileWrite $0 "===============================================================================$\n"
  1062. FileWrite $0 "$\n"
  1063. System::Free $0
  1064. System::Free $1
  1065. System::Call 'kernel32::FreeConsole()'
  1066. # Give the user back the prompt
  1067. !define VK_RETURN 0x0D ; Enter Key
  1068. !define KEYEVENTF_EXTENDEDKEY 0x0001
  1069. !define KEYEVENTF_KEYUP 0x0002
  1070. System::Call "user32::keybd_event(i${VK_RETURN}, i0x45, i${KEYEVENTF_EXTENDEDKEY}|0, i0)"
  1071. System::Call "user32::keybd_event(i${VK_RETURN}, i0x45, i${KEYEVENTF_EXTENDEDKEY}|${KEYEVENTF_KEYUP}, i0)"
  1072. Abort
  1073. display_help_not_found:
  1074. # Set default value for Use Existing Config
  1075. StrCpy $ConfigType_State "Existing Config"
  1076. # Check for start-minion switches
  1077. # /start-service is to be deprecated, so we must check for both
  1078. ${GetOptions} $R0 "/start-service=" $R1
  1079. ${GetOptions} $R0 "/start-minion=" $R2
  1080. # Service: Start Salt Minion
  1081. ${IfNot} $R2 == ""
  1082. # If start-minion was passed something, then set it
  1083. StrCpy $StartMinion $R2
  1084. ${ElseIfNot} $R1 == ""
  1085. # If start-service was passed something, then set StartMinion to that
  1086. StrCpy $StartMinion $R1
  1087. ${Else}
  1088. # Otherwise default to 1
  1089. StrCpy $StartMinion 1
  1090. ${EndIf}
  1091. # Service: Minion Startup Type Delayed
  1092. ClearErrors
  1093. ${GetOptions} $R0 "/start-minion-delayed" $R1
  1094. IfErrors start_minion_delayed_not_found
  1095. StrCpy $StartMinionDelayed 1
  1096. start_minion_delayed_not_found:
  1097. # Minion Config: Master IP/Name
  1098. # If setting master, we don't want to use existing config
  1099. ${GetOptions} $R0 "/master=" $R1
  1100. ${IfNot} $R1 == ""
  1101. StrCpy $MasterHost_State $R1
  1102. StrCpy $ConfigType_State "Default Config"
  1103. ${ElseIf} $MasterHost_State == ""
  1104. StrCpy $MasterHost_State "salt"
  1105. ${EndIf}
  1106. # Minion Config: Minion ID
  1107. # If setting minion id, we don't want to use existing config
  1108. ${GetOptions} $R0 "/minion-name=" $R1
  1109. ${IfNot} $R1 == ""
  1110. StrCpy $MinionName_State $R1
  1111. StrCpy $ConfigType_State "Default Config"
  1112. ${ElseIf} $MinionName_State == ""
  1113. StrCpy $MinionName_State "hostname"
  1114. ${EndIf}
  1115. # Use Default Config
  1116. ${GetOptions} $R0 "/default-config" $R1
  1117. IfErrors default_config_not_found
  1118. StrCpy $ConfigType_State "Default Config"
  1119. default_config_not_found:
  1120. # Use Custom Config
  1121. # Set default value for Use Custom Config
  1122. StrCpy $CustomConfig_State ""
  1123. # Existing config will get a `.bak` extension
  1124. ${GetOptions} $R0 "/custom-config=" $R1
  1125. ${IfNot} $R1 == ""
  1126. # Custom Config was passed something, set it
  1127. StrCpy $CustomConfig_State $R1
  1128. StrCpy $ConfigType_State "Custom Config"
  1129. ${EndIf}
  1130. FunctionEnd