mixlibrary-core 0.0.10-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +13 -0
- data/README.md +64 -0
- data/lib/mixlibrary/core/apps/_dependencies.rb +7 -0
- data/lib/mixlibrary/core/apps/shell.rb +3 -0
- data/lib/mixlibrary/core/apps/utilities.rb +4 -0
- data/lib/mixlibrary/core/shell/app.rb +55 -0
- data/lib/mixlibrary/core/shell/scripts/base.rb +32 -0
- data/lib/mixlibrary/core/shell/scripts/powershell.rb +145 -0
- data/lib/mixlibrary/core/shell/scripts/shelloutwrapper.rb +111 -0
- data/lib/mixlibrary/core/shell/scripts/windows_script.rb +55 -0
- data/lib/mixlibrary/core/shell/shell_call.rb +28 -0
- data/lib/mixlibrary/core/utilities/ruby_info.rb +31 -0
- data/lib/mixlibrary/core/utilities/windows_architecture_helper.rb +79 -0
- data/lib/mixlibrary/core/version.rb +6 -0
- data/lib/mixlibrary/core/windows/features.rb +8 -0
- metadata +165 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7c83fe0d62a694a7e1dad5cd238947981c4dde9d
|
4
|
+
data.tar.gz: 8148c0655f4d391e8266b0af0bbb14a2f4f296ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00ccd0f0074d345e5d3df36ab60636cc6fb417f19def1177c8fea53e3a4b8ebf5bd732a3c874ab61e22de95e4244d4d4b07157a74b793bd3231bae3b4357adb1
|
7
|
+
data.tar.gz: 1b22b143753da755ce012bb253bcda829c196ad6441fe7f58216d0961b536a60322da1385fca7b5cd53649c8ab91b9fcce10904579c0658030e9fbac3ba35beb
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2014 EBSCO Information Services
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Mixlibrary-Core
|
2
|
+
[](https://travis-ci.org/ebsco/mixlibrary-core)
|
3
|
+
|
4
|
+
Wraps some provider functionality from chef into easily consumable ruby classes that do not have the extra baggage of being dependent on Chef data objects. Node object, Environment etc.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'mixlibrary-core'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle install
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install mixlibrary-core
|
19
|
+
|
20
|
+
## How to Install via Chef Recipe
|
21
|
+
* [Recipe Install Sample](https://github.com/ebsco/mixlibrary-core/blob/master/Samples/SampleRecipeDeployment.rb)
|
22
|
+
|
23
|
+
## Documentation
|
24
|
+
* Uses yard to document classes and methods. Generate docs or automatic documentation: http://www.rubydoc.info
|
25
|
+
* rake doc
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
### Windows Oriented
|
30
|
+
|
31
|
+
#### Powershell Scripts
|
32
|
+
Needed ability to execute powershell scripts and get the powershell process back. So to execute a powershell script:
|
33
|
+
|
34
|
+
```
|
35
|
+
require 'mixlibrary/core/apps/shell'
|
36
|
+
|
37
|
+
script= <<-EOF
|
38
|
+
write-host "Hello 'World'"
|
39
|
+
EOF
|
40
|
+
|
41
|
+
procobj = Mixlibrary::Core::Shell.windows_script_out!(:powershell,script)
|
42
|
+
```
|
43
|
+
|
44
|
+
#### Batch
|
45
|
+
Not Implemented yet
|
46
|
+
|
47
|
+
### Linux Oriented
|
48
|
+
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
# Run All the Tests on your platform and build the gem
|
52
|
+
|
53
|
+
bundle install
|
54
|
+
|
55
|
+
bundle exec rake
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
1. Fork it (http://github.com/<my-github-username>/mixlibrary-core/fork)
|
61
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
64
|
+
5. Create new Pull Request
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#This file defines the typical entrypoint into this shell code base. Other entrypoints can be used, but this one is currently made easiest
|
2
|
+
#by including an apps folder at the top level and including this file to get the pieces that are needed.
|
3
|
+
|
4
|
+
#Could you easily enough require the powershell.rb directly and just outright call it, sure. But most if not all of this code should be stateless. This
|
5
|
+
#implies static methods should be used. After a bunch of reading, there seems to be no real consensus on where static methods belong. I like the idea of classes
|
6
|
+
#but I found more people sticking these methods in the base module, which is what I am doing here. So the way one can interpret this file is it is the base methods
|
7
|
+
#that are exposed in its entirety for the Shell (sub-module) within this Gem. Since everything is stateless no need to expose classes directly unless it is overwhelmingly
|
8
|
+
#more complicated and many methods would need to be exposed (Scalability). (We are just scripting after all....)
|
9
|
+
|
10
|
+
require 'mixlibrary/core/shell/scripts/powershell'
|
11
|
+
require "mixlibrary/core/shell/shell_call"
|
12
|
+
|
13
|
+
module Mixlibrary
|
14
|
+
module Core
|
15
|
+
module Shell
|
16
|
+
|
17
|
+
#########################
|
18
|
+
#Scripts
|
19
|
+
#########################
|
20
|
+
def self.windows_script_out(shellType,script, options=nil, flags=nil,desiredarchitecture=nil)
|
21
|
+
return run_windows_script(shellType,false,script, options, flags,desiredarchitecture)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.windows_script_out!(shellType,script, options=nil, flags=nil,desiredarchitecture=nil )
|
25
|
+
return run_windows_script(shellType,true,script, options, flags,desiredarchitecture)
|
26
|
+
end
|
27
|
+
|
28
|
+
#########################
|
29
|
+
#Shell Out
|
30
|
+
#########################
|
31
|
+
def self.shell_out!(command, options=nil)
|
32
|
+
shellclass=Shell::ShellCall.new
|
33
|
+
return shellclass.shell!(command, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.shell_out(command, options=nil)
|
37
|
+
shellclass=Shell::ShellCall.new
|
38
|
+
return shellclass.shell(command, options)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def self.run_windows_script(shellType, validate, script, options, flags, architecture)
|
43
|
+
case shellType
|
44
|
+
when :powershell
|
45
|
+
|
46
|
+
obj= Shell::Scripts::Powershell.new(script, validate, options, flags,architecture)
|
47
|
+
return obj.orchestrate
|
48
|
+
|
49
|
+
else
|
50
|
+
raise "Shell not supported. Currently supports: :powershell for now!"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "mixlibrary/core/shell/scripts/shelloutwrapper"
|
2
|
+
|
3
|
+
module Mixlibrary
|
4
|
+
module Core
|
5
|
+
module Shell
|
6
|
+
class Scripts
|
7
|
+
|
8
|
+
#Base class for all script classes. Provides an Interface of sorts that all other classes must implement and also provides the base methods that would need to be implemented.
|
9
|
+
class Base
|
10
|
+
|
11
|
+
#Orchestrates running the script. Might be as simple as calling shell_out or more complicated like doing syntax validation of the script before execution
|
12
|
+
def orchestrate
|
13
|
+
raise "Not Implemented Exception"
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def run_command(shell_executable, flags, filename_prefix, file_extension, code,shellout_options, eval_error)
|
19
|
+
shellobj =Scripts::ShellOutWrapper.new(shell_executable, flags, filename_prefix, file_extension, code, shellout_options)
|
20
|
+
|
21
|
+
if(eval_error)
|
22
|
+
return shellobj.run_command!
|
23
|
+
else
|
24
|
+
return shellobj.run_command
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
#Runs powershell scripts with the least amount of intrusion possible. We do some syntax checking and validation that the script did not end badly, but other than that, we
|
2
|
+
#try to leave the executing script in the hands of the developer.
|
3
|
+
require "chef"
|
4
|
+
require "mixlibrary/core/shell/scripts/windows_script"
|
5
|
+
|
6
|
+
module Mixlibrary
|
7
|
+
module Core
|
8
|
+
module Shell
|
9
|
+
class Scripts
|
10
|
+
class Powershell < WindowsScript
|
11
|
+
@originalScript =nil
|
12
|
+
@validate =nil
|
13
|
+
@options =nil
|
14
|
+
@flagoverrides =nil
|
15
|
+
|
16
|
+
def initialize(script, validate, options, flags, architecture = nil)
|
17
|
+
super(architecture)
|
18
|
+
@originalScript=script
|
19
|
+
@options = options
|
20
|
+
@validate=validate
|
21
|
+
@flagoverrides=flags
|
22
|
+
end
|
23
|
+
|
24
|
+
def orchestrate
|
25
|
+
#Powershell kind of sucks with syntax checking.
|
26
|
+
#If any part of the script syntactically fails it will exit with a clean exit code of 0
|
27
|
+
#So this forced our hand to call powershell twice for every script call.
|
28
|
+
#1 - Put passed in script in a function to see if any standard error is generated -
|
29
|
+
#only will happen if syntax is incorrect since function is never called
|
30
|
+
#2 - Run the user script with exception wraps to guarantee some exit status
|
31
|
+
syntax_check()
|
32
|
+
|
33
|
+
myscriptstring = finalscript()
|
34
|
+
Chef::Log::debug("Script Contents:")
|
35
|
+
Chef::Log::debug("-----------------------------------------------------")
|
36
|
+
Chef::Log::debug(myscriptstring)
|
37
|
+
Chef::Log::debug("-----------------------------------------------------")
|
38
|
+
return run_command(shell,flags,filename,file_extension, myscriptstring, @options, @validate)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
EXIT_STATUS_EXITCONVERSION = <<-EOF
|
44
|
+
\#This function changes the exit code as desired back to ruby code.
|
45
|
+
function exit-mixlibpowershell([int] $exitcode){
|
46
|
+
[Environment]::Exit($exitcode)
|
47
|
+
}
|
48
|
+
EOF
|
49
|
+
|
50
|
+
EXIT_STATUS_EXCEPTION_HANDLER= <<-EOF
|
51
|
+
trap [Exception]{
|
52
|
+
write-error "Trapped in Trap Exception block" -erroraction continue;
|
53
|
+
write-error -exception ($_.Exception.Message) -erroraction continue;
|
54
|
+
exit-mixlibpowershell 1
|
55
|
+
}
|
56
|
+
EOF
|
57
|
+
|
58
|
+
EXIT_STATUS_RESET_SCRIPT= <<-EOF
|
59
|
+
$LASTEXITCODE=0
|
60
|
+
EOF
|
61
|
+
|
62
|
+
#Make this set-variable call a read only. Technically can be overridden but most of PS scripts that set this setting,
|
63
|
+
#usually try to set this by doing things like $ERRORACTIONPREFERENCE="Stop"
|
64
|
+
#Generally speaking this is the best way to handle this situation. We will need to determine if there are many dependent scripts
|
65
|
+
#that depend on being able to set this setting.
|
66
|
+
EXIT_STATUS_INTIALIZATION= <<-EOF
|
67
|
+
|
68
|
+
Set-Variable -Name ERRORACTIONPREFERENCE -Value "STOP" -Scope Script -Option "ReadOnly" -force
|
69
|
+
\#$ErrorActionPreference="STOP"
|
70
|
+
try{
|
71
|
+
EOF
|
72
|
+
|
73
|
+
EXIT_STATUS_POST= <<-EOF
|
74
|
+
exit-mixlibpowershell $LASTEXITCODE
|
75
|
+
}
|
76
|
+
catch{
|
77
|
+
write-error "Trapped in Catch block" -erroraction continue;
|
78
|
+
write-error -exception ($_.Exception) -erroraction continue;
|
79
|
+
exit-mixlibpowershell 1
|
80
|
+
}
|
81
|
+
EOF
|
82
|
+
|
83
|
+
#Validate valid powershell was passed in.
|
84
|
+
def syntax_check
|
85
|
+
local_script_contents=("function testme(){ \n #{@originalScript.to_s} \n} \n")
|
86
|
+
|
87
|
+
result = run_command(shell,flags,filename,file_extension, local_script_contents, @options, false)
|
88
|
+
#puts result.inspect
|
89
|
+
if(result.stderr.length >= 1 || result.exitstatus !=0)
|
90
|
+
#puts "Standard Output: \n #{result.stdout}"
|
91
|
+
#puts "Standard Error: \n #{result.stderr}"
|
92
|
+
raise RuntimeError,"Did not syntactically pass the powershell check. \n Standard out: #{result.stdout} \n Standard Error:#{result.stderr}"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def finalscript
|
97
|
+
changed_script =
|
98
|
+
EXIT_STATUS_EXITCONVERSION +
|
99
|
+
EXIT_STATUS_EXCEPTION_HANDLER +
|
100
|
+
EXIT_STATUS_RESET_SCRIPT +
|
101
|
+
EXIT_STATUS_INTIALIZATION +
|
102
|
+
@originalScript +
|
103
|
+
EXIT_STATUS_POST
|
104
|
+
|
105
|
+
return changed_script
|
106
|
+
end
|
107
|
+
|
108
|
+
def flags
|
109
|
+
flags = [
|
110
|
+
# Hides the copyright banner at startup.
|
111
|
+
"-NoLogo",
|
112
|
+
# Does not present an interactive prompt to the user.
|
113
|
+
"-NonInteractive",
|
114
|
+
# Does not load the Windows PowerShell profile.
|
115
|
+
"-NoProfile",
|
116
|
+
# always set the ExecutionPolicy flag
|
117
|
+
# see http://technet.microsoft.com/en-us/library/ee176961.aspx
|
118
|
+
"-ExecutionPolicy RemoteSigned",
|
119
|
+
# Powershell will hang if STDIN is redirected
|
120
|
+
# http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected
|
121
|
+
"-InputFormat None",
|
122
|
+
|
123
|
+
"-File"
|
124
|
+
]
|
125
|
+
return @flagoverrides if @flagoverrides != nil
|
126
|
+
return flags.join(' ')
|
127
|
+
end
|
128
|
+
|
129
|
+
def shell
|
130
|
+
return "powershell.exe"
|
131
|
+
end
|
132
|
+
|
133
|
+
def filename
|
134
|
+
return "tempPSchef"
|
135
|
+
end
|
136
|
+
|
137
|
+
def file_extension
|
138
|
+
return ".ps1"
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
#Wraps calling shell out with any script file. Will create the script file execute the shell out command and delete the file once complete
|
2
|
+
|
3
|
+
require "mixlibrary/core/shell/shell_call"
|
4
|
+
module Mixlibrary
|
5
|
+
module Core
|
6
|
+
module Shell
|
7
|
+
class Scripts
|
8
|
+
class ShellOutWrapper
|
9
|
+
@exe
|
10
|
+
@flags
|
11
|
+
@filename
|
12
|
+
@fileext
|
13
|
+
@code
|
14
|
+
@shellout_options
|
15
|
+
|
16
|
+
#runtime
|
17
|
+
@script_file
|
18
|
+
|
19
|
+
def initialize(exe, flags, filename, fileext, code, shellout_options)
|
20
|
+
@exe=exe
|
21
|
+
@flags=flags
|
22
|
+
@filename=filename
|
23
|
+
@fileext=fileext
|
24
|
+
@code=code
|
25
|
+
if(shellout_options==nil)
|
26
|
+
@shellout_options= Hash.new()
|
27
|
+
else
|
28
|
+
@shellout_options=shellout_options
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
public
|
33
|
+
#Supported options
|
34
|
+
#opts[:domain]
|
35
|
+
#opts[:password]
|
36
|
+
#opts[:timeout] = @new_resource.timeout || 3600
|
37
|
+
#opts[:returns] = @new_resource.returns if @new_resource.returns
|
38
|
+
#opts[:environment] = @new_resource.environment if @new_resource.environment
|
39
|
+
#opts[:user] = @new_resource.user if @new_resource.user
|
40
|
+
#opts[:group] = @new_resource.group if @new_resource.group
|
41
|
+
#opts[:cwd] = @new_resource.cwd if @new_resource.cwd
|
42
|
+
#opts[:umask] = @new_resource.umask if @new_resource.umask
|
43
|
+
#opts[:log_level] = :info
|
44
|
+
#opts[:log_tag] = @new_resource.to_s
|
45
|
+
#cmd = Chef::ShellOut.new("apachectl", "start", :user => 'www', :env => nil, :cwd => '/tmp')
|
46
|
+
#puts "#{script_file.path}"
|
47
|
+
|
48
|
+
def run_command
|
49
|
+
return shellout(false)
|
50
|
+
end
|
51
|
+
|
52
|
+
def run_command!
|
53
|
+
return shellout(true)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def set_owner_and_group
|
59
|
+
# FileUtils itself implements a no-op if +user+ or +group+ are nil
|
60
|
+
# You can prove this by running FileUtils.chown(nil,nil,'/tmp/file')
|
61
|
+
# as an unprivileged user.
|
62
|
+
#puts "#{@shellout_options.inspect}"
|
63
|
+
::FileUtils.chown(@shellout_options[:user], @shellout_options[:group], @script_file.path)
|
64
|
+
end
|
65
|
+
|
66
|
+
def script_file
|
67
|
+
#puts "File name #{filename}"
|
68
|
+
@script_file ||= Tempfile.open([@filename, @fileext])
|
69
|
+
end
|
70
|
+
|
71
|
+
def unlink_script_file
|
72
|
+
@script_file && @script_file.close!
|
73
|
+
@script_file=nil
|
74
|
+
end
|
75
|
+
|
76
|
+
def create_file ()
|
77
|
+
#Output script to file path
|
78
|
+
script_file.puts(@code)
|
79
|
+
script_file.close
|
80
|
+
|
81
|
+
set_owner_and_group
|
82
|
+
end
|
83
|
+
|
84
|
+
def shellout(eval_error)
|
85
|
+
begin
|
86
|
+
create_file()
|
87
|
+
|
88
|
+
shellclass=Shell::ShellCall.new
|
89
|
+
if(eval_error)
|
90
|
+
result = shellclass.shell!("#{@exe} #{@flags} #{@script_file.path}", @shellout_options)
|
91
|
+
return result
|
92
|
+
else
|
93
|
+
result = shellclass.shell("#{@exe} #{@flags} #{@script_file.path}", @shellout_options)
|
94
|
+
return result
|
95
|
+
end
|
96
|
+
|
97
|
+
rescue Exception => e
|
98
|
+
#puts e.message
|
99
|
+
#puts e.backtrace.inspect
|
100
|
+
raise
|
101
|
+
|
102
|
+
ensure
|
103
|
+
unlink_script_file
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#All windows scripts will inherit from here
|
2
|
+
require "mixlibrary/core/shell/scripts/base"
|
3
|
+
require 'mixlibrary/core/apps/utilities'
|
4
|
+
|
5
|
+
module Mixlibrary
|
6
|
+
module Core
|
7
|
+
module Shell
|
8
|
+
class Scripts
|
9
|
+
class WindowsScript < Base
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
@targetarchitecutre = nil;
|
14
|
+
@should_override = nil
|
15
|
+
|
16
|
+
def initialize(architecture)
|
17
|
+
super()
|
18
|
+
|
19
|
+
#The target arch is either what the machine is or passed in parameter
|
20
|
+
@targetarchitecutre = architecture.nil? ? Utilities::WindowsArchitectureHelper.architecture : architecture
|
21
|
+
@should_override = Utilities::WindowsArchitectureHelper.wow64_architecture_override_required?(@targetarchitecutre)
|
22
|
+
|
23
|
+
#why do we care here? If user wants a 32bit process call the 32 bit executable?
|
24
|
+
if ( @targetarchitecutre == :i386 )
|
25
|
+
if (RubyInfo.architecture==:x86_64)
|
26
|
+
raise "Support for the i386 architecture from a 64-bit Ruby runtime is not supported. Please call the specific 32 bit assembly directly"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def run_command(shell_executable, flags, filename_prefix, file_extension, code,shellout_options, eval_error)
|
33
|
+
wow64_redirection_state = nil
|
34
|
+
|
35
|
+
if @should_override
|
36
|
+
#puts "Disabling redirection"
|
37
|
+
wow64_redirection_state = Utilities::WindowsArchitectureHelper.disable_wow64_file_redirection()
|
38
|
+
end
|
39
|
+
|
40
|
+
begin
|
41
|
+
return super(shell_executable, flags, filename_prefix, file_extension, code,shellout_options, eval_error)
|
42
|
+
rescue
|
43
|
+
raise
|
44
|
+
ensure
|
45
|
+
if ! wow64_redirection_state.nil?
|
46
|
+
#puts "Restoring redirection"
|
47
|
+
Utilities::WindowsArchitectureHelper.restore_wow64_file_redirection(wow64_redirection_state)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#We had our hand forced here. We had to make this an instantianted class because the Ruby Include syntax does not work with entirely static methods.
|
2
|
+
|
3
|
+
module Mixlibrary
|
4
|
+
module Core
|
5
|
+
module Shell
|
6
|
+
class ShellCall
|
7
|
+
include Chef::Mixin::ShellOut
|
8
|
+
|
9
|
+
def intialize ()
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def shell(command, options)
|
14
|
+
result = shell_out("#{command}", options)
|
15
|
+
return result
|
16
|
+
end
|
17
|
+
|
18
|
+
def shell!(command, options)
|
19
|
+
result = shell_out!("#{command}", options)
|
20
|
+
return result
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#Begin defining constant symbols for ruby versions
|
2
|
+
|
3
|
+
module Mixlibrary
|
4
|
+
module Core
|
5
|
+
module Utilities
|
6
|
+
class RubyInfo
|
7
|
+
|
8
|
+
def self.windows?
|
9
|
+
if RUBY_PLATFORM =~ /mswin|mingw|windows/
|
10
|
+
true
|
11
|
+
else
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.architecture
|
17
|
+
#x64-mingw32
|
18
|
+
#i386-mingw32
|
19
|
+
myarch = RbConfig::CONFIG["arch"]
|
20
|
+
if(myarch.upcase.include?("I386"))
|
21
|
+
return :i386
|
22
|
+
elsif (myarch.upcase.include?("X64"))
|
23
|
+
return :x86_64
|
24
|
+
else
|
25
|
+
raise "Unsupported arch found: #{myarch}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'mixlibrary/core/utilities/ruby_info'
|
2
|
+
require 'win32/api' if Mixlibrary::Core::Utilities::RubyInfo.windows?
|
3
|
+
|
4
|
+
module Mixlibrary
|
5
|
+
module Core
|
6
|
+
module Utilities
|
7
|
+
class WindowsArchitectureHelper
|
8
|
+
|
9
|
+
#Attempts to determine if this machine is 64 bit or not in a variety of ways - using generic ruby and/or Windows specific environment variabes
|
10
|
+
def self.is_machine_64bit?
|
11
|
+
if(RubyInfo.architecture==:x86_64)
|
12
|
+
return true
|
13
|
+
end
|
14
|
+
|
15
|
+
if(ENV.has_key?('ProgramFiles(x86)'))
|
16
|
+
return true;
|
17
|
+
end
|
18
|
+
|
19
|
+
if(ENV.has_key?('PROCESSOR_ARCHITEW6432'))
|
20
|
+
return true;
|
21
|
+
end
|
22
|
+
|
23
|
+
return false;
|
24
|
+
end
|
25
|
+
|
26
|
+
#returns the architecture based on if the machine is 64 bit
|
27
|
+
def self.architecture
|
28
|
+
if(is_machine_64bit?)
|
29
|
+
return :x86_64
|
30
|
+
else
|
31
|
+
return :i386
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
#Determines if the syswow redirection needs to be disabled based on the desired architecture.
|
36
|
+
def self.wow64_architecture_override_required?(desired_architecture)
|
37
|
+
#only use case we need to disable redirection is if
|
38
|
+
#running as 32 bit
|
39
|
+
#want 64 bit
|
40
|
+
#On 64bit machine
|
41
|
+
RubyInfo.architecture==:i386 &&
|
42
|
+
desired_architecture == :x86_64 &&
|
43
|
+
is_machine_64bit?
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
#Disables syswow redirection
|
48
|
+
def self.disable_wow64_file_redirection()
|
49
|
+
original_redirection_state = ['0'].pack('P')
|
50
|
+
|
51
|
+
win32_wow_64_disable_wow_64_fs_redirection =
|
52
|
+
::Win32::API.new('Wow64DisableWow64FsRedirection', 'P', 'L', 'kernel32')
|
53
|
+
|
54
|
+
succeeded = win32_wow_64_disable_wow_64_fs_redirection.call(original_redirection_state)
|
55
|
+
|
56
|
+
if succeeded == 0
|
57
|
+
raise "Failed to disable Wow64 file redirection"
|
58
|
+
end
|
59
|
+
|
60
|
+
return original_redirection_state
|
61
|
+
end
|
62
|
+
|
63
|
+
#Restore syswow redirection
|
64
|
+
def self.restore_wow64_file_redirection(original_redirection_state )
|
65
|
+
|
66
|
+
win32_wow_64_revert_wow_64_fs_redirection =
|
67
|
+
::Win32::API.new('Wow64RevertWow64FsRedirection', 'P', 'L', 'kernel32')
|
68
|
+
|
69
|
+
succeeded = win32_wow_64_revert_wow_64_fs_redirection.call(original_redirection_state)
|
70
|
+
|
71
|
+
if succeeded == 0
|
72
|
+
raise "Failed to revert Wow64 file redirection"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mixlibrary-core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.10
|
5
|
+
platform: x86-mingw32
|
6
|
+
authors:
|
7
|
+
- Nicholas Carpenter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-reporters
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: chef
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '11.16'
|
90
|
+
- - <
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '13'
|
93
|
+
type: :runtime
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '11.16'
|
100
|
+
- - <
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '13'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: win32-api
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.5.1
|
110
|
+
type: :runtime
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 1.5.1
|
117
|
+
description: 'MixLib for creating Core libraries in ruby for automating machines. This
|
118
|
+
is an abstraction away from using Chef Providers directly to give us access to the
|
119
|
+
lower layers of Chef implementation to meet additional use cases. '
|
120
|
+
email:
|
121
|
+
- ncarpenter@ebsco.com
|
122
|
+
executables: []
|
123
|
+
extensions: []
|
124
|
+
extra_rdoc_files: []
|
125
|
+
files:
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- lib/mixlibrary/core/apps/_dependencies.rb
|
129
|
+
- lib/mixlibrary/core/apps/shell.rb
|
130
|
+
- lib/mixlibrary/core/apps/utilities.rb
|
131
|
+
- lib/mixlibrary/core/shell/app.rb
|
132
|
+
- lib/mixlibrary/core/shell/scripts/base.rb
|
133
|
+
- lib/mixlibrary/core/shell/scripts/powershell.rb
|
134
|
+
- lib/mixlibrary/core/shell/scripts/shelloutwrapper.rb
|
135
|
+
- lib/mixlibrary/core/shell/scripts/windows_script.rb
|
136
|
+
- lib/mixlibrary/core/shell/shell_call.rb
|
137
|
+
- lib/mixlibrary/core/utilities/ruby_info.rb
|
138
|
+
- lib/mixlibrary/core/utilities/windows_architecture_helper.rb
|
139
|
+
- lib/mixlibrary/core/version.rb
|
140
|
+
- lib/mixlibrary/core/windows/features.rb
|
141
|
+
homepage: https://www.ebsco.com/
|
142
|
+
licenses:
|
143
|
+
- Apache2
|
144
|
+
metadata: {}
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '2.4'
|
159
|
+
requirements: []
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 2.4.1
|
162
|
+
signing_key:
|
163
|
+
specification_version: 4
|
164
|
+
summary: MixLib for creating Core libraries in ruby for automating machines.
|
165
|
+
test_files: []
|