]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - 3rdparty/modules/staging/lib/facter/staging_http_get.rb
add nanliu/staging to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / staging / lib / facter / staging_http_get.rb
diff --git a/3rdparty/modules/staging/lib/facter/staging_http_get.rb b/3rdparty/modules/staging/lib/facter/staging_http_get.rb
new file mode 100644 (file)
index 0000000..9f55b47
--- /dev/null
@@ -0,0 +1,29 @@
+Facter.add("staging_http_get") do
+  setcode do
+
+    fact = nil
+
+    which = lambda do |cmd|
+      result = nil
+      exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
+      ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
+        exts.each do |ext|
+          exe = File.join(path, "#{cmd}#{ext}")
+          result = exe if File.executable? exe
+          break if result
+        end
+        break if result
+      end
+      result
+    end
+
+    ['powershell', 'curl', 'wget'].each do |cmd|
+      available = which.call(cmd)
+      fact = available ? cmd : nil
+      break if fact
+    end
+
+    fact
+
+  end
+end