Salt-Minion-Setup.nsi 59 KB

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