View | Details | Raw Unified | Return to bug 156239
Collapse All | Expand All

(-)b/puppet/Makefile (-1 / +3 lines)
Lines 6-12 Link Here
6
#
6
#
7
7
8
PORTNAME=	puppet
8
PORTNAME=	puppet
9
PORTVERSION=	2.6.6
9
PORTVERSION=	2.6.7
10
PORTREVISION=	1
10
CATEGORIES=	sysutils
11
CATEGORIES=	sysutils
11
MASTER_SITES=	http://www.puppetlabs.com/downloads/puppet/
12
MASTER_SITES=	http://www.puppetlabs.com/downloads/puppet/
12
13
Lines 50-55 RUN_DEPENDS+= rubygem-mongrel>=0:${PORTSDIR}/www/rubygem-mongrel Link Here
50
51
51
.if defined(WITH_PACKAGE_ORIGIN)
52
.if defined(WITH_PACKAGE_ORIGIN)
52
EXTRA_PATCHES+=	${FILESDIR}/optpatch-package_origin
53
EXTRA_PATCHES+=	${FILESDIR}/optpatch-package_origin
54
RUN_DEPENDS+=	${RUBY_SITEARCHLIBDIR}/bz2.so:${PORTSDIR}/archivers/ruby-bz2
53
.endif
55
.endif
54
56
55
.include <bsd.port.pre.mk>
57
.include <bsd.port.pre.mk>
(-)b/puppet/distinfo (-2 / +2 lines)
Lines 1-2 Link Here
1
SHA256 (puppet-2.6.6.tar.gz) = bc613c2764345947268a080ca0595aa6d4dbb0b9eab65d1476ff6542caf1647a
1
SHA256 (puppet-2.6.7.tar.gz) = 90c0741f66d15716cfd76f0b8cd15f5b867056f0180ba160ce868350c6dd4ddc
2
SIZE (puppet-2.6.6.tar.gz) = 1514638
2
SIZE (puppet-2.6.7.tar.gz) = 1530756
(-)b/puppet/files/optpatch-package_origin (-58 / +147 lines)
Lines 1-19 Link Here
1
diff --git a/lib/puppet/provider/package/freebsd.rb b/lib/puppet/provider/package/freebsd.rb
1
diff --git lib/puppet/provider/package/freebsd.rb lib/puppet/provider/package/freebsd.rb
2
index e10a20b..fbda52d 100755
2
index e10a20b..f36e29e 100755
3
--- lib/puppet/provider/package/freebsd.rb
3
--- lib/puppet/provider/package/freebsd.rb
4
+++ lib/puppet/provider/package/freebsd.rb
4
+++ lib/puppet/provider/package/freebsd.rb
5
@@ -1,36 +1,79 @@
5
@@ -1,37 +1,165 @@
6
 Puppet::Type.type(:package).provide :freebsd, :parent => :openbsd do
6
-Puppet::Type.type(:package).provide :freebsd, :parent => :openbsd do
7
-  desc "The specific form of package management on FreeBSD.  This is an
7
-  desc "The specific form of package management on FreeBSD.  This is an
8
-    extremely quirky packaging system, in that it freely mixes between
8
-    extremely quirky packaging system, in that it freely mixes between
9
-    ports and packages.  Apparently all of the tools are written in Ruby,
9
-    ports and packages.  Apparently all of the tools are written in Ruby,
10
-    so there are plans to rewrite this support to directly use those
10
-    so there are plans to rewrite this support to directly use those
11
-    libraries."
11
-    libraries."
12
+  include Puppet::Util::Execution
12
+require 'open-uri'
13
+require 'net/ftp'
14
+require 'bz2'
13
 
15
 
