1
0

Salt-Minion-Setup.nsi 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640
  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 will be KB2999226 for Win8.1 and below
  338. # These files are downloaded by build_pkg.bat
  339. # This directory gets removed upon completion
  340. SetOutPath "$PLUGINSDIR\"
  341. File /r "..\prereqs\"
  342. SectionEnd
  343. # Check and install the Windows 10 Universal C Runtime (KB2999226)
  344. # ucrt is needed on Windows 8.1 and lower
  345. # They are installed as a Microsoft Update package (.msu)
  346. # ucrt for Windows 8.1 RT is only available via Windows Update
  347. Section -install_ucrt
  348. Var /GLOBAL MsuPrefix
  349. Var /GLOBAL MsuFileName
  350. # Get the Major.Minor version Number
  351. # Windows 10 introduced CurrentMajorVersionNumber
  352. ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" \
  353. CurrentMajorVersionNumber
  354. # Windows 10/2016 will return a value here, skip to the end if returned
  355. StrCmp $R0 '' lbl_needs_ucrt 0
  356. # Found Windows 10
  357. detailPrint "KB2999226 does not apply to this machine"
  358. goto lbl_done
  359. lbl_needs_ucrt:
  360. # UCRT only needed on Windows Server 2012R2/Windows 8.1 and below
  361. # The first ReadRegStr command above should have skipped to lbl_done if on
  362. # Windows 10 box
  363. # Is the update already installed
  364. ClearErrors
  365. # Use WMI to check if it's installed
  366. detailPrint "Checking for existing KB2999226 installation"
  367. nsExec::ExecToStack 'cmd /q /c wmic qfe get hotfixid | findstr "^KB2999226"'
  368. # Clean up the stack
  369. Pop $R0 # Gets the ErrorCode
  370. Pop $R1 # Gets the stdout, which should be KB2999226 if it's installed
  371. # If it returned KB2999226 it's already installed
  372. StrCmp $R1 'KB2999226' lbl_done
  373. detailPrint "KB2999226 not found"
  374. # All lower versions of Windows
  375. ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" \
  376. CurrentVersion
  377. # Get the name of the .msu file based on the value of $R0
  378. ${Switch} "$R0"
  379. ${Case} "6.3"
  380. StrCpy $MsuPrefix "Windows8.1"
  381. ${break}
  382. ${Case} "6.2"
  383. StrCpy $MsuPrefix "Windows8-RT"
  384. ${break}
  385. ${Case} "6.1"
  386. StrCpy $MsuPrefix "Windows6.1"
  387. ${break}
  388. ${Case} "6.0"
  389. StrCpy $MsuPrefix "Windows6.0"
  390. ${break}
  391. ${EndSwitch}
  392. # Use RunningX64 here to get the Architecture for the system running the installer
  393. # CPUARCH is defined when the installer is built and is based on the machine that
  394. # built the installer, not the target system as we need here.
  395. ${If} ${RunningX64}
  396. StrCpy $MsuFileName "$MsuPrefix-KB2999226-x64.msu"
  397. ${Else}
  398. StrCpy $MsuFileName "$MsuPrefix-KB2999226-x86.msu"
  399. ${EndIf}
  400. ClearErrors
  401. detailPrint "Installing KB2999226 using file $MsuFileName"
  402. nsExec::ExecToStack 'cmd /c wusa "$PLUGINSDIR\$MsuFileName" /quiet /norestart'
  403. # Clean up the stack
  404. Pop $R0 # Get Error
  405. Pop $R1 # Get stdout
  406. ${IfNot} $R0 == 0
  407. detailPrint "error: $R0"
  408. detailPrint "output: $R2"
  409. Sleep 3000
  410. ${Else}
  411. detailPrint "KB2999226 installed successfully"
  412. ${EndIf}
  413. lbl_done:
  414. SectionEnd
  415. # Check and install Visual C++ redist 2013 packages
  416. # Hidden section (-) to install VCRedist
  417. Section -install_vcredist_2013
  418. Var /GLOBAL VcRedistName
  419. Var /GLOBAL VcRedistGuid
  420. Var /GLOBAL NeedVcRedist
  421. # GUIDs can be found by installing them and then running the following command:
  422. # wmic product where "Name like '%2013%minimum runtime%'" get Name, Version, IdentifyingNumber
  423. !define VCREDIST_X86_NAME "vcredist_x86_2013"
  424. !define VCREDIST_X86_GUID "{8122DAB1-ED4D-3676-BB0A-CA368196543E}"
  425. !define VCREDIST_X64_NAME "vcredist_x64_2013"
  426. !define VCREDIST_X64_GUID "{53CF6934-A98D-3D84-9146-FC4EDF3D5641}"
  427. # Only install 64bit VCRedist on 64bit machines
  428. ${If} ${CPUARCH} == "AMD64"
  429. StrCpy $VcRedistName ${VCREDIST_X64_NAME}
  430. StrCpy $VcRedistGuid ${VCREDIST_X64_GUID}
  431. Call InstallVCRedist
  432. ${Else}
  433. # Install 32bit VCRedist on all machines
  434. StrCpy $VcRedistName ${VCREDIST_X86_NAME}
  435. StrCpy $VcRedistGuid ${VCREDIST_X86_GUID}
  436. Call InstallVCRedist
  437. ${EndIf}
  438. SectionEnd
  439. Function InstallVCRedist
  440. # Check to see if it's already installed
  441. Call MsiQueryProductState
  442. ${If} $NeedVcRedist == "True"
  443. detailPrint "System requires $VcRedistName"
  444. MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 \
  445. "$VcRedistName is currently not installed. Would you like to install?" \
  446. /SD IDYES IDNO endVCRedist
  447. # If an output variable is specified ($0 in the case below),
  448. # ExecWait sets the variable with the exit code (and only sets the
  449. # error flag if an error occurs; if an error occurs, the contents
  450. # of the user variable are undefined).
  451. # http://nsis.sourceforge.net/Reference/ExecWait
  452. ClearErrors
  453. detailPrint "Installing $VcRedistName..."
  454. ExecWait '"$PLUGINSDIR\$VcRedistName.exe" /install /quiet /norestart' $0
  455. IfErrors 0 CheckVcRedistErrorCode
  456. MessageBox MB_OK \
  457. "$VcRedistName failed to install. Try installing the package manually." \
  458. /SD IDOK
  459. detailPrint "An error occurred during installation of $VcRedistName"
  460. CheckVcRedistErrorCode:
  461. # Check for Reboot Error Code (3010)
  462. ${If} $0 == 3010
  463. MessageBox MB_OK \
  464. "$VcRedistName installed but requires a restart to complete." \
  465. /SD IDOK
  466. detailPrint "Reboot and run Salt install again"
  467. # Check for any other errors
  468. ${ElseIfNot} $0 == 0
  469. MessageBox MB_OK \
  470. "$VcRedistName failed with ErrorCode: $0. Try installing the package manually." \
  471. /SD IDOK
  472. detailPrint "An error occurred during installation of $VcRedistName"
  473. detailPrint "Error: $0"
  474. ${EndIf}
  475. endVCRedist:
  476. ${EndIf}
  477. FunctionEnd
  478. Section "MainSection" SEC01
  479. SetOutPath "$INSTDIR\"
  480. SetOverwrite off
  481. CreateDirectory $INSTDIR\conf\pki\minion
  482. CreateDirectory $INSTDIR\conf\minion.d
  483. File /r "..\buildenv\"
  484. 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'
  485. SectionEnd
  486. Function .onInit
  487. InitPluginsDir
  488. Call parseCommandLineSwitches
  489. # Uninstall msi-installed salt
  490. # Source https://nsis-dev.github.io/NSIS-Forums/html/t-303468.html
  491. !define upgradecode {FC6FB3A2-65DE-41A9-AD91-D10A402BD641} ;Salt upgrade code
  492. StrCpy $0 0
  493. loop:
  494. System::Call 'MSI::MsiEnumRelatedProducts(t "${upgradecode}",i0,i r0,t.r1)i.r2'
  495. ${If} $2 = 0
  496. # Now $1 contains the product code
  497. DetailPrint product:$1
  498. push $R0
  499. StrCpy $R0 $1
  500. Call UninstallMSI
  501. pop $R0
  502. IntOp $0 $0 + 1
  503. goto loop
  504. ${Endif}
  505. # If custom config passed, verify its existence before continuing so we
  506. # don't uninstall an existing installation and then fail
  507. ${If} $ConfigType_State == "Custom Config"
  508. IfFileExists "$CustomConfig_State" customConfigExists 0
  509. Abort
  510. ${EndIf}
  511. customConfigExists:
  512. # Check for existing installation
  513. ReadRegStr $R0 HKLM \
  514. "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  515. "UninstallString"
  516. StrCmp $R0 "" checkOther
  517. # Found existing installation, prompt to uninstall
  518. MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
  519. "${PRODUCT_NAME} is already installed.$\n$\n\
  520. Click `OK` to remove the existing installation." \
  521. /SD IDOK IDOK uninst
  522. Abort
  523. checkOther:
  524. # Check for existing installation of full salt
  525. ReadRegStr $R0 HKLM \
  526. "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME_OTHER}" \
  527. "UninstallString"
  528. StrCmp $R0 "" skipUninstall
  529. # Found existing installation, prompt to uninstall
  530. MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
  531. "${PRODUCT_NAME_OTHER} is already installed.$\n$\n\
  532. Click `OK` to remove the existing installation." \
  533. /SD IDOK IDOK uninst
  534. Abort
  535. uninst:
  536. # Get current Silent status
  537. StrCpy $R0 0
  538. ${If} ${Silent}
  539. StrCpy $R0 1
  540. ${EndIf}
  541. # Turn on Silent mode
  542. SetSilent silent
  543. # Don't remove all directories
  544. StrCpy $DeleteInstallDir 0
  545. # Uninstall silently
  546. Call uninstallSalt
  547. # Set it back to Normal mode, if that's what it was before
  548. ${If} $R0 == 0
  549. SetSilent normal
  550. ${EndIf}
  551. skipUninstall:
  552. Call getExistingMinionConfig
  553. ${If} $ExistingConfigFound == 0
  554. ${AndIf} $ConfigType_State == "Existing Config"
  555. StrCpy $ConfigType_State "Default Config"
  556. ${EndIf}
  557. IfSilent 0 +2
  558. Call BackupExistingConfig
  559. FunctionEnd
  560. # Time Stamp Definition
  561. !define /date TIME_STAMP "%Y-%m-%d-%H-%M-%S"
  562. Function BackupExistingConfig
  563. ${If} $ExistingConfigFound == 1 # If existing config found
  564. ${AndIfNot} $ConfigType_State == "Existing Config" # If not using Existing Config
  565. # Backup the minion config
  566. Rename "$INSTDIR\conf\minion" "$INSTDIR\conf\minion-${TIME_STAMP}.bak"
  567. IfFileExists "$INSTDIR\conf\minion.d" 0 +2
  568. Rename "$INSTDIR\conf\minion.d" "$INSTDIR\conf\minion.d-${TIME_STAMP}.bak"
  569. ${EndIf}
  570. # By this point there should be no existing config
  571. # It was either backed up or wasn't there to begin with
  572. ${If} $ConfigType_State == "Custom Config" # If we're using Custom Config
  573. ${AndIfNot} $CustomConfig_State == "" # If a custom config is passed
  574. # Check for a file name
  575. # Named file should be in the same directory as the installer
  576. CreateDirectory "$INSTDIR\conf"
  577. IfFileExists "$EXEDIR\$CustomConfig_State" 0 checkFullPath
  578. CopyFiles /SILENT /FILESONLY "$EXEDIR\$CustomConfig_State" "$INSTDIR\conf\minion"
  579. goto finished
  580. # Maybe it was a full path to a file
  581. checkFullPath:
  582. IfFileExists "$CustomConfig_State" 0 finished
  583. CopyFiles /SILENT /FILESONLY "$CustomConfig_State" "$INSTDIR\conf\minion"
  584. finished:
  585. ${EndIf}
  586. FunctionEnd
  587. Section -Post
  588. WriteUninstaller "$INSTDIR\uninst.exe"
  589. # Uninstall Registry Entries
  590. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
  591. "DisplayName" "$(^Name)"
  592. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
  593. "UninstallString" "$INSTDIR\uninst.exe"
  594. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
  595. "DisplayIcon" "$INSTDIR\salt.ico"
  596. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
  597. "DisplayVersion" "${PRODUCT_VERSION}"
  598. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
  599. "URLInfoAbout" "${PRODUCT_WEB_SITE}"
  600. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
  601. "Publisher" "${PRODUCT_PUBLISHER}"
  602. WriteRegStr HKLM "SYSTEM\CurrentControlSet\services\salt-minion" \
  603. "DependOnService" "nsi"
  604. # Set the estimated size
  605. ${GetSize} "$INSTDIR\bin" "/S=OK" $0 $1 $2
  606. IntFmt $0 "0x%08X" $0
  607. WriteRegDWORD ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
  608. "EstimatedSize" "$0"
  609. # Commandline Registry Entries
  610. WriteRegStr HKLM "${PRODUCT_CALL_REGKEY}" "" "$INSTDIR\salt-call.bat"
  611. WriteRegStr HKLM "${PRODUCT_CALL_REGKEY}" "Path" "$INSTDIR\bin\"
  612. WriteRegStr HKLM "${PRODUCT_MINION_REGKEY}" "" "$INSTDIR\salt-minion.bat"
  613. WriteRegStr HKLM "${PRODUCT_MINION_REGKEY}" "Path" "$INSTDIR\bin\"
  614. # Register the Salt-Minion Service
  615. 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"
  616. nsExec::Exec "$INSTDIR\bin\ssm.exe set salt-minion Description Salt Minion from saltstack.com"
  617. nsExec::Exec "$INSTDIR\bin\ssm.exe set salt-minion Start SERVICE_AUTO_START"
  618. nsExec::Exec "$INSTDIR\bin\ssm.exe set salt-minion AppStopMethodConsole 24000"
  619. nsExec::Exec "$INSTDIR\bin\ssm.exe set salt-minion AppStopMethodWindow 2000"
  620. ${IfNot} $ConfigType_State == "Existing Config" # If not using Existing Config
  621. Call updateMinionConfig
  622. ${EndIf}
  623. Push "C:\salt"
  624. Call AddToPath
  625. SectionEnd
  626. Function .onInstSuccess
  627. # If StartMinionDelayed is 1, then set the service to start delayed
  628. ${If} $StartMinionDelayed == 1
  629. nsExec::Exec "$INSTDIR\bin\ssm.exe set salt-minion Start SERVICE_DELAYED_AUTO_START"
  630. ${EndIf}
  631. # If start-minion is 1, then start the service
  632. ${If} $StartMinion == 1
  633. nsExec::Exec 'net start salt-minion'
  634. ${EndIf}
  635. FunctionEnd
  636. Function un.onInit
  637. # Load the parameters
  638. ${GetParameters} $R0
  639. # Uninstaller: Remove Installation Directory
  640. ClearErrors
  641. ${GetOptions} $R0 "/delete-install-dir" $R1
  642. IfErrors delete_install_dir_not_found
  643. StrCpy $DeleteInstallDir 1
  644. delete_install_dir_not_found:
  645. MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 \
  646. "Are you sure you want to completely remove $(^Name) and all of its components?" \
  647. /SD IDYES IDYES +2
  648. Abort
  649. FunctionEnd
  650. Section Uninstall
  651. Call un.uninstallSalt
  652. # Remove C:\salt from the Path
  653. Push "C:\salt"
  654. Call un.RemoveFromPath
  655. SectionEnd
  656. !macro uninstallSalt un
  657. Function ${un}uninstallSalt
  658. # Make sure we're in the right directory
  659. ${If} $INSTDIR == "c:\salt\bin\Scripts"
  660. StrCpy $INSTDIR "C:\salt"
  661. ${EndIf}
  662. # Stop and Remove salt-minion service
  663. nsExec::Exec 'net stop salt-minion'
  664. nsExec::Exec 'sc delete salt-minion'
  665. # Stop and remove the salt-master service
  666. nsExec::Exec 'net stop salt-master'
  667. nsExec::Exec 'sc delete salt-master'
  668. # Remove files
  669. Delete "$INSTDIR\uninst.exe"
  670. Delete "$INSTDIR\ssm.exe"
  671. Delete "$INSTDIR\salt*"
  672. Delete "$INSTDIR\vcredist.exe"
  673. RMDir /r "$INSTDIR\bin"
  674. # Remove Registry entries
  675. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  676. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY_OTHER}"
  677. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_CALL_REGKEY}"
  678. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_CP_REGKEY}"
  679. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_KEY_REGKEY}"
  680. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_MASTER_REGKEY}"
  681. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_MINION_REGKEY}"
  682. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_RUN_REGKEY}"
  683. # Automatically close when finished
  684. SetAutoClose true
  685. # Prompt to remove the Installation directory
  686. ${IfNot} $DeleteInstallDir == 1
  687. MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 \
  688. "Would you like to completely remove $INSTDIR and all of its contents?" \
  689. /SD IDNO IDNO finished
  690. ${EndIf}
  691. # Make sure you're not removing Program Files
  692. ${If} $INSTDIR != 'Program Files'
  693. ${AndIf} $INSTDIR != 'Program Files (x86)'
  694. RMDir /r "$INSTDIR"
  695. ${EndIf}
  696. finished:
  697. FunctionEnd
  698. !macroend
  699. !insertmacro uninstallSalt ""
  700. !insertmacro uninstallSalt "un."
  701. Function un.onUninstSuccess
  702. HideWindow
  703. MessageBox MB_ICONINFORMATION|MB_OK \
  704. "$(^Name) was successfully removed from your computer." \
  705. /SD IDOK
  706. FunctionEnd
  707. ###############################################################################
  708. # Helper Functions
  709. ###############################################################################
  710. Function MsiQueryProductState
  711. # Used for detecting VCRedist Installation
  712. !define INSTALLSTATE_DEFAULT "5"
  713. StrCpy $NeedVcRedist "False"
  714. System::Call "msi::MsiQueryProductStateA(t '$VcRedistGuid') i.r0"
  715. StrCmp $0 ${INSTALLSTATE_DEFAULT} +2 0
  716. StrCpy $NeedVcRedist "True"
  717. FunctionEnd
  718. #------------------------------------------------------------------------------
  719. # Trim Function
  720. # - Trim whitespace from the beginning and end of a string
  721. # - Trims spaces, \r, \n, \t
  722. #
  723. # Usage:
  724. # Push " some string " ; String to Trim
  725. # Call Trim
  726. # Pop $0 ; Trimmed String: "some string"
  727. #
  728. # or
  729. #
  730. # ${Trim} $0 $1 ; Trimmed String, String to Trim
  731. #------------------------------------------------------------------------------
  732. Function Trim
  733. Exch $R1 # Original string
  734. Push $R2
  735. Loop:
  736. StrCpy $R2 "$R1" 1
  737. StrCmp "$R2" " " TrimLeft
  738. StrCmp "$R2" "$\r" TrimLeft
  739. StrCmp "$R2" "$\n" TrimLeft
  740. StrCmp "$R2" "$\t" TrimLeft
  741. GoTo Loop2
  742. TrimLeft:
  743. StrCpy $R1 "$R1" "" 1
  744. Goto Loop
  745. Loop2:
  746. StrCpy $R2 "$R1" 1 -1
  747. StrCmp "$R2" " " TrimRight
  748. StrCmp "$R2" "$\r" TrimRight
  749. StrCmp "$R2" "$\n" TrimRight
  750. StrCmp "$R2" "$\t" TrimRight
  751. GoTo Done
  752. TrimRight:
  753. StrCpy $R1 "$R1" -1
  754. Goto Loop2
  755. Done:
  756. Pop $R2
  757. Exch $R1
  758. FunctionEnd
  759. #------------------------------------------------------------------------------
  760. # Explode Function
  761. # - Splits a string based off the passed separator
  762. # - Each item in the string is pushed to the stack
  763. # - The last item pushed to the stack is the length of the array
  764. #
  765. # Usage:
  766. # Push "," ; Separator
  767. # Push "string,to,separate" ; String to explode
  768. # Call Explode
  769. # Pop $0 ; Number of items in the array
  770. #
  771. # or
  772. #
  773. # ${Explode} $0 $1 $2 ; Length, Separator, String
  774. #------------------------------------------------------------------------------
  775. Function Explode
  776. # Initialize variables
  777. Var /GLOBAL explString
  778. Var /GLOBAL explSeparator
  779. Var /GLOBAL explStrLen
  780. Var /GLOBAL explSepLen
  781. Var /GLOBAL explOffset
  782. Var /GLOBAL explTmp
  783. Var /GLOBAL explTmp2
  784. Var /GLOBAL explTmp3
  785. Var /GLOBAL explArrCount
  786. # Get input from user
  787. Pop $explString
  788. Pop $explSeparator
  789. # Calculates initial values
  790. StrLen $explStrLen $explString
  791. StrLen $explSepLen $explSeparator
  792. StrCpy $explArrCount 1
  793. ${If} $explStrLen <= 1 # If we got a single character
  794. ${OrIf} $explSepLen > $explStrLen # or separator is larger than the string,
  795. Push $explString # then we return initial string with no change
  796. Push 1 # and set array's length to 1
  797. Return
  798. ${EndIf}
  799. # Set offset to the last symbol of the string
  800. StrCpy $explOffset $explStrLen
  801. IntOp $explOffset $explOffset - 1
  802. # Clear temp string to exclude the possibility of appearance of occasional data
  803. StrCpy $explTmp ""
  804. StrCpy $explTmp2 ""
  805. StrCpy $explTmp3 ""
  806. # Loop until the offset becomes negative
  807. ${Do}
  808. # If offset becomes negative, it is time to leave the function
  809. ${IfThen} $explOffset == -1 ${|} ${ExitDo} ${|}
  810. # Remove everything before and after the searched part ("TempStr")
  811. StrCpy $explTmp $explString $explSepLen $explOffset
  812. ${If} $explTmp == $explSeparator
  813. # Calculating offset to start copy from
  814. IntOp $explTmp2 $explOffset + $explSepLen # Offset equals to the current offset plus length of separator
  815. StrCpy $explTmp3 $explString "" $explTmp2
  816. Push $explTmp3 # Throwing array item to the stack
  817. IntOp $explArrCount $explArrCount + 1 # Increasing array's counter
  818. StrCpy $explString $explString $explOffset 0 # Cutting all characters beginning with the separator entry
  819. StrLen $explStrLen $explString
  820. ${EndIf}
  821. ${If} $explOffset = 0 # If the beginning of the line met and there is no separator,
  822. # copying the rest of the string
  823. ${If} $explSeparator == "" # Fix for the empty separator
  824. IntOp $explArrCount $explArrCount - 1
  825. ${Else}
  826. Push $explString
  827. ${EndIf}
  828. ${EndIf}
  829. IntOp $explOffset $explOffset - 1
  830. ${Loop}
  831. Push $explArrCount
  832. FunctionEnd
  833. #------------------------------------------------------------------------------
  834. # StrStr Function
  835. # - find substring in a string
  836. #
  837. # Usage:
  838. # Push "this is some string"
  839. # Push "some"
  840. # Call StrStr
  841. # Pop $0 # "some string"
  842. #------------------------------------------------------------------------------
  843. !macro StrStr un
  844. Function ${un}StrStr
  845. Exch $R1 # $R1=substring, stack=[old$R1,string,...]
  846. Exch # stack=[string,old$R1,...]
  847. Exch $R2 # $R2=string, stack=[old$R2,old$R1,...]
  848. Push $R3 # $R3=strlen(substring)
  849. Push $R4 # $R4=count
  850. Push $R5 # $R5=tmp
  851. StrLen $R3 $R1 # Get the length of the Search String
  852. StrCpy $R4 0 # Set the counter to 0
  853. loop:
  854. StrCpy $R5 $R2 $R3 $R4 # Create a moving window of the string that is
  855. # the size of the length of the search string
  856. StrCmp $R5 $R1 done # Is the contents of the window the same as
  857. # search string, then done
  858. StrCmp $R5 "" done # Is the window empty, then done
  859. IntOp $R4 $R4 + 1 # Shift the windows one character
  860. Goto loop # Repeat
  861. done:
  862. StrCpy $R1 $R2 "" $R4
  863. Pop $R5
  864. Pop $R4
  865. Pop $R3
  866. Pop $R2
  867. Exch $R1 # $R1=old$R1, stack=[result,...]
  868. FunctionEnd
  869. !macroend
  870. !insertmacro StrStr ""
  871. !insertmacro StrStr "un."
  872. #------------------------------------------------------------------------------
  873. # AddToPath Function
  874. # - Adds item to Path for All Users
  875. # - Overcomes NSIS ReadRegStr limitation of 1024 characters by using Native
  876. # Windows Commands
  877. #
  878. # Usage:
  879. # Push "C:\path\to\add"
  880. # Call AddToPath
  881. #------------------------------------------------------------------------------
  882. !define Environ 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
  883. Function AddToPath
  884. Exch $0 # Path to add
  885. Push $1 # Current Path
  886. Push $2 # Results of StrStr / Length of Path + Path to Add
  887. Push $3 # Handle to Reg / Length of Path
  888. Push $4 # Result of Registry Call
  889. # Open a handle to the key in the registry, handle in $3, Error in $4
  890. System::Call "advapi32::RegOpenKey(i 0x80000002, t'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', *i.r3) i.r4"
  891. # Make sure registry handle opened successfully (returned 0)
  892. IntCmp $4 0 0 done done
  893. # Load the contents of path into $1, Error Code into $4, Path length into $2
  894. System::Call "advapi32::RegQueryValueEx(i $3, t'PATH', i 0, i 0, t.r1, *i ${NSIS_MAX_STRLEN} r2) i.r4"
  895. # Close the handle to the registry ($3)
  896. System::Call "advapi32::RegCloseKey(i $3)"
  897. # Check for Error Code 234, Path too long for the variable
  898. IntCmp $4 234 0 +4 +4 # $4 == ERROR_MORE_DATA
  899. DetailPrint "AddToPath Failed: original length $2 > ${NSIS_MAX_STRLEN}"
  900. MessageBox MB_OK \
  901. "You may add C:\salt to the %PATH% for convenience when issuing local salt commands from the command line." \
  902. /SD IDOK
  903. Goto done
  904. # If no error, continue
  905. IntCmp $4 0 +5 # $4 != NO_ERROR
  906. # Error 2 means the Key was not found
  907. IntCmp $4 2 +3 # $4 != ERROR_FILE_NOT_FOUND
  908. DetailPrint "AddToPath: unexpected error code $4"
  909. Goto done
  910. StrCpy $1 ""
  911. # Check if already in PATH
  912. Push "$1;" # The string to search
  913. Push "$0;" # The string to find
  914. Call StrStr
  915. Pop $2 # The result of the search
  916. StrCmp $2 "" 0 done # String not found, try again with ';' at the end
  917. # Otherwise, it's already in the path
  918. Push "$1;" # The string to search
  919. Push "$0\;" # The string to find
  920. Call StrStr
  921. Pop $2 # The result
  922. StrCmp $2 "" 0 done # String not found, continue (add)
  923. # Otherwise, it's already in the path
  924. # Prevent NSIS string overflow
  925. StrLen $2 $0 # Length of path to add ($2)
  926. StrLen $3 $1 # Length of current path ($3)
  927. IntOp $2 $2 + $3 # Length of current path + path to add ($2)
  928. IntOp $2 $2 + 2 # Account for the additional ';'
  929. # $2 = strlen(dir) + strlen(PATH) + sizeof(";")
  930. # Make sure the new length isn't over the NSIS_MAX_STRLEN
  931. IntCmp $2 ${NSIS_MAX_STRLEN} +4 +4 0
  932. DetailPrint "AddToPath Failed: new length $2 > ${NSIS_MAX_STRLEN}"
  933. MessageBox MB_OK \
  934. "You may add C:\salt to the %PATH% for convenience when issuing local salt commands from the command line." \
  935. /SD IDOK
  936. Goto done
  937. # Append dir to PATH
  938. DetailPrint "Add to PATH: $0"
  939. StrCpy $2 $1 1 -1 # Copy the last character of the existing path
  940. StrCmp $2 ";" 0 +2 # Check for trailing ';'
  941. StrCpy $1 $1 -1 # remove trailing ';'
  942. StrCmp $1 "" +2 # Make sure Path is not empty
  943. StrCpy $0 "$1;$0" # Append new path at the end ($0)
  944. # We can use the NSIS command here. Only 'ReadRegStr' is affected
  945. WriteRegExpandStr ${Environ} "PATH" $0
  946. # Broadcast registry change to open programs
  947. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  948. done:
  949. Pop $4
  950. Pop $3
  951. Pop $2
  952. Pop $1
  953. Pop $0
  954. FunctionEnd
  955. #------------------------------------------------------------------------------
  956. # RemoveFromPath Function
  957. # - Removes item from Path for All Users
  958. # - Overcomes NSIS ReadRegStr limitation of 1024 characters by using Native
  959. # Windows Commands
  960. #
  961. # Usage:
  962. # Push "C:\path\to\add"
  963. # Call un.RemoveFromPath
  964. #------------------------------------------------------------------------------
  965. Function un.RemoveFromPath
  966. Exch $0
  967. Push $1
  968. Push $2
  969. Push $3
  970. Push $4
  971. Push $5
  972. Push $6
  973. # Open a handle to the key in the registry, handle in $3, Error in $4
  974. System::Call "advapi32::RegOpenKey(i 0x80000002, t'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', *i.r3) i.r4"
  975. # Make sure registry handle opened successfully (returned 0)
  976. IntCmp $4 0 0 done done
  977. # Load the contents of path into $1, Error Code into $4, Path length into $2
  978. System::Call "advapi32::RegQueryValueEx(i $3, t'PATH', i 0, i 0, t.r1, *i ${NSIS_MAX_STRLEN} r2) i.r4"
  979. # Close the handle to the registry ($3)
  980. System::Call "advapi32::RegCloseKey(i $3)"
  981. # Check for Error Code 234, Path too long for the variable
  982. IntCmp $4 234 0 +4 +4 # $4 == ERROR_MORE_DATA
  983. DetailPrint "AddToPath: original length $2 > ${NSIS_MAX_STRLEN}"
  984. Goto done
  985. # If no error, continue
  986. IntCmp $4 0 +5 # $4 != NO_ERROR
  987. # Error 2 means the Key was not found
  988. IntCmp $4 2 +3 # $4 != ERROR_FILE_NOT_FOUND
  989. DetailPrint "AddToPath: unexpected error code $4"
  990. Goto done
  991. StrCpy $1 ""
  992. # Ensure there's a trailing ';'
  993. StrCpy $5 $1 1 -1 # Copy the last character of the path
  994. StrCmp $5 ";" +2 # Check for trailing ';', if found continue
  995. StrCpy $1 "$1;" # ensure trailing ';'
  996. # Check for our directory inside the path
  997. Push $1 # String to Search
  998. Push "$0;" # Dir to Find
  999. Call un.StrStr
  1000. Pop $2 # The results of the search
  1001. StrCmp $2 "" done # If results are empty, we're done, otherwise continue
  1002. # Remove our Directory from the Path
  1003. DetailPrint "Remove from PATH: $0"
  1004. StrLen $3 "$0;" # Get the length of our dir ($3)
  1005. StrLen $4 $2 # Get the length of the return from StrStr ($4)
  1006. StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
  1007. StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
  1008. StrCpy $3 "$5$6" # Combine $5 and $6
  1009. # Check for Trailing ';'
  1010. StrCpy $5 $3 1 -1 # Load the last character of the string
  1011. StrCmp $5 ";" 0 +2 # Check for ';'
  1012. StrCpy $3 $3 -1 # remove trailing ';'
  1013. # Write the new path to the registry
  1014. WriteRegExpandStr ${Environ} "PATH" $3
  1015. # Broadcast the change to all open applications
  1016. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  1017. done:
  1018. Pop $6
  1019. Pop $5
  1020. Pop $4
  1021. Pop $3
  1022. Pop $2
  1023. Pop $1
  1024. Pop $0
  1025. FunctionEnd
  1026. #------------------------------------------------------------------------------
  1027. # UninstallMSI Function
  1028. # - Uninstalls MSI by product code
  1029. #
  1030. # Usage:
  1031. # Push product code
  1032. # Call UninstallMSI
  1033. #
  1034. # Source:
  1035. # https://nsis.sourceforge.io/Uninstalling_a_previous_MSI_(Windows_installer_package)
  1036. #------------------------------------------------------------------------------
  1037. Function UninstallMSI
  1038. ; $R0 === product code
  1039. MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
  1040. "${PRODUCT_NAME} is already installed via MSI.$\n$\n\
  1041. Click `OK` to remove the existing installation." \
  1042. /SD IDOK IDOK UninstallMSI
  1043. Abort
  1044. UninstallMSI:
  1045. ExecWait '"msiexec.exe" /x $R0 /qb /quiet /norestart'
  1046. FunctionEnd
  1047. ###############################################################################
  1048. # Specialty Functions
  1049. ###############################################################################
  1050. Function getExistingMinionConfig
  1051. # Set Config Found Default Value
  1052. StrCpy $ExistingConfigFound 0
  1053. confFind:
  1054. IfFileExists "$INSTDIR\conf\minion" confFound confNotFound
  1055. confNotFound:
  1056. ${If} $INSTDIR == "c:\salt\bin\Scripts"
  1057. StrCpy $INSTDIR "C:\salt"
  1058. goto confFind
  1059. ${Else}
  1060. goto confReallyNotFound
  1061. ${EndIf}
  1062. confFound:
  1063. StrCpy $ExistingConfigFound 1
  1064. FileOpen $0 "$INSTDIR\conf\minion" r
  1065. confLoop:
  1066. ClearErrors # clear Errors
  1067. FileRead $0 $1 # read the next line
  1068. IfErrors EndOfFile # error is probably EOF
  1069. ${StrLoc} $2 $1 "master:" ">" # find `master:` starting at the beginning
  1070. ${If} $2 == 0 # if it found it in the first position, then it is defined
  1071. ${StrStrAdv} $2 $1 "master: " ">" ">" "0" "0" "0" # read everything after `master: `
  1072. ${Trim} $2 $2 # trim white space
  1073. ${If} $2 == "" # if it's empty, it's probably a list of masters
  1074. masterLoop:
  1075. ClearErrors # clear Errors
  1076. FileRead $0 $1 # read the next line
  1077. IfErrors EndOfFile # error is probably EOF
  1078. ${StrStrAdv} $2 $1 "- " ">" ">" "0" "0" "0" # read everything after `- `
  1079. ${Trim} $2 $2 # trim white space
  1080. ${IfNot} $2 == "" # if the line is not empty, we found something
  1081. ${If} $ConfigMasterHost == "" # if the config setting is empty
  1082. StrCpy $ConfigMasterHost $2 # make the first item the new entry
  1083. ${Else}
  1084. StrCpy $ConfigMasterHost "$ConfigMasterHost,$2" # Append the new master, comma separated
  1085. ${EndIf}
  1086. Goto masterLoop # check the next one
  1087. ${EndIf}
  1088. ${Else}
  1089. StrCpy $ConfigMasterHost $2 # a single master entry
  1090. ${EndIf}
  1091. ${EndIf}
  1092. ${StrLoc} $2 $1 "id:" ">"
  1093. ${If} $2 == 0
  1094. ${StrStrAdv} $2 $1 "id: " ">" ">" "0" "0" "0"
  1095. ${Trim} $2 $2
  1096. StrCpy $ConfigMinionName $2
  1097. ${EndIf}
  1098. Goto confLoop
  1099. EndOfFile:
  1100. FileClose $0
  1101. confReallyNotFound:
  1102. # Set Default Config Values if not found
  1103. ${If} $ConfigMasterHost == ""
  1104. StrCpy $ConfigMasterHost "salt"
  1105. ${EndIf}
  1106. ${If} $ConfigMinionName == ""
  1107. StrCpy $ConfigMinionName "hostname"
  1108. ${EndIf}
  1109. FunctionEnd
  1110. Var cfg_line
  1111. Var chk_line
  1112. Var lst_check
  1113. Function updateMinionConfig
  1114. ClearErrors
  1115. FileOpen $0 "$INSTDIR\conf\minion" "r" # open target file for reading
  1116. GetTempFileName $R0 # get new temp file name
  1117. FileOpen $1 $R0 "w" # open temp file for writing
  1118. StrCpy $ConfigWriteMaster 1 # write the master config value
  1119. StrCpy $ConfigWriteMinion 1 # write the minion config value
  1120. loop: # loop through each line
  1121. FileRead $0 $cfg_line # read line from target file
  1122. IfErrors done # end if errors are encountered (end of line)
  1123. loop_after_read:
  1124. StrCpy $lst_check 0 # list check not performed
  1125. ${If} $MasterHost_State == "" # if master is empty
  1126. ${OrIf} $MasterHost_State == "salt" # or if master is 'salt'
  1127. StrCpy $ConfigWriteMaster 0 # no need to write master config
  1128. ${EndIf} # close if statement
  1129. ${If} $MinionName_State == "" # if minion is empty
  1130. ${OrIf} $MinionName_State == "hostname" # and if minion is not 'hostname'
  1131. StrCpy $ConfigWriteMinion 0 # no need to write minion config
  1132. ${EndIf} # close if statement
  1133. ${If} $ConfigWriteMaster == 1 # if we need to write master config
  1134. ${StrLoc} $3 $cfg_line "master:" ">" # where is 'master:' in this line
  1135. ${If} $3 == 0 # is it in the first...
  1136. ${OrIf} $3 == 1 # or second position (account for comments)
  1137. ${Explode} $9 "," $MasterHost_state # Split the hostname on commas, $9 is the number of items found
  1138. ${If} $9 == 1 # 1 means only a single master was passed
  1139. StrCpy $cfg_line "master: $MasterHost_State$\r$\n" # write the master
  1140. ${Else} # make a multi-master entry
  1141. StrCpy $cfg_line "master:" # make the first line "master:"
  1142. loop_explode: # start a loop to go through the list in the config
  1143. pop $8 # pop the next item off the stack
  1144. ${Trim} $8 $8 # trim any whitespace
  1145. StrCpy $cfg_line "$cfg_line$\r$\n - $8" # add it to the master variable ($2)
  1146. IntOp $9 $9 - 1 # decrement the list count
  1147. ${If} $9 >= 1 # if it's not 0
  1148. Goto loop_explode # do it again
  1149. ${EndIf} # close if statement
  1150. StrCpy $cfg_line "$cfg_line$\r$\n" # Make sure there's a new line at the end
  1151. # Remove remaining items in list
  1152. ${While} $lst_check == 0 # while list item found
  1153. FileRead $0 $chk_line # read line from target file
  1154. IfErrors done # end if errors are encountered (end of line)
  1155. ${StrLoc} $3 $chk_line " - " ">" # where is 'master:' in this line
  1156. ${If} $3 == "" # is it in the first...
  1157. StrCpy $lst_check 1 # list check performed and finished
  1158. ${EndIf}
  1159. ${EndWhile}
  1160. ${EndIf} # close if statement
  1161. StrCpy $ConfigWriteMaster 0 # master value written to config
  1162. ${EndIf} # close if statement
  1163. ${EndIf} # close if statement
  1164. ${If} $ConfigWriteMinion == 1 # if we need to write minion config
  1165. ${StrLoc} $3 $cfg_line "id:" ">" # where is 'id:' in this line
  1166. ${If} $3 == 0 # is it in the first...
  1167. ${OrIf} $3 == 1 # or the second position (account for comments)
  1168. StrCpy $cfg_line "id: $MinionName_State$\r$\n" # write the minion config setting
  1169. StrCpy $ConfigWriteMinion 0 # minion value written to config
  1170. ${EndIf} # close if statement
  1171. ${EndIf} # close if statement
  1172. FileWrite $1 $cfg_line # write changed or unchanged line to temp file
  1173. ${If} $lst_check == 1 # master not written to the config
  1174. StrCpy $cfg_line $chk_line
  1175. Goto loop_after_read # A loop was performed, skip the next read
  1176. ${EndIf} # close if statement
  1177. Goto loop # check the next line in the config file
  1178. done:
  1179. ClearErrors
  1180. # Does master config still need to be written
  1181. ${If} $ConfigWriteMaster == 1 # master not written to the config
  1182. ${Explode} $9 "," $MasterHost_state # split the hostname on commas, $9 is the number of items found
  1183. ${If} $9 == 1 # 1 means only a single master was passed
  1184. StrCpy $cfg_line "master: $MasterHost_State" # write the master
  1185. ${Else} # make a multi-master entry
  1186. StrCpy $cfg_line "master:" # make the first line "master:"
  1187. loop_explode_2: # start a loop to go through the list in the config
  1188. pop $8 # pop the next item off the stack
  1189. ${Trim} $8 $8 # trim any whitespace
  1190. StrCpy $cfg_line "$cfg_line$\r$\n - $8" # add it to the master variable ($2)
  1191. IntOp $9 $9 - 1 # decrement the list count
  1192. ${If} $9 >= 1 # if it's not 0
  1193. Goto loop_explode_2 # do it again
  1194. ${EndIf} # close if statement
  1195. ${EndIf} # close if statement
  1196. FileWrite $1 $cfg_line # write changed or unchanged line to temp file
  1197. ${EndIf} # close if statement
  1198. ${If} $ConfigWriteMinion == 1 # minion ID not written to the config
  1199. StrCpy $cfg_line "$\r$\nid: $MinionName_State" # write the minion config setting
  1200. FileWrite $1 $cfg_line # write changed or unchanged line to temp file
  1201. ${EndIf} # close if statement
  1202. FileClose $0 # close target file
  1203. FileClose $1 # close temp file
  1204. Delete "$INSTDIR\conf\minion" # delete target file
  1205. CopyFiles /SILENT $R0 "$INSTDIR\conf\minion" # copy temp file to target file
  1206. Delete $R0 # delete temp file
  1207. FunctionEnd
  1208. Function parseCommandLineSwitches
  1209. # Load the parameters
  1210. ${GetParameters} $R0
  1211. # Display Help
  1212. ClearErrors
  1213. ${GetOptions} $R0 "/?" $R1
  1214. IfErrors display_help_not_found
  1215. System::Call 'kernel32::GetStdHandle(i -11)i.r0'
  1216. System::Call 'kernel32::AttachConsole(i -1)i.r1'
  1217. ${If} $0 = 0
  1218. ${OrIf} $1 = 0
  1219. System::Call 'kernel32::AllocConsole()'
  1220. System::Call 'kernel32::GetStdHandle(i -11)i.r0'
  1221. ${EndIf}
  1222. FileWrite $0 "$\n"
  1223. FileWrite $0 "$\n"
  1224. FileWrite $0 "Help for Salt Minion installation$\n"
  1225. FileWrite $0 "===============================================================================$\n"
  1226. FileWrite $0 "$\n"
  1227. FileWrite $0 "/minion-name=$\t$\tA string value to set the minion name. Default value is$\n"
  1228. FileWrite $0 "$\t$\t$\t'hostname'. Setting the minion name causes the installer$\n"
  1229. FileWrite $0 "$\t$\t$\tto use the default config or a custom config if defined$\n"
  1230. FileWrite $0 "$\n"
  1231. FileWrite $0 "/master=$\t$\tA string value to set the IP address or hostname of the$\n"
  1232. FileWrite $0 "$\t$\t$\tmaster. Default value is 'salt'. You may pass a single$\n"
  1233. FileWrite $0 "$\t$\t$\tmaster or a comma-separated list of masters. Setting$\n"
  1234. FileWrite $0 "$\t$\t$\tthe master will cause the installer to use the default$\n"
  1235. FileWrite $0 "$\t$\t$\tconfig or a custom config if defined$\n"
  1236. FileWrite $0 "$\n"
  1237. FileWrite $0 "/start-minion=$\t$\t1 will start the minion service, 0 will not.$\n"
  1238. FileWrite $0 "$\t$\t$\tDefault is 1$\n"
  1239. FileWrite $0 "$\n"
  1240. FileWrite $0 "/start-minion-delayed$\tSet the minion start type to 'Automatic (Delayed Start)'$\n"
  1241. FileWrite $0 "$\n"
  1242. FileWrite $0 "/default-config$\t$\tOverwrite the existing config if present with the$\n"
  1243. FileWrite $0 "$\t$\t$\tdefault config for salt. Default is to use the existing$\n"
  1244. FileWrite $0 "$\t$\t$\tconfig if present. If /master and/or /minion-name is$\n"
  1245. FileWrite $0 "$\t$\t$\tpassed, those values will be used to update the new$\n"
  1246. FileWrite $0 "$\t$\t$\tdefault config$\n"
  1247. FileWrite $0 "$\n"
  1248. FileWrite $0 "$\t$\t$\tAny existing config will be backed up by appending$\n"
  1249. FileWrite $0 "$\t$\t$\ta timestamp and a .bak extension. That includes\n"
  1250. FileWrite $0 "$\t$\t$\tthe minion file and the minion.d directory$\n"
  1251. FileWrite $0 "$\n"
  1252. FileWrite $0 "/custom-config=$\t$\tA string value specifying the name of a custom config$\n"
  1253. FileWrite $0 "$\t$\t$\tfile in the same path as the installer or the full path$\n"
  1254. FileWrite $0 "$\t$\t$\tto a custom config file. If /master and/or /minion-name$\n"
  1255. FileWrite $0 "$\t$\t$\tis passed, those values will be used to update the new$\n"
  1256. FileWrite $0 "$\t$\t$\tcustom config$\n"
  1257. FileWrite $0 "$\n"
  1258. FileWrite $0 "$\t$\t$\tAny existing config will be backed up by appending$\n"
  1259. FileWrite $0 "$\t$\t$\ta timestamp and a .bak extension. That includes\n"
  1260. FileWrite $0 "$\t$\t$\tthe minion file and the minion.d directory$\n"
  1261. FileWrite $0 "$\n"
  1262. FileWrite $0 "/S$\t$\t$\tInstall Salt silently$\n"
  1263. FileWrite $0 "$\n"
  1264. FileWrite $0 "/?$\t$\t$\tDisplay this help screen$\n"
  1265. FileWrite $0 "$\n"
  1266. FileWrite $0 "-------------------------------------------------------------------------------$\n"
  1267. FileWrite $0 "$\n"
  1268. FileWrite $0 "Examples:$\n"
  1269. FileWrite $0 "$\n"
  1270. FileWrite $0 "${OutFile} /S$\n"
  1271. FileWrite $0 "$\n"
  1272. FileWrite $0 "${OutFile} /S /minion-name=myminion /master=master.mydomain.com /start-minion-delayed$\n"
  1273. FileWrite $0 "$\n"
  1274. FileWrite $0 "===============================================================================$\n"
  1275. FileWrite $0 "$\n"
  1276. System::Free $0
  1277. System::Free $1
  1278. System::Call 'kernel32::FreeConsole()'
  1279. # Give the user back the prompt
  1280. !define VK_RETURN 0x0D ; Enter Key
  1281. !define KEYEVENTF_EXTENDEDKEY 0x0001
  1282. !define KEYEVENTF_KEYUP 0x0002
  1283. System::Call "user32::keybd_event(i${VK_RETURN}, i0x45, i${KEYEVENTF_EXTENDEDKEY}|0, i0)"
  1284. System::Call "user32::keybd_event(i${VK_RETURN}, i0x45, i${KEYEVENTF_EXTENDEDKEY}|${KEYEVENTF_KEYUP}, i0)"
  1285. Abort
  1286. display_help_not_found:
  1287. # Set default value for Use Existing Config
  1288. StrCpy $ConfigType_State "Existing Config"
  1289. # Check for start-minion switches
  1290. # /start-service is to be deprecated, so we must check for both
  1291. ${GetOptions} $R0 "/start-service=" $R1
  1292. ${GetOptions} $R0 "/start-minion=" $R2
  1293. # Service: Start Salt Minion
  1294. ${IfNot} $R2 == ""
  1295. # If start-minion was passed something, then set it
  1296. StrCpy $StartMinion $R2
  1297. ${ElseIfNot} $R1 == ""
  1298. # If start-service was passed something, then set StartMinion to that
  1299. StrCpy $StartMinion $R1
  1300. ${Else}
  1301. # Otherwise default to 1
  1302. StrCpy $StartMinion 1
  1303. ${EndIf}
  1304. # Service: Minion Startup Type Delayed
  1305. ClearErrors
  1306. ${GetOptions} $R0 "/start-minion-delayed" $R1
  1307. IfErrors start_minion_delayed_not_found
  1308. StrCpy $StartMinionDelayed 1
  1309. start_minion_delayed_not_found:
  1310. # Minion Config: Master IP/Name
  1311. # If setting master, we don't want to use existing config
  1312. ${GetOptions} $R0 "/master=" $R1
  1313. ${IfNot} $R1 == ""
  1314. StrCpy $MasterHost_State $R1
  1315. StrCpy $ConfigType_State "Default Config"
  1316. ${ElseIf} $MasterHost_State == ""
  1317. StrCpy $MasterHost_State "salt"
  1318. ${EndIf}
  1319. # Minion Config: Minion ID
  1320. # If setting minion id, we don't want to use existing config
  1321. ${GetOptions} $R0 "/minion-name=" $R1
  1322. ${IfNot} $R1 == ""
  1323. StrCpy $MinionName_State $R1
  1324. StrCpy $ConfigType_State "Default Config"
  1325. ${ElseIf} $MinionName_State == ""
  1326. StrCpy $MinionName_State "hostname"
  1327. ${EndIf}
  1328. # Use Default Config
  1329. ${GetOptions} $R0 "/default-config" $R1
  1330. IfErrors default_config_not_found
  1331. StrCpy $ConfigType_State "Default Config"
  1332. default_config_not_found:
  1333. # Use Custom Config
  1334. # Set default value for Use Custom Config
  1335. StrCpy $CustomConfig_State ""
  1336. # Existing config will get a `.bak` extension
  1337. ${GetOptions} $R0 "/custom-config=" $R1
  1338. ${IfNot} $R1 == ""
  1339. # Custom Config was passed something, set it
  1340. StrCpy $CustomConfig_State $R1
  1341. StrCpy $ConfigType_State "Custom Config"
  1342. ${EndIf}
  1343. FunctionEnd