blob: 56b42af78c9164ceba7479b0f4230c4e986c7598 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
function Get-ScriptDirectory {
if (!$PSScriptRoot) {
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
$PSScriptRoot = Split-Path $Invocation.MyCommand.Path
}
$PSScriptRoot
}
function Run-Command($command, $argList) {
# Take each input string, escape any \ ' or " character in it and then surround it with "s.
# This is to defeat the second-level parsing performed by the MSVCRT argument parser used
# by ruby which only understands \ ' and ".
#
# This is a fuster cluck. Don't touch this unless you are sure you understand regexes.
# The \\ is to request a literal \ match in a regex.
# The "" is to inject a literal " character in a PS string surrounded by "s.
# The replacement pattern must be '\$1' and not "\$1" because $1 is not a real variable
# that needs substituting - it's a capture group that's interpreted by the regex engine.
# \ in the replacement pattern does not need to be escaped - it is literally substituted.
$transformed = $argList | foreach { '"' + ( $_ -replace "([\\'""])",'\$1' ) + '"' }
#& "echoargs.exe" $transformed
# Use the correct embedded ruby path. We'll be deployed at a path that looks like
# [C:\opscode or some other prefix]\chef\modules\chef
$ruby = Join-Path (Get-ScriptDirectory) "..\..\embedded\bin\ruby.exe"
$commandPath = Join-Path (Get-ScriptDirectory) "..\..\bin\$command"
& $ruby $commandPath $transformed
}
function chef-apply {
Run-Command 'chef-apply' $args
}
function chef-client {
Run-Command 'chef-client' $args
}
function chef-service-manager {
Run-Command 'chef-service-manager' $args
}
function chef-shell {
Run-Command 'chef-shell' $args
}
function chef-solo {
Run-Command 'chef-solo' $args
}
function chef-windows-service {
Run-Command 'chef-windows-service' $args
}
function knife {
Run-Command 'knife' $args
}
Export-ModuleMember -function chef-*
Export-ModuleMember -function knife
|