14
-  commands :pkginfo => "/usr/sbin/pkg_info",
16
-  commands :pkginfo => "/usr/sbin/pkg_info",
15
-    :pkgadd => "/usr/sbin/pkg_add",
17
-    :pkgadd => "/usr/sbin/pkg_add",
16
-    :pkgdelete => "/usr/sbin/pkg_delete"
18
-    :pkgdelete => "/usr/sbin/pkg_delete"
19
+Puppet::Type.type(:package).provide :freebsd, :parent => Puppet::Provider::Package do
20
+  include Puppet::Util::Execution
21
+
17
+  desc "The specific form of package management on FreeBSD. Resource names must be
22
+  desc "The specific form of package management on FreeBSD. Resource names must be
18
+  specified as the port origin: <port_category>/<port_name>."
23
+  specified as the port origin: <port_category>/<port_name>."
19
+
24
+
Lines 24-107 index e10a20b..fbda52d 100755 Link Here
24
   confine :operatingsystem => :freebsd
29
   confine :operatingsystem => :freebsd
25
+  defaultfor :operatingsystem => :freebsd
30
+  defaultfor :operatingsystem => :freebsd
26
+
31
+
27
+  def self.instances
32
+  @@lock = Mutex.new
28
+    packages = []
33
+  @@ports_index = nil
29
+    
30
+    output = pkginfo "-aoQ"
31
+    output.split("\n").each do |data|
32
+      lhs, pkg_origin = data.split(":")
33
+      pkg_name = lhs.split("-").slice(0..-2).join("-")
34
+      pkg_version = lhs.split("-")[-1]
35
+
36
+      packages << new({
37
+        :provider => self.name,
38
+        :name     => pkg_origin,
39
+        :ensure   => pkg_version,
40
+      })
41
+    end
42
 
34
 
43
-  def self.listcmd
35
-  def self.listcmd
44
-    command(:pkginfo)
36
-    command(:pkginfo)
45
+    packages
37
+  # fix bug in URI::FTP merge method that tries to set typecode
38
+  # even when other is a string.
39
+  class URI::FTP
40
+    def merge(other)
41
+      tmp = super(other)
42
+      if self != tmp
43
+        tmp.set_typecode(other.typecode) rescue NoMethodError
44
+      end
45
+      return tmp
46
+    end
46
   end
47
   end
47
 
48
 
48
   def install
49
-  def install
49
     should = @resource.should(:ensure)
50
-    should = @resource.should(:ensure)
51
+  def self.parse_pkg_string(pkg_string)
52
+    {
53
+      :pkg_name => pkg_string.split("-").slice(0..-2).join("-"),
54
+      :pkg_version => pkg_string.split("-")[-1],
55
+    }
56
+  end
57
+
58
+  def self.unparse_pkg_info(pkg_info)
59
+    [:pkg_name, :pkg_version].map { |key| pkg_info[key] }.join("-")
60
+  end
50
+  
61
+  
51
+    origin = {}
62
+  def self.parse_origin(origin_path)
52
+    [:category, :name].zip(@resource[:name].split("/")).each { |a,b| origin[a] = b }
63
+    begin
53
+    Puppet.debug "origin => #{origin.inspect}"
64
+      origin = {
54
+    if origin[:name] == nil
65
+        :port_category => origin_path.split("/").fetch(-2),
55
+      raise Puppet::Error.new "package name must be in origin format: <category>/<name>"
66
+        :port_name     => origin_path.split("/").fetch(-1),
67
+      }
68
+    rescue IndexError
69
+      raise Puppet::Error.new "#{origin_path}: not in required origin format: .*/<port_category>/<port_name>"
56
+    end
70
+    end
57
+
71
+    origin
58
+    # source parameter is set
72
+  end
59
+    if @resource[:source]
60
+      source = URI.parse(@resource[:source])
61
+      Puppet.debug "source => #{source.inspect}"
62
 
73
 
