From cb3e067a1f8cf4c683eccf8cd80c7ced63568d8a Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Sun, 21 Jun 2015 18:19:04 +0200 Subject: [PATCH] feature: helper method to check if a default command exists Signed-off-by: Dominik Richter --- lib/resources/command.rb | 11 +++++++++++ lib/vulcano.rb | 1 + 2 files changed, 12 insertions(+) create mode 100644 lib/resources/command.rb diff --git a/lib/resources/command.rb b/lib/resources/command.rb new file mode 100644 index 000000000..e9a845eaa --- /dev/null +++ b/lib/resources/command.rb @@ -0,0 +1,11 @@ +# Copyright (c) 2015 Vulcano Security GmbH. All rights reserved. +module Serverspec::Type + class Command < Base + # Check if a given command (executable) exists + # in the default path + def exists? + cmd = @name + Command.new("type \"#{cmd}\" > /dev/null").exit_status == 0 + end + end +end \ No newline at end of file diff --git a/lib/vulcano.rb b/lib/vulcano.rb index 99d455cb6..a6c3cf9f2 100644 --- a/lib/vulcano.rb +++ b/lib/vulcano.rb @@ -13,6 +13,7 @@ require 'vulcano/rule' require 'vulcano/rspec_json_formatter' require 'resources/audit_policy' +require 'resources/command' require 'resources/file' require 'resources/group_policy' require 'resources/mysql_conf'