Guest User

Untitled

a guest
Dec 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. function Get-ScriptDirectory {
  2. if (!$PSScriptRoot) {
  3. $Invocation = (Get-Variable MyInvocation -Scope 1).Value
  4. $PSScriptRoot = Split-Path $Invocation.MyCommand.Path
  5. }
  6. $PSScriptRoot
  7. }
  8.  
  9. function Run-RubyCommand($command, $argList) {
  10. # Use the correct embedded ruby path. We'll be deployed at a path that looks like
  11. # [C:\opscode or some other prefix]\chef\modules\chef
  12. $ruby = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(
  13. (Join-Path (Get-ScriptDirectory) "../../embedded/bin/ruby.exe")
  14. )
  15. $commandPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(
  16. (Join-Path (Get-ScriptDirectory) "../../bin/$command")
  17. )
  18.  
  19. # create list of process arguments by appending command arguments to ruby command path
  20. $commandArgumentList = @($commandPath) + @($argList)
  21.  
  22. # splat argument list when invoking ruby
  23. & "$ruby" @commandArgumentList
  24. }
  25.  
  26.  
  27. function Invoke-ChefApply {
  28. Run-RubyCommand 'chef-apply' $args
  29. }
  30. Set-Alias -Name chef-apply -Value Invoke-ChefApply
  31.  
  32. function Invoke-ChefClient {
  33. Run-RubyCommand 'chef-client' $args
  34. }
  35. Set-Alias -Name chef-client -Value Invoke-ChefClient
  36.  
  37. function Invoke-ChefServiceManager {
  38. Run-RubyCommand 'chef-service-manager' $args
  39. }
  40. Set-Alias -Name chef-service-manager -Value Invoke-ChefServiceManager
  41.  
  42. function Invoke-ChefShell {
  43. Run-RubyCommand 'chef-shell' $args
  44. }
  45. Set-Alias -Name chef-shell -Value Invoke-ChefShell
  46.  
  47. function Invoke-ChefSolo {
  48. Run-RubyCommand 'chef-solo' $args
  49. }
  50. Set-Alias -Name chef-solo -Value Invoke-ChefSolo
  51.  
  52. function Invoke-ChefWindowsService {
  53. Run-RubyCommand 'chef-windows-service' $args
  54. }
  55. Set-Alias -Name chef-windows-service -Value Invoke-ChefWindowsService
  56.  
  57. function Invoke-Knife {
  58. Run-RubyCommand 'knife' $args
  59. }
  60. Set-Alias -Name knife -Value Invoke-Knife
  61.  
  62. Export-ModuleMember -Function Invoke-ChefApply
  63. Export-ModuleMember -Alias chef-apply
  64.  
  65. Export-ModuleMember -Function Invoke-ChefClient
  66. Export-ModuleMember -Alias chef-client
  67.  
  68. Export-ModuleMember -Function Invoke-ChefServiceManager
  69. Export-ModuleMember -Alias chef-service-manager
  70.  
  71. Export-ModuleMember -Function Invoke-ChefShell
  72. Export-ModuleMember -Alias chef-shell
  73.  
  74. Export-ModuleMember -Function Invoke-ChefSolo
  75. Export-ModuleMember -Alias chef-solo
  76.  
  77. Export-ModuleMember -Function Invoke-ChefWindowsService
  78. Export-ModuleMember -Alias chef-windows-service
  79.  
  80. Export-ModuleMember -Function Invoke-Knife
  81. Export-ModuleMember -Alias knife
  82.  
  83. # To debug this module, uncomment the line below
  84. # Export-ModuleMember -function Run-RubyCommand
  85.  
  86. # Then run the following to reload the module. Use puts_argv as a helpful debug executable.
  87. # Remove-Module chef
  88. # Import-Module chef
  89. # "puts ARGV" | Out-File C:\opscode\chef\bin\puts_args -Encoding ASCII
  90. # Copy-Item C:\opscode\chef\bin\ohai.bat C:\opscode\chef\bin\puts_args.bat
  91. # Run-RubyCommand puts_args 'Here' "are" some '"very interesting"' 'arguments[to]' "`"try out`""
Add Comment
Please, Sign In to add comment