63
-    if @resource[:source] =~ /\/$/
74
-    if @resource[:source] =~ /\/$/
64
-      if @resource[:source] =~ /^(ftp|https?):/
75
-      if @resource[:source] =~ /^(ftp|https?):/
65
-        Puppet::Util::Execution::withenv :PACKAGESITE => @resource[:source] do
76
-        Puppet::Util::Execution::withenv :PACKAGESITE => @resource[:source] do
66
-          pkgadd "-r", @resource[:name]
77
-          pkgadd "-r", @resource[:name]
67
+      # URI is for local file path.
78
+  def self.instances
68
+      if (source.scheme == "file" || source.scheme == nil) && source.path
79
+    packages = []
69
+        # Pass pkg_add only the URI path.
80
+    output = pkginfo "-aoQ"
70
+        pkgadd source.path
81
+    output.split("\n").each do |data|
82
+      pkg_string, pkg_origin = data.split(":")
83
+      pkg_info = self.parse_pkg_string(pkg_string)
84
+
85
+      packages << new({
86
+        :provider => self.name,
87
+        :name     => pkg_origin,
88
+        :ensure   => pkg_info[:pkg_version],
89
+      })
90
+    end
91
+    packages
92
+  end
71
+
93
+
72
+      # URI scheme is something other than 'file'.
94
+  def ports_index
73
+      elsif source.scheme && source.host && source.path
95
+    @@lock.synchronize do
74
+        if source.path.end_with?(".tbz") # URI references a package.
96
+      if @@ports_index.nil?
75
+          # Pass pkg_add the entire URI.
97
+        @@ports_index = {}
76
+          pkgadd source.to_s
98
+        uri = source.merge "INDEX.bz2"
77
+        else # Assume URI references a directory.
99
+        Puppet.debug "Fetching INDEX: #{uri.inspect}"
78
+          # Set PACKAGESITE in execution environment to source URI.
100
+        begin
79
+          # Pass pkg_add the origin name.
101
+          open(uri, "r") do |f|
80
+          withenv :PACKAGESITE => source.path.end_with?("/") ? source.to_s : source.to_s << "/" do
102
+            BZ2::Reader.open(f.path) do |f|
81
+            Puppet.debug "ENV['PACKAGESITE'] => #{ENV['PACKAGESITE']}"
103
+              while (line = f.gets)
82
+            pkgadd "-rf", origin[:name]
104
+                fields = line.split("|")
105
+                pkg_info = self.class.parse_pkg_string(fields[0])
106
+                origin = self.class.parse_origin(fields[1])
107
+                @@ports_index[origin] = pkg_info
108
+              end
109
+            end
83
+          end
110
+          end
111
+        rescue IOError, OpenURI::HTTPError, Net::FTPError
112
+          @@ports_index = nil
113
+          raise Puppet::Error.new "Could not fetch ports INDEX: #{$!}"
84
         end
114
         end
85
+
115
-      else
86
+      # URI is not usable by pkg_add
87
       else
88
-        Puppet::Util::Execution::withenv :PKG_PATH => @resource[:source] do
116
-        Puppet::Util::Execution::withenv :PKG_PATH => @resource[:source] do
89
-          pkgadd @resource[:name]
117
-          pkgadd @resource[:name]
90
-        end
118
+      end
91
+        raise Puppet::Error.new "source URI is inappropriate: #{source.inspect}"
119
+    end
120
+    @@ports_index
121
+  end
122
+
123
+  def uri_path
124
+    Facter.loadfacts
125
+    File.join(
126
+      "/", "pub", "FreeBSD", "ports",
127
+      Facter.value(:hardwareisa),
128
+      [
129
+        "packages",
130
+        Facter.value(:kernelmajversion).split(".")[0],
131
+        "stable",
132
+      ].join("-")
133
+    ) << "/"
134
+  end
135
+
136
+  def source
137
+    if !defined? @source
138
+      if @resource[:source]
139
+        @source = URI.parse(@resource[:source])
140
+        if @source.path.empty?
141
+          @source.merge! uri_path
142
         end
143
+      else # source parameter not set; build default source URI
144
+        @source = URI::FTP.build({
145
+          :host => "ftp.freebsd.org",
146
+          :path => uri_path,
147
+        })
92
       end
148
       end
