summaryrefslogtreecommitdiffstats
path: root/modules/slapt
diff options
context:
space:
mode:
Diffstat (limited to 'modules/slapt')
-rw-r--r--modules/slapt/lib/puppet/provider/package/slapt.rb120
1 files changed, 120 insertions, 0 deletions
diff --git a/modules/slapt/lib/puppet/provider/package/slapt.rb b/modules/slapt/lib/puppet/provider/package/slapt.rb
new file mode 100644
index 0000000..7bd65de
--- /dev/null
+++ b/modules/slapt/lib/puppet/provider/package/slapt.rb
@@ -0,0 +1,120 @@
+# puppet/provider/package/slapt.rb
+require 'puppet/provider/package'
+
+# slapt-get package manager for Slackware Linux. http://software.jaos.org/
+Puppet::Type.type(:package).provide :slapt, :parent => :slackware, :source => :slackware do
+ desc "slapt-get is an APT like system for Slackware package management. Requires `/usr/sbin/slapt-get`"
+
+ has_feature :installable
+ has_feature :uninstallable
+ has_feature :upgradeable
+ has_feature :versionable
+
+ # Regex to match Slackware packages
+ # Name, Version, Architecure, and Build
+ SLAPT_REGEX = /^(.*)-(\d|\w[^-]*)[-]([\w_]+)[-](\d+?[\w.^\s]*)/
+ SLAPT_NVAB_FIELDS = [:name, :version, :arch, :build]
+
+ commands :slapt => "/usr/sbin/slapt-get"
+
+ confine :operatingsystem => :slackware
+ confine :exists => "/usr/sbin/slapt-get"
+
+
+ def self.instances
+ packages = []
+ cmd = "#{command(:slapt)} --installed"
+ Puppet.debug "Executing '#{cmd}'"
+ execpipe(cmd) do |process|
+ hash = {}
+ # now turn each returned line into a package object
+ process.each_line { |line|
+ if hash = nvab_to_hash(line)
+ packages << new(hash)
+ end
+ }
+ end
+ packages
+ end
+
+
+ def install
+ should = @resource.should(:ensure)
+ unless @resource[:source]
+ if File.exist?("/etc/slapt-get/slapt-getrc")
+ File.open("/etc/slapt-get/slapt-getrc", "rb").readlines.each do |line|
+ if matchdata = line.match(/^SOURCE=(.+)\s*$/i)
+ @resource[:source] = matchdata[1]
+ break
+ end
+ end
+ unless @resource[:source]
+ raise Puppet::Error,
+ "No valid source found in /etc/slapt-get/slapt-getrc"
+ end
+ else
+ raise Puppet::Error,
+ "You must specify a package source or configure a source in /etc/slapt-get/slapt-getrc"
+ end
+ end
+
+ cmd = "#{command(:slapt)} --no-prompt --install #{@resource[:name]}"
+ Puppet.debug "Executing '#{cmd}'"
+ if [:latest, :installed, :present].include?(should)
+ output = slapt("--no-prompt", "--install", @resource[:name])
+ else
+ output = slapt("--no-prompt", "--install", @resource[:name], "-#{should}")
+ end
+ end
+
+
+ def latest
+ packages = ""
+ cmd = "#{command(:slapt)} --available"
+ Puppet.debug "Executing '#{cmd}'"
+ execpipe(cmd) do |process|
+ process.each_line { |line|
+ match = SLAPT_REGEX.match(line.split[0])
+ if match[0].match(Regexp.escape(@resource[:name]))
+ Puppet.debug "package: #{match}"
+ packages = "#{match[2]}-#{match[3]}-#{match[4]}"
+ end
+ }
+ end
+ packages
+ end
+
+
+ def query
+ self.class.instances.each do |provider|
+ if provider.name == @resource.name
+ return provider.properties
+ end
+ end
+ nil
+ end
+
+
+ def uninstall
+ nvab = "#{get(:name)}-#{get(:version)}-#{get(:arch)}-#{get(:build)}"
+ cmd = "#{command(:slapt)} --no-prompt --remove #{nvab}"
+ Puppet.debug "Executing '#{cmd}'"
+ slapt("--no-prompt", "--remove", nvab)
+ end
+
+
+ def update
+ self.install
+ end
+
+
+ def self.nvab_to_hash(line)
+ line.chomp!
+ hash = {}
+ match = SLAPT_REGEX.match(line.split[0])
+ SLAPT_NVAB_FIELDS.zip(match[1,4]) { |f, v| hash[f] = v }
+ hash[:provider] = self.name
+ hash[:ensure] = "#{hash[:version]}-#{hash[:arch]}-#{hash[:build]}"
+ hash
+ end
+end