Skip to content

Instantly share code, notes, and snippets.

@bdwyertech
Last active August 23, 2018 00:00
Show Gist options
  • Save bdwyertech/32ddccdbcb95f5cfe98540c483a3956b to your computer and use it in GitHub Desktop.
Save bdwyertech/32ddccdbcb95f5cfe98540c483a3956b to your computer and use it in GitHub Desktop.
Hotfix for Berkshelf to use latest mixlib-archive without chdir issue
# Filename: BerksFix.ps1
# Brian Dwyer - 8/22/18
$bad = 'gem "mixlib-archive", "= 0.4.6"'
$good = 'gem "mixlib-archive", "= 0.4.13"'
$berks_cache = Resolve-Path '~\.berkshelf\cookbooks' -ErrorAction SilentlyContinue
if ($berks_cache) {
'Clearing Berkshelf Cookbook Cache...'
Remove-Item -Recurse $berks_cache
}
'Gathering installed mixlib-archive versions...'
$vers = $(chef exec gem list mixlib-archive)
If (($vers -match '0.4.13') -and ($vers -match '0.4.6')) {
'Updated mixlib-archive already present... Nothing to do'
} Elseif ($vers -match '0.4.6') {
'Detected faulty mixlib-archive version... Updating...'
chef exec gem install mixlib-archive -v 0.4.13
If ($lastexitcode -ne 0) { throw }
} Else {
"Unknown versions detected... Script not designed for $vers"
exit 1
}
$files = @('berks', 'kitchen')
foreach ($file in $files) {
$filepath = [IO.Path]::Combine(($env:Path.Split(';') -match 'chefdk\\bin\\$')[0], $file)
$content = Get-Content -Path $filepath
if ( ($content -match $bad) ) {
"Updating $file"
$content -replace $bad, $good | Set-Content -Path $filepath
} Else {
"Content already up to date. Nothing to do ($file)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment