Skip to content

Instantly share code, notes, and snippets.

@chriswessells
Last active June 8, 2016 19:24
Show Gist options
  • Save chriswessells/54b902b5fa2e2aab1cb38bbbd4dfbf84 to your computer and use it in GitHub Desktop.
Save chriswessells/54b902b5fa2e2aab1cb38bbbd4dfbf84 to your computer and use it in GitHub Desktop.
<#
PowerShell Script that updates the knife-windows bootstrap template so it installs chef as a service.
#>
$basePath = "C:\opscode\chefdk\embedded\lib\ruby\gems"
$folders = Get-ChildItem -Path $basePath
$knifeWindows = Get-ChildItem -Path "$basepath\$folders\gems"
foreach ($folder in $knifeWindows) {
if ($folder.Name -Like "knife-windows*") {
$knifeWindowsVer = $folder.Name
}
}
$fullBootstrapPath = "$basepath\$folders\gems\$knifeWindowsVer\lib\chef\knife\bootstrap"
$templateFile = Get-ChildItem -Path $fullBootstrapPath
if ($templateFile -is [System.IO.FileSystemInfo]) {
Write-Host "Copying the original bootstrap file to windows-chef-client-msi-original.erb"
copy-item "$fullBootstrapPath\$templateFile" -Destination "$fullBootstrapPath\windows-chef-client-msi-original.erb"
Write-Host "Replacing the default install parameter with install parameters for adding the service"
(Get-Content "$fullBootstrapPath\$templateFile").Replace('<%= install_chef %>',"`n@ECHO Installing Chef...`n@msiexec /qn /i `"%LOCAL_DESTINATION_MSI_PATH%`" ADDLOCAL=`"ChefClientFeature,ChefServiceFeature`"`n@ECHO Installation complete`n@endlocal`n`n") | Set-Content "$fullBootstrapPath\$templateFile"
} else {
if (-not (Test-Path "$fullBootstrapPath\windows-chef-client-msi-original.erb")) {
copy-item "$fullBootstrapPath\$templateFile" -Destination "$fullBootstrapPath\windows-chef-client-msi-original.erb"
} else {
write-host "You may have alread edited the windows-chef-client-msi-original.erb"
Write-Host "Doing nothing, check the folder $fullBootstrapPath"
Write-Host "it should contain one file windows-chef-client-msi.erb"
}
}
@chriswessells
Copy link
Author

Chef Windows

Powershell script that updates the windows bootstrap template to install chef-client as a service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment