summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorGravatar Daniel Washburn <daniel@washburn.at> 2018-07-13 10:44:07 -0400
committerGravatar Daniel Washburn <daniel@washburn.at> 2018-07-13 10:44:07 -0400
commit2da2fed5f9c21288cbe8a807458a8f56272631af (patch)
treea6411cfdbd34290e6020ef3598649d7d08c2bd07 /modules
parent3ce94f1b5124daceb255ad7de4ab58b0c8b69188 (diff)
downloadpuppet-slackware-master.tar.gz
puppet-slackware-master.tar.bz2
puppet-slackware-master.zip
Add Slackware package and service and slapt-get package providersHEADmaster
Diffstat (limited to 'modules')
-rw-r--r--modules/slackware/lib/puppet/provider/package/slackware.rb73
-rw-r--r--modules/slackware/lib/puppet/provider/service/slackware.rb84
-rw-r--r--modules/slapt/lib/puppet/provider/package/slapt.rb120
3 files changed, 277 insertions, 0 deletions
diff --git a/modules/slackware/lib/puppet/provider/package/slackware.rb b/modules/slackware/lib/puppet/provider/package/slackware.rb
new file mode 100644
index 0000000..32ab31f
--- /dev/null
+++ b/modules/slackware/lib/puppet/provider/package/slackware.rb
@@ -0,0 +1,73 @@
+# puppet/provider/package/slackware.rb
+require 'puppet/provider/package'
+
+# Slackware Linux pkgtools
+Puppet::Type.type(:package).provide :slackware, :parent => Puppet::Provider::Package do
+ desc "Slackware package maintenance system. Requires `/sbin/removepkg` and `/sbin/upgradepkg`."
+
+ has_feature :installable
+ has_feature :uninstallable
+
+ # Regex to match Slackware packages
+ # Name, Version, Architecure, and Build
+ SLACK_REGEX = /^(.*)-(\d|\w[^-]*)[-]([\w_]+)[-](\d+?.*?)$/
+ SLACK_NVAB_FIELDS = [:name, :version, :arch, :build]
+
+ commands :upgradepkg => "/sbin/upgradepkg",
+ :removepkg => "/sbin/removepkg"
+
+ defaultfor :operatingsystem => :slackware
+ confine :operatingsystem => :slackware
+
+
+ def self.instances
+ packages = []
+ # list the contents of /var/log/packages
+ cmd = "/bin/ls -1 /var/log/packages/"
+ 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 query
+ self.class.instances.each do |provider|
+ if provider.name == @resource.name
+ return provider.properties
+ end
+ end
+ nil
+ end
+
+
+ def install
+ unless source = @resource[:source]
+ raise ArgumentError, "You cannot install Slackware packages without a source"
+ end
+ upgradepkg("--install-new", source)
+ end
+
+
+ def uninstall
+ nvab = "#{get(:name)}-#{get(:version)}-#{get(:arch)}-#{get(:build)}"
+ removepkg(nvab)
+ end
+
+
+ def self.nvab_to_hash(line)
+ line.chomp!
+ hash = {}
+ match = SLACK_REGEX.match(line.split[0])
+ SLACK_NVAB_FIELDS.zip(match[1,4]) { |f, v| hash[f] = v }
+ hash[:provider] = self.name
+ hash[:ensure] = "present"
+ hash
+ end
+end
diff --git a/modules/slackware/lib/puppet/provider/service/slackware.rb b/modules/slackware/lib/puppet/provider/service/slackware.rb
new file mode 100644
index 0000000..4c22554
--- /dev/null
+++ b/modules/slackware/lib/puppet/provider/service/slackware.rb
@@ -0,0 +1,84 @@
+# Manage Slackware services
+
+Puppet::Type.type(:service).provide :slackware, :parent => :init do
+ desc "Manage Slackware's old-school BSD-style init scripts. Services
+ are enabled or disabled by toggling the executable bit."
+
+ defaultfor :operatingsystem => :slackware
+ confine :operatingsystem => :slackware
+
+ has_feature :enableable
+ has_feature :refreshable
+
+ def self.defpath
+ "/etc/rc.d"
+ end
+
+ def self.excludes
+ exclude = []
+ # Runlevel init scripts and symlinks thereto
+ exclude += %w{rc.0 rc.4 rc.6 rc.K rc.M rc.S}
+ # Additional system init scripts which aren't, strictly
+ # speaking, services
+ exclude += %w{rc.inet1 rc.inet2 rc.loop rc.font}
+ # rc.inet1.conf is a configuration file
+ exclude += %w{rc.inet1.conf}
+ end
+
+ def self.instances
+ get_instances(self.defpath)
+ end
+
+ def self.get_instances(defpath, exclude = self.excludes)
+ path = defpath
+ instances = []
+ unless FileTest.directory?(path)
+ Puppet.debug "Service path #{path} does not exist"
+ end
+
+ check = [:ensure]
+
+ check << :enable if public_method_defined? :enabled?
+
+ Dir.entries(path).each do |script|
+ fullpath = File.join(path, script)
+ next if script =~ /^\./
+ next if exclude.include? script
+ next if FileTest.directory?(fullpath)
+ next if FileTest.symlink?(fullpath)
+ name = /^rc\.(.*)$/.match(script)[1]
+ instances << new(:name => name, :path => path, :hasstatus => :false)
+ end
+ instances
+ end
+
+ def search(name)
+ paths.each { |path|
+ fqname_sh = File.join(path,"rc.#{name}")
+ begin
+ stat = File.stat(fqname_sh)
+ rescue
+ # should probably rescue specific errors...
+ self.debug("Could not find rc.#{name} in #{path}")
+ next
+ end
+
+ # if we've gotten this far, we found a valid script
+ return fqname_sh
+ }
+ raise Puppet::Error, "Could not find init script for '#{name}'"
+ end
+
+ def enabled?
+ FileTest.executable?(initscript)
+ end
+
+ def enable
+ File.chmod(0755, initscript) if not FileTest.executable?(initscript)
+ end
+
+ def disable
+ File.chmod(0644, initscript) if FileTest.executable?(initscript)
+ end
+
+end
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