149
+      Puppet.debug "Package: #{@resource[:name]}: source => #{@source.inspect}"
150
+    end
151
+    @source
152
+  end
153
+
154
+  def origin
155
+    if !defined? @origin
156
+      @origin = self.class.parse_origin(@resource[:name])
157
+      Puppet.debug "Package: #{@resource[:name]}: origin => #{@origin.inspect}"
158
+    end
159
+    @origin
160
+  end
161
+
162
+  def package_uri
163
+    begin
164
+      pkg_name = self.class.unparse_pkg_info(ports_index.fetch(origin))
165
+    rescue IndexError
166
+      raise Puppet::Error.new "package not found in INDEX"
167
+    end
168
+    uri = source.merge File.join("All", pkg_name + ".tbz")
169
+    Puppet.debug "Package: #{@resource[:name]}: package_uri => #{uri.inspect}"
170
+    uri
171
+  end
172
+
173
+  def install
174
+    should = @resource.should(:ensure)
175
+    origin # call origin so we check the package name for correctness early
93
+
176
+
94
+    # source parameter is not set.
177
+    # Source URI is for local file path.
178
+    if !source.absolute? or source.scheme == "file"
179
+      pkgadd source.path
180
+    # Source URI is to specific package file
181
+    elsif source.absolute? && source.path.end_with?(".tbz")
182
+      pkgadd source.to_s
183
+    # Source URI is to a package repository
95
     else
184
     else
96
-      Puppet.warning "source is defined but does not have trailing slash, ignoring #{@resource[:source]}" if @resource[:source]
185
-      Puppet.warning "source is defined but does not have trailing slash, ignoring #{@resource[:source]}" if @resource[:source]
97
-      pkgadd "-r", @resource[:name]
186
-      pkgadd "-r", @resource[:name]
98
+      # fetch package using default PACKAGESITE directory logic.
187
+      pkgadd "-f", package_uri.to_s
99
+      # Pass pkg_add the origin name.
100
+      pkgadd "-rf", origin[:name]
101
     end
188
     end
189
+    nil
102
   end
190
   end
103
 
191
 
104
@@ -44,7 +87,7 @@ Puppet::Type.type(:package).provide :freebsd, :parent => :openbsd do
192
   def query
193
@@ -44,7 +172,7 @@ Puppet::Type.type(:package).provide :freebsd, :parent => :openbsd do
105
   end
194
   end
106
 
195
 
107
   def uninstall
196
   def uninstall
(-)b/puppet/files/patch-fix_password_provider (+42 lines)
Added Link Here
1
diff --git lib/puppet/provider/user/pw.rb lib/puppet/provider/user/pw.rb
2
index a5988ca..c2fff37 100644
3
--- lib/puppet/provider/user/pw.rb
4
+++ lib/puppet/provider/user/pw.rb
5
@@ -1,10 +1,11 @@
6
 require 'puppet/provider/nameservice/pw'
7
+require 'open3'
8
 
9
 Puppet::Type.type(:user).provide :pw, :parent => Puppet::Provider::NameService::PW do
10
   desc "User management via `pw` on FreeBSD."
11
 
12
   commands :pw => "pw"
13
-  has_features :manages_homedir, :allows_duplicates
14
+  has_features :manages_homedir, :allows_duplicates, :manages_passwords
15
 
16
   defaultfor :operatingsystem => :freebsd
17
 
18
@@ -37,5 +38,24 @@ Puppet::Type.type(:user).provide :pw, :parent => Puppet::Provider::NameService::
19
 
20
     cmd
21
   end
22
+
23
+  # use pw to update password hash
24
+  def password=(cryptopw)
25
+    Puppet.debug "change password for user '#{@resource[:name]}' method called with hash '#{cryptopw}'"
26
+    stdin, stdout, stderr = Open3.popen3("pw user mod #{@resource[:name]} -H 0")
27
+    stdin.puts(cryptopw)
28
+    stdin.close
29
+    Puppet.debug "finished password for user '#{@resource[:name]}' method called with hash '#{cryptopw}'"
30
+  end
31
+
32
+  # get password from /etc/master.passwd
33
+  def password
34
+    Puppet.debug "checking password for user '#{@resource[:name]}' method called"
35
+    current_passline = `getent passwd #{@resource[:name]}`
36
+    current_password = current_passline.chomp.split(':')[1] if current_passline
37
+    Puppet.debug "finished password for user '#{@resource[:name]}' method called : '#{current_password}'"
38
+    current_password
39
+  end
40
+
41
 end
42

Return to bug 156239