Hello James,

It's below:

Regards,
-Roy

--- type.rb.0.25.1.rc2.stock    2009-10-21 15:56:41.000000000 -0600
+++ type.rb    2009-10-26 09:01:26.000000000 -0600
@@ -25,6 +25,7 @@
     include Puppet::Util::Cacher
     include Puppet::FileCollection::Lookup
     include Puppet::Util::Tagging
+    include Puppet::Util::Execution
 
     ###############################
     # Code related to resource type attributes.
@@ -1259,6 +1260,45 @@
         end
     end
 
+    def self.newcheckme(myname, &block)
+        @checksme ||= {}
+
+        check = newmetaparam(myname, &block)
+        @checksme[myname] = check
+    end
+
+    def self.checks
+        @checksme.keys
+    end
+
+    newcheckme(:unless) do
+        desc "If this parameter is set, then the type will run unless
+            the command returns 0.  For example::
+
+                exec { \"/bin/echo root >> /usr/lib/cron/cron.allow\":
+                    unless => \"/usr/bin/grep root 
/usr/lib/cron/cron.allow 2>/dev/null\"
+                }
+
+            This would add ``root`` to the cron.allow file (on Solaris) 
unless
+            ``grep`` determines it's already there.
+
+            Note that this metaparameter requires the full path to the 
command.
+        "
+
+        munge do |cmds|
+            cmds = [cmds] unless cmds.is_a? Array
+
+            cmds.each do |cmd|
+                @resource.validateexecmd(cmd)
+                output, status = @resource.runexec(cmd, true)
+                if status.exitstatus == 0
+                    self.fail("Unless returned 0 with command: %s" % [cmd])
+                end
+            end
+        end
+    end
+
+
     class RelationshipMetaparam < Puppet::Parameter
         class << self
             attr_accessor :direction, :events, :callback, :subclasses
@@ -1726,6 +1766,69 @@
     end
 
     ###############################
+    # All of the unless code.
+
+    def checkexec(cmd)
+        if cmd =~ /^\//
+            exe = cmd.split(/ /)[0]
+            unless FileTest.exists?(exe)
+                raise ArgumentError, "Could not find executable %s" % exe
+            end
+            unless FileTest.executable?(exe)
+                raise ArgumentError,
+                    "%s is not executable" % exe
+            end
+        else
+            raise ArgumentError,
+                "is somehow not qualified with no search path"
+        end
+    end
+   
+    def runexec(command, check = false)
+        output = nil
+        status = nil
+
+        dir = nil
+
+        checkexec(command)
+
+        dir ||= Dir.pwd
+
+        if check
+            debug "Executing check '#{command}'"
+        else
+            debug "Executing '#{command}'"
+        end
+        begin
+            # Do our chdir
+            Dir.chdir(dir) do
+                environment = {}
+
+                withenv environment do
+                    output, status = 
Puppet::Util::SUIDManager.run_and_capture(
+                        [command]
+                    )
+                    # The shell returns 127 if the command is missing.
+                    if status.exitstatus == 127
+                        raise ArgumentError, output
+                    end
+                end
+            end
+        rescue Errno::ENOENT => detail
+            self.fail detail.to_s
+        end
+
+        return output, status
+    end
+
+    def validateexecmd(cmd)
+        # if we're not fully qualified, require a path
+        if cmd !~ /^\//
+            self.fail "'%s' is both unqualifed and specified no search 
path" % cmd
+        end
+    end
+
+    ###############################
     # All of the scheduling code.
 
     # Look up the schedule and set it appropriately.  This is done after


James Turnbull wrote:
> 2009/10/27 Roy Nielsen <[email protected]>:
>   
>> Should work now, patched type.rb by hand and uploaded the code.
>>
>>     
>
> Can you please re-send the updated patch to the list please.
>
> Thanks
>
> James Turnbull
>
>   


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to