puppet 0.13.6 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (149) hide show
  1. data/CHANGELOG +57 -0
  2. data/Rakefile +38 -410
  3. data/bin/puppet +14 -12
  4. data/bin/puppetca +1 -3
  5. data/bin/puppetd +25 -7
  6. data/bin/puppetdoc +161 -104
  7. data/bin/puppetmasterd +4 -4
  8. data/conf/epm.list +8 -0
  9. data/conf/redhat/client.init +6 -1
  10. data/conf/redhat/no-chuser-0.15.1.patch +38 -0
  11. data/conf/redhat/puppet.spec +20 -5
  12. data/conf/redhat/puppetd.conf +1 -1
  13. data/conf/redhat/puppetmasterd.conf +1 -1
  14. data/conf/redhat/server.init +2 -4
  15. data/examples/code/snippets/{casestatement → casestatement.pp} +12 -1
  16. data/examples/code/snippets/selectorvalues.pp +15 -0
  17. data/examples/code/snippets/singleselector.pp +22 -0
  18. data/examples/code/snippets/tag.pp +9 -0
  19. data/ext/module_puppet +1 -1
  20. data/install.rb +303 -303
  21. data/lib/puppet.rb +7 -9
  22. data/lib/puppet/client.rb +18 -5
  23. data/lib/puppet/client/dipper.rb +12 -10
  24. data/lib/puppet/client/master.rb +113 -41
  25. data/lib/puppet/client/pelement.rb +20 -0
  26. data/lib/puppet/config.rb +113 -6
  27. data/lib/puppet/element.rb +1 -3
  28. data/lib/puppet/event.rb +12 -23
  29. data/lib/puppet/filetype.rb +93 -5
  30. data/lib/puppet/inifile.rb +201 -0
  31. data/lib/puppet/log.rb +18 -6
  32. data/lib/puppet/parameter.rb +80 -29
  33. data/lib/puppet/parser/ast.rb +6 -4
  34. data/lib/puppet/parser/ast/caseopt.rb +13 -4
  35. data/lib/puppet/parser/ast/casestatement.rb +2 -2
  36. data/lib/puppet/parser/ast/component.rb +4 -14
  37. data/lib/puppet/parser/ast/hostclass.rb +1 -1
  38. data/lib/puppet/parser/ast/leaf.rb +12 -0
  39. data/lib/puppet/parser/ast/node.rb +4 -4
  40. data/lib/puppet/parser/ast/objectdef.rb +5 -51
  41. data/lib/puppet/parser/ast/selector.rb +2 -0
  42. data/lib/puppet/parser/ast/tag.rb +26 -0
  43. data/lib/puppet/parser/interpreter.rb +89 -74
  44. data/lib/puppet/parser/lexer.rb +4 -3
  45. data/lib/puppet/parser/parser.rb +440 -378
  46. data/lib/puppet/parser/scope.rb +844 -887
  47. data/lib/puppet/server.rb +12 -1
  48. data/lib/puppet/server/authconfig.rb +166 -0
  49. data/lib/puppet/server/authstore.rb +8 -6
  50. data/lib/puppet/server/ca.rb +23 -26
  51. data/lib/puppet/server/filebucket.rb +24 -23
  52. data/lib/puppet/server/fileserver.rb +116 -47
  53. data/lib/puppet/server/master.rb +58 -19
  54. data/lib/puppet/server/pelement.rb +176 -0
  55. data/lib/puppet/server/rights.rb +78 -0
  56. data/lib/puppet/server/servlet.rb +19 -6
  57. data/lib/puppet/sslcertificates.rb +4 -2
  58. data/lib/puppet/sslcertificates/ca.rb +66 -34
  59. data/lib/puppet/storage.rb +20 -26
  60. data/lib/puppet/transaction.rb +49 -92
  61. data/lib/puppet/type.rb +142 -35
  62. data/lib/puppet/type/cron.rb +29 -14
  63. data/lib/puppet/type/exec.rb +92 -35
  64. data/lib/puppet/type/group.rb +29 -11
  65. data/lib/puppet/type/nameservice.rb +50 -1
  66. data/lib/puppet/type/nameservice/netinfo.rb +68 -1
  67. data/lib/puppet/type/nameservice/objectadd.rb +1 -0
  68. data/lib/puppet/type/package.rb +150 -109
  69. data/lib/puppet/type/package/apple.rb +27 -0
  70. data/lib/puppet/type/package/apt.rb +1 -0
  71. data/lib/puppet/type/package/darwinport.rb +97 -0
  72. data/lib/puppet/type/package/dpkg.rb +10 -2
  73. data/lib/puppet/type/package/freebsd.rb +19 -0
  74. data/lib/puppet/type/package/{bsd.rb → openbsd.rb} +36 -7
  75. data/lib/puppet/type/package/ports.rb +98 -0
  76. data/lib/puppet/type/package/rpm.rb +43 -7
  77. data/lib/puppet/type/package/sun.rb +53 -36
  78. data/lib/puppet/type/package/yum.rb +5 -16
  79. data/lib/puppet/type/parsedtype.rb +41 -29
  80. data/lib/puppet/type/parsedtype/host.rb +13 -5
  81. data/lib/puppet/type/parsedtype/mount.rb +250 -0
  82. data/lib/puppet/type/parsedtype/port.rb +8 -6
  83. data/lib/puppet/type/pfile.rb +284 -30
  84. data/lib/puppet/type/pfile/checksum.rb +96 -68
  85. data/lib/puppet/type/pfile/content.rb +16 -13
  86. data/lib/puppet/type/pfile/ensure.rb +64 -126
  87. data/lib/puppet/type/pfile/group.rb +12 -5
  88. data/lib/puppet/type/pfile/mode.rb +16 -4
  89. data/lib/puppet/type/pfile/source.rb +47 -73
  90. data/lib/puppet/type/pfile/target.rb +81 -0
  91. data/lib/puppet/type/pfile/uid.rb +10 -3
  92. data/lib/puppet/type/pfilebucket.rb +12 -3
  93. data/lib/puppet/type/schedule.rb +5 -1
  94. data/lib/puppet/type/service.rb +138 -66
  95. data/lib/puppet/type/service/debian.rb +9 -3
  96. data/lib/puppet/type/service/init.rb +51 -56
  97. data/lib/puppet/type/service/smf.rb +16 -6
  98. data/lib/puppet/type/state.rb +71 -32
  99. data/lib/puppet/type/symlink.rb +12 -7
  100. data/lib/puppet/type/tidy.rb +5 -1
  101. data/lib/puppet/type/user.rb +116 -20
  102. data/lib/puppet/type/yumrepo.rb +314 -0
  103. data/lib/puppet/util.rb +84 -14
  104. data/test/client/client.rb +41 -18
  105. data/test/client/master.rb +50 -4
  106. data/test/executables/puppetbin.rb +31 -4
  107. data/test/executables/puppetca.rb +18 -2
  108. data/test/language/ast.rb +201 -31
  109. data/test/language/interpreter.rb +8 -2
  110. data/test/{parser → language}/lexer.rb +1 -1
  111. data/test/language/node.rb +84 -0
  112. data/test/{parser → language}/parser.rb +1 -1
  113. data/test/language/scope.rb +101 -2
  114. data/test/language/snippets.rb +23 -2
  115. data/test/other/config.rb +99 -1
  116. data/test/other/filetype.rb +95 -0
  117. data/test/other/inifile.rb +114 -0
  118. data/test/other/log.rb +3 -2
  119. data/test/other/transactions.rb +55 -10
  120. data/test/puppet/utiltest.rb +25 -1
  121. data/test/puppettest.rb +140 -46
  122. data/test/server/authconfig.rb +56 -0
  123. data/test/server/bucket.rb +32 -18
  124. data/test/server/fileserver.rb +75 -30
  125. data/test/server/master.rb +27 -4
  126. data/test/server/pelement.rb +298 -0
  127. data/test/server/rights.rb +41 -0
  128. data/test/server/server.rb +2 -2
  129. data/test/tagging/tagging.rb +100 -1
  130. data/test/types/basic.rb +3 -3
  131. data/test/types/cron.rb +24 -1
  132. data/test/types/exec.rb +99 -1
  133. data/test/types/file.rb +298 -2
  134. data/test/types/filebucket.rb +4 -15
  135. data/test/types/filesources.rb +43 -14
  136. data/test/types/group.rb +1 -13
  137. data/test/types/mount.rb +277 -0
  138. data/test/types/package.rb +164 -33
  139. data/test/types/parameter.rb +107 -0
  140. data/test/types/port.rb +2 -1
  141. data/test/types/service.rb +37 -2
  142. data/test/types/state.rb +92 -0
  143. data/test/types/symlink.rb +30 -2
  144. data/test/types/tidy.rb +2 -14
  145. data/test/types/type.rb +35 -1
  146. data/test/types/user.rb +110 -1
  147. data/test/types/yumrepo.rb +95 -0
  148. metadata +316 -290
  149. data/test/types/filetype.rb +0 -160
@@ -184,9 +184,9 @@ if haveca
184
184
  handlers[:CA] = ca
185
185
  end
186
186
 
187
- #if havebucket
188
- # handlers[:FileBucket] = bucket
189
- #end
187
+ if havebucket
188
+ handlers[:FileBucket] = bucket
189
+ end
190
190
 
191
191
  if File.exists?(Puppet[:fileserverconfig])
192
192
  fs[:Config] = Puppet[:fileserverconfig]
@@ -245,4 +245,4 @@ rescue => detail
245
245
  exit(1)
246
246
  end
247
247
 
248
- # $Id: puppetmasterd 966 2006-03-02 17:12:26Z luke $
248
+ # $Id: puppetmasterd 1012 2006-03-12 02:56:23Z luke $
@@ -0,0 +1,8 @@
1
+ %product Puppet
2
+ %copyright 2004-2005 by Reductive Labs, All Rights Reserved
3
+ %vendor Reductive Labs
4
+ %license COPYING
5
+ %readme README
6
+ %description System Automation and Configuration Management Software
7
+ %version 0.15.0
8
+ %requires facter 1.1
@@ -15,7 +15,7 @@ export PATH
15
15
 
16
16
  [ -f /etc/sysconfig/puppet ] && . /etc/sysconfig/puppet
17
17
  lockfile=${LOCKFILE-/var/lock/subsys/puppet}
18
- pidfile=${PIDFILE-/var/run/puppet/puppet.pid}
18
+ pidfile=${PIDFILE-/var/run/puppet.pid}
19
19
  puppetd=${PUPPETD-/usr/sbin/puppetd}
20
20
  RETVAL=0
21
21
 
@@ -27,6 +27,11 @@ PUPPET_OPTS=""
27
27
  [ -n "$PUPPET_LOG" ] && PUPPET_OPTS="${PUPPET_OPTS} --logdest=${PUPPET_LOG}"
28
28
  [ -n "$PUPPET_PORT" ] && PUPPET_OPTS="${PUPPET_OPTS} --port=${PUPPET_PORT}"
29
29
 
30
+ # Figure out if the system just booted. Let's assume
31
+ # boot doesn't take longer than 5 minutes
32
+ ## Not used for now
33
+ ##[ -n "$INIT_VERSION" ] && PUPPET_OPTS="${PUPPET_OPTS} --fullrun"
34
+
30
35
  start() {
31
36
  echo -n $"Starting puppet: "
32
37
  daemon $puppetd ${PUPPET_OPTS} ${PUPPET_EXTRA_OPTS}
@@ -0,0 +1,38 @@
1
+ --- puppet-0.15.1/bin/puppetmasterd.orig 2006-03-15 08:33:45.000000000 -0800
2
+ +++ puppet-0.15.1/bin/puppetmasterd 2006-03-22 13:07:54.000000000 -0800
3
+ @@ -210,14 +210,15 @@
4
+ exit(1)
5
+ end
6
+
7
+ -if Process.uid == 0
8
+ - begin
9
+ - Puppet::Util.chuser
10
+ - rescue => detail
11
+ - $stderr.puts "Could not change user to %s: %s" % [Puppet[:user], detail]
12
+ - exit(39)
13
+ - end
14
+ -end
15
+ +# FIXME: Running as non-root is not ready for primetime
16
+ +# if Process.uid == 0
17
+ +# begin
18
+ +# Puppet::Util.chuser
19
+ +# rescue => detail
20
+ +# $stderr.puts "Could not change user to %s: %s" % [Puppet[:user], detail]
21
+ +# exit(39)
22
+ +# end
23
+ +# end
24
+
25
+ if Puppet[:parseonly]
26
+ # we would have already exited if the file weren't syntactically correct
27
+ --- puppet-0.15.1/bin/puppetca.orig 2006-02-07 15:12:39.000000000 -0800
28
+ +++ puppet-0.15.1/bin/puppetca 2006-03-22 13:07:56.000000000 -0800
29
+ @@ -138,7 +138,8 @@
30
+ Puppet.genconfig
31
+ Puppet.genmanifest
32
+
33
+ -Puppet::Util.chuser
34
+ +# FIXME: Running as non-root is not ready for primetime
35
+ +# Puppet::Util.chuser
36
+
37
+ begin
38
+ ca = Puppet::SSLCertificates::CA.new()
@@ -4,7 +4,7 @@
4
4
 
5
5
  Summary: A network tool for managing many disparate systems
6
6
  Name: puppet
7
- Version: 0.13.6
7
+ Version: 0.16.0
8
8
  Release: 1%{?dist}
9
9
  License: GPL
10
10
  Group: System Environment/Base
@@ -15,7 +15,10 @@ Source: http://reductivelabs.com/downloads/puppet/%{name}-%{version}.tgz
15
15
  Requires: ruby >= 1.8.1
16
16
  Requires: facter >= 1.1
17
17
  BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
18
- BuildArchitectures: noarch
18
+ # It's not possible to build ruby noarch packages currently
19
+ # See bz184199
20
+ #BuildArchitectures: noarch
21
+ BuildRequires: ruby >= 1.8.1
19
22
 
20
23
  %description
21
24
  Puppet lets you centrally manage every important aspect of your system using a
@@ -90,13 +93,10 @@ find %{buildroot}%{rubylibdir} -type f -perm +ugo+x -print0 | xargs -0 -r %{__ch
90
93
  -s /sbin/nologin -r -d /var/puppet puppet 2> /dev/null || :
91
94
 
92
95
  %post
93
- touch %{_localstatedir}/log/puppet.log
94
96
  /sbin/chkconfig --add puppet
95
97
  exit 0
96
98
 
97
99
  %post server
98
- touch %{_localstatedir}/log/puppetmaster.log
99
- touch %{_localstatedir}/log/puppetmaster-http.log
100
100
  /sbin/chkconfig --add puppetmaster
101
101
 
102
102
  %preun
@@ -120,6 +120,21 @@ fi
120
120
  %{__rm} -rf %{buildroot}
121
121
 
122
122
  %changelog
123
+ * Mon Apr 17 2006 David Lutterkort <dlutter@redhat.com> - 0.15.3-2
124
+ - Don't create empty log files in post-install scriptlet
125
+
126
+ * Fri Apr 7 2006 David Lutterkort <dlutter@redhat.com> - 0.15.3-1
127
+ - Rebuilt for new version
128
+
129
+ * Wed Mar 22 2006 David Lutterkort <dlutter@redhat.com> - 0.15.1-1
130
+ - Patch0: Run puppetmaster as root; running as puppet is not ready for primetime
131
+
132
+ * Mon Mar 13 2006 David Lutterkort <dlutter@redhat.com> - 0.15.0-1
133
+ - Commented out noarch; requires fix for bz184199
134
+
135
+ * Mon Mar 6 2006 David Lutterkort <dlutter@redhat.com> - 0.14.0-1
136
+ - Added BuildRequires for ruby
137
+
123
138
  * Wed Mar 1 2006 David Lutterkort <dlutter@redhat.com> - 0.13.5-1
124
139
  - Removed use of fedora-usermgmt. It is not required for Fedora Extras and
125
140
  makes it unnecessarily hard to use this rpm outside of Fedora. Just
@@ -2,4 +2,4 @@
2
2
  # Make sure all log messages are sent to the right directory
3
3
  # This directory must be writable by the puppet user
4
4
  logdir=/var/log/puppet
5
- rundir=/var/run/puppet
5
+ rundir=/var/run
@@ -2,4 +2,4 @@
2
2
  # Make sure all log messages are sent to the right directory
3
3
  # This directory must be writable by the puppet user
4
4
  logdir=/var/log/puppet
5
- rundir=/var/run/puppet
5
+ rundir=/var/run
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # Author: Duane Griffin <d.griffin@psenterprise.com>
5
5
  #
6
- # chkconfig: 345 65 45
6
+ # chkconfig: - 65 45
7
7
  #
8
8
  # description: Server for the puppet system management tool.
9
9
  # processname: puppetmaster
@@ -37,7 +37,7 @@ start() {
37
37
 
38
38
  # Confirm the manifest exists
39
39
  if [ -r $PUPPETMASTER_MANIFEST ]; then
40
- $PUPPETMASTER $PUPPETMASTER_OPTS
40
+ daemon $PUPPETMASTER $PUPPETMASTER_OPTS
41
41
  RETVAL=$?
42
42
  else
43
43
  failure $"Manifest does not exist: $PUPPETMASTER_MANIFEST"
@@ -45,8 +45,6 @@ start() {
45
45
  return 1
46
46
  fi
47
47
  [ $RETVAL -eq 0 ] && touch "$lockfile"
48
- [ $RETVAL -eq 0 ] && echo_success
49
- [ $RETVAL -ne 0 ] && echo_failure
50
48
  echo
51
49
  return $RETVAL
52
50
  }
@@ -1,4 +1,4 @@
1
- # $Id: casestatement 832 2006-01-17 07:11:50Z luke $
1
+ # $Id: casestatement.pp 976 2006-03-03 22:23:00Z luke $
2
2
 
3
3
  $var = "value"
4
4
 
@@ -45,3 +45,14 @@ case $bool {
45
45
  file { "/tmp/existsfile4": mode => 755, ensure => file }
46
46
  }
47
47
  }
48
+
49
+ $yay = yay
50
+ $a = yay
51
+ $b = boo
52
+
53
+ case $yay {
54
+ $a: { file { "/tmp/existsfile5": mode => 755, ensure => file } }
55
+ $b: { file { "/tmp/existsfile5": mode => 644, ensure => file } }
56
+ default: { file { "/tmp/existsfile5": mode => 711, ensure => file } }
57
+
58
+ }
@@ -1,6 +1,9 @@
1
1
  $value1 = ""
2
2
  $value2 = true
3
3
  $value3 = false
4
+ $value4 = yay
5
+
6
+ $test = "yay"
4
7
 
5
8
  $mode1 = $value1 ? {
6
9
  "" => 755,
@@ -17,6 +20,18 @@ $mode3 = $value3 ? {
17
20
  default => 644
18
21
  }
19
22
 
23
+ $mode4 = $value4 ? {
24
+ $test => 755,
25
+ default => 644
26
+ }
27
+
28
+ $mode5 = yay ? {
29
+ $test => 755,
30
+ default => 644
31
+ }
32
+
20
33
  file { "/tmp/selectorvalues1": ensure => file, mode => $mode1 }
21
34
  file { "/tmp/selectorvalues2": ensure => file, mode => $mode2 }
22
35
  file { "/tmp/selectorvalues3": ensure => file, mode => $mode3 }
36
+ file { "/tmp/selectorvalues4": ensure => file, mode => $mode4 }
37
+ file { "/tmp/selectorvalues5": ensure => file, mode => $mode4 }
@@ -0,0 +1,22 @@
1
+ $value1 = ""
2
+ $value2 = true
3
+ $value3 = false
4
+ $value4 = yay
5
+
6
+ $test = "yay"
7
+
8
+ $mode1 = $value1 ? {
9
+ "" => 755
10
+ }
11
+
12
+ $mode2 = $value2 ? {
13
+ true => 755
14
+ }
15
+
16
+ $mode3 = $value3 ? {
17
+ default => 755
18
+ }
19
+
20
+ file { "/tmp/singleselector1": ensure => file, mode => $mode1 }
21
+ file { "/tmp/singleselector2": ensure => file, mode => $mode2 }
22
+ file { "/tmp/singleselector3": ensure => file, mode => $mode3 }
@@ -0,0 +1,9 @@
1
+ # $Id: tag.pp 1113 2006-04-17 16:15:33Z luke $
2
+
3
+ $variable = value
4
+
5
+ tag yayness, rahness
6
+
7
+ tag booness, $variable
8
+
9
+ file { "/tmp/settestingness": ensure => file }
@@ -158,7 +158,7 @@ unless setdest
158
158
  Puppet::Log.newdestination(:syslog)
159
159
  end
160
160
 
161
- master[:File] = ARGV.shift
161
+ master[:Manifest] = ARGV.shift
162
162
 
163
163
  unless ENV.include?("CFALLCLASSES")
164
164
  $stderr.puts "Cfengine classes must be passed to the module"
data/install.rb CHANGED
@@ -1,303 +1,303 @@
1
- #! /usr/bin/env ruby
2
- #--
3
- # Copyright 2004 Austin Ziegler <ruby-install@halostatue.ca>
4
- # Install utility. Based on the original installation script for rdoc by the
5
- # Pragmatic Programmers.
6
- #
7
- # This program is free software. It may be redistributed and/or modified under
8
- # the terms of the GPL version 2 (or later) or the Ruby licence.
9
- #
10
- # Usage
11
- # -----
12
- # In most cases, if you have a typical project layout, you will need to do
13
- # absolutely nothing to make this work for you. This layout is:
14
- #
15
- # bin/ # executable files -- "commands"
16
- # lib/ # the source of the library
17
- # tests/ # unit tests
18
- #
19
- # The default behaviour:
20
- # 1) Run all unit test files (ending in .rb) found in all directories under
21
- # tests/.
22
- # 2) Build Rdoc documentation from all files in bin/ (excluding .bat and .cmd),
23
- # all .rb files in lib/, ./README, ./ChangeLog, and ./Install.
24
- # 3) Build ri documentation from all files in bin/ (excluding .bat and .cmd),
25
- # and all .rb files in lib/. This is disabled by default on Win32.
26
- # 4) Install commands from bin/ into the Ruby bin directory. On Windows, if a
27
- # if a corresponding batch file (.bat or .cmd) exists in the bin directory,
28
- # it will be copied over as well. Otherwise, a batch file (always .bat) will
29
- # be created to run the specified command.
30
- # 5) Install all library files ending in .rb from lib/ into Ruby's
31
- # site_lib/version directory.
32
- #
33
- # $Id: install.rb 779 2006-01-05 20:36:01Z luke $
34
- #++
35
-
36
- require 'rbconfig'
37
- require 'find'
38
- require 'fileutils'
39
- require 'ftools' # apparently on some system ftools doesn't get loaded
40
- require 'optparse'
41
- require 'ostruct'
42
-
43
- begin
44
- require 'rdoc/rdoc'
45
- $haverdoc = true
46
- rescue LoadError
47
- puts "Missing rdoc; skipping documentation"
48
- $haverdoc = false
49
- end
50
-
51
- PREREQS = %w{openssl facter xmlrpc/client xmlrpc/server cgi}
52
-
53
- InstallOptions = OpenStruct.new
54
-
55
- def glob(list)
56
- g = list.map { |i| Dir.glob(i) }
57
- g.flatten!
58
- g.compact!
59
- g.reject! { |e| e =~ /\.svn/ }
60
- g
61
- end
62
-
63
- # Set these values to what you want installed.
64
- bins = glob(%w{bin/**/*})
65
- rdoc = glob(%w{bin/**/* lib/**/*.rb README README-library CHANGELOG TODO Install}).reject { |e| e=~ /\.(bat|cmd)$/ }
66
- ri = glob(%w(bin/**/*.rb lib/**/*.rb)).reject { |e| e=~ /\.(bat|cmd)$/ }
67
- libs = glob(%w{lib/**/*.rb})
68
- tests = glob(%w{tests/**/*.rb})
69
-
70
- def do_bins(bins, target, strip = 'bin/')
71
- bins.each do |bf|
72
- obf = bf.gsub(/#{strip}/, '')
73
- install_binfile(bf, obf, target)
74
- end
75
- end
76
-
77
- def do_libs(libs, strip = 'lib/')
78
- libs.each do |lf|
79
- olf = File.join(InstallOptions.site_dir, lf.gsub(/#{strip}/, ''))
80
- op = File.dirname(olf)
81
- File.makedirs(op, true)
82
- File.chmod(0755, op)
83
- File.install(lf, olf, 0755, true)
84
- end
85
- end
86
-
87
- # Verify that all of the prereqs are installed
88
- def check_prereqs
89
- PREREQS.each { |pre|
90
- begin
91
- require pre
92
- rescue LoadError
93
- puts "Could not load %s; cannot install" % pre
94
- end
95
- }
96
- end
97
-
98
- ##
99
- # Prepare the file installation.
100
- #
101
- def prepare_installation
102
- # Only try to do docs if we're sure they have rdoc
103
- if $haverdoc
104
- InstallOptions.rdoc = true
105
- if RUBY_PLATFORM == "i386-mswin32"
106
- InstallOptions.ri = false
107
- else
108
- InstallOptions.ri = true
109
- end
110
- else
111
- InstallOptions.rdoc = false
112
- InstallOptions.ri = false
113
- end
114
- InstallOptions.tests = true
115
-
116
- ARGV.options do |opts|
117
- opts.banner = "Usage: #{File.basename($0)} [options]"
118
- opts.separator ""
119
- opts.on('--[no-]rdoc', 'Prevents the creation of RDoc output.', 'Default on.') do |onrdoc|
120
- InstallOptions.rdoc = onrdoc
121
- end
122
- opts.on('--[no-]ri', 'Prevents the creation of RI output.', 'Default off on mswin32.') do |onri|
123
- InstallOptions.ri = onri
124
- end
125
- opts.on('--[no-]tests', 'Prevents the execution of unit tests.', 'Default on.') do |ontest|
126
- InstallOptions.tests = ontest
127
- end
128
- opts.on('--quick', 'Performs a quick installation. Only the', 'installation is done.') do |quick|
129
- InstallOptions.rdoc = false
130
- InstallOptions.ri = false
131
- InstallOptions.tests = false
132
- end
133
- opts.on('--full', 'Performs a full installation. All', 'optional installation steps are run.') do |full|
134
- InstallOptions.rdoc = true
135
- InstallOptions.ri = true
136
- InstallOptions.tests = true
137
- end
138
- opts.separator("")
139
- opts.on_tail('--help', "Shows this help text.") do
140
- $stderr.puts opts
141
- exit
142
- end
143
-
144
- opts.parse!
145
- end
146
-
147
- bds = [".", ENV['TMP'], ENV['TEMP']]
148
-
149
- version = [Config::CONFIG["MAJOR"], Config::CONFIG["MINOR"]].join(".")
150
- ld = File.join(Config::CONFIG["libdir"], "ruby", version)
151
-
152
- sd = Config::CONFIG["sitelibdir"]
153
- if sd.nil?
154
- sd = $:.find { |x| x =~ /site_ruby/ }
155
- if sd.nil?
156
- sd = File.join(ld, "site_ruby")
157
- elsif sd !~ Regexp.quote(version)
158
- sd = File.join(sd, version)
159
- end
160
- end
161
-
162
- if (destdir = ENV['DESTDIR'])
163
- bd = "#{destdir}#{Config::CONFIG['bindir']}"
164
- sd = "#{destdir}#{sd}"
165
- bds << bd
166
-
167
- FileUtils.makedirs(bd)
168
- FileUtils.makedirs(sd)
169
- else
170
- bds << Config::CONFIG['bindir']
171
- end
172
-
173
- InstallOptions.bin_dirs = bds.compact
174
- InstallOptions.site_dir = sd
175
- InstallOptions.bin_dir = bd
176
- InstallOptions.lib_dir = ld
177
- end
178
-
179
- ##
180
- # Build the rdoc documentation. Also, try to build the RI documentation.
181
- #
182
- def build_rdoc(files)
183
- return unless $haverdoc
184
- begin
185
- r = RDoc::RDoc.new
186
- r.document(["--main", "README", "--title",
187
- "Puppet -- Site Configuration Management", "--line-numbers"] + files)
188
- rescue RDoc::RDocError => e
189
- $stderr.puts e.message
190
- rescue Exception => e
191
- $stderr.puts "Couldn't build RDoc documentation\n#{e.message}"
192
- end
193
- end
194
-
195
- def build_ri(files)
196
- return unless $haverdoc
197
- begin
198
- ri = RDoc::RDoc.new
199
- #ri.document(["--ri-site", "--merge"] + files)
200
- ri.document(["--ri-site"] + files)
201
- rescue RDoc::RDocError => e
202
- $stderr.puts e.message
203
- rescue Exception => e
204
- $stderr.puts "Couldn't build Ri documentation\n#{e.message}"
205
- $stderr.puts "Continuing with install..."
206
- end
207
- end
208
-
209
- def run_tests(test_list)
210
- begin
211
- require 'test/unit/ui/console/testrunner'
212
- $:.unshift "lib"
213
- test_list.each do |test|
214
- next if File.directory?(test)
215
- require test
216
- end
217
-
218
- tests = []
219
- ObjectSpace.each_object { |o| tests << o if o.kind_of?(Class) }
220
- tests.delete_if { |o| !o.ancestors.include?(Test::Unit::TestCase) }
221
- tests.delete_if { |o| o == Test::Unit::TestCase }
222
-
223
- tests.each { |test| Test::Unit::UI::Console::TestRunner.run(test) }
224
- $:.shift
225
- rescue LoadError
226
- puts "Missing testrunner library; skipping tests"
227
- end
228
- end
229
-
230
- ##
231
- # Install file(s) from ./bin to Config::CONFIG['bindir']. Patch it on the way
232
- # to insert a #! line; on a Unix install, the command is named as expected
233
- # (e.g., bin/rdoc becomes rdoc); the shebang line handles running it. Under
234
- # windows, we add an '.rb' extension and let file associations do their stuff.
235
- def install_binfile(from, op_file, target)
236
- tmp_dir = nil
237
- InstallOptions.bin_dirs.each do |t|
238
- if File.directory?(t) and File.writable?(t)
239
- tmp_dir = t
240
- break
241
- end
242
- end
243
-
244
- fail "Cannot find a temporary directory" unless tmp_dir
245
- tmp_file = File.join(tmp_dir, '_tmp')
246
- ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
247
-
248
- File.open(from) do |ip|
249
- File.open(tmp_file, "w") do |op|
250
- ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
251
- op.puts "#!#{ruby}"
252
- op.write ip.read
253
- end
254
- end
255
-
256
- if Config::CONFIG["target_os"] =~ /win/io
257
- installed_wrapper = false
258
-
259
- if File.exists?("#{from}.bat")
260
- FileUtils.install("#{from}.bat", File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
261
- installed_wrapper = true
262
- end
263
-
264
- if File.exists?("#{from}.cmd")
265
- FileUtils.install("#{from}.cmd", File.join(target, "#{op_file}.cmd"), :mode => 0755, :verbose => true)
266
- installed_wrapper = true
267
- end
268
-
269
- if not installed_wrapper
270
- tmp_file2 = File.join(tmp_dir, '_tmp_wrapper')
271
- cwn = File.join(Config::CONFIG['bindir'], op_file)
272
- cwv = CMD_WRAPPER.gsub('<ruby>', ruby.gsub(%r{/}) { "\\" }).gsub!('<command>', cwn.gsub(%r{/}) { "\\" } )
273
-
274
- File.open(tmp_file2, "wb") { |cw| cw.puts cwv }
275
- FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
276
-
277
- File.unlink(tmp_file2)
278
- installed_wrapper = true
279
- end
280
- end
281
- FileUtils.install(tmp_file, File.join(target, op_file), :mode => 0755, :verbose => true)
282
- File.unlink(tmp_file)
283
- end
284
-
285
- CMD_WRAPPER = <<-EOS
286
- @echo off
287
- if "%OS%"=="Windows_NT" goto WinNT
288
- <ruby> -x "<command>" %1 %2 %3 %4 %5 %6 %7 %8 %9
289
- goto done
290
- :WinNT
291
- <ruby> -x "<command>" %*
292
- goto done
293
- :done
294
- EOS
295
-
296
- check_prereqs
297
- prepare_installation
298
-
299
- run_tests(tests) if InstallOptions.tests
300
- #build_rdoc(rdoc) if InstallOptions.rdoc
301
- #build_ri(ri) if InstallOptions.ri
302
- do_bins(bins, Config::CONFIG['bindir'])
303
- do_libs(libs)
1
+ #! /usr/bin/env ruby
2
+ #--
3
+ # Copyright 2004 Austin Ziegler <ruby-install@halostatue.ca>
4
+ # Install utility. Based on the original installation script for rdoc by the
5
+ # Pragmatic Programmers.
6
+ #
7
+ # This program is free software. It may be redistributed and/or modified under
8
+ # the terms of the GPL version 2 (or later) or the Ruby licence.
9
+ #
10
+ # Usage
11
+ # -----
12
+ # In most cases, if you have a typical project layout, you will need to do
13
+ # absolutely nothing to make this work for you. This layout is:
14
+ #
15
+ # bin/ # executable files -- "commands"
16
+ # lib/ # the source of the library
17
+ # tests/ # unit tests
18
+ #
19
+ # The default behaviour:
20
+ # 1) Run all unit test files (ending in .rb) found in all directories under
21
+ # tests/.
22
+ # 2) Build Rdoc documentation from all files in bin/ (excluding .bat and .cmd),
23
+ # all .rb files in lib/, ./README, ./ChangeLog, and ./Install.
24
+ # 3) Build ri documentation from all files in bin/ (excluding .bat and .cmd),
25
+ # and all .rb files in lib/. This is disabled by default on Win32.
26
+ # 4) Install commands from bin/ into the Ruby bin directory. On Windows, if a
27
+ # if a corresponding batch file (.bat or .cmd) exists in the bin directory,
28
+ # it will be copied over as well. Otherwise, a batch file (always .bat) will
29
+ # be created to run the specified command.
30
+ # 5) Install all library files ending in .rb from lib/ into Ruby's
31
+ # site_lib/version directory.
32
+ #
33
+ # $Id: install.rb 1030 2006-03-14 04:29:26Z luke $
34
+ #++
35
+
36
+ require 'rbconfig'
37
+ require 'find'
38
+ require 'fileutils'
39
+ require 'ftools' # apparently on some system ftools doesn't get loaded
40
+ require 'optparse'
41
+ require 'ostruct'
42
+
43
+ begin
44
+ require 'rdoc/rdoc'
45
+ $haverdoc = true
46
+ rescue LoadError
47
+ puts "Missing rdoc; skipping documentation"
48
+ $haverdoc = false
49
+ end
50
+
51
+ PREREQS = %w{openssl facter xmlrpc/client xmlrpc/server cgi}
52
+
53
+ InstallOptions = OpenStruct.new
54
+
55
+ def glob(list)
56
+ g = list.map { |i| Dir.glob(i) }
57
+ g.flatten!
58
+ g.compact!
59
+ g.reject! { |e| e =~ /\.svn/ }
60
+ g
61
+ end
62
+
63
+ # Set these values to what you want installed.
64
+ bins = glob(%w{bin/**/*})
65
+ rdoc = glob(%w{bin/**/* lib/**/*.rb README README-library CHANGELOG TODO Install}).reject { |e| e=~ /\.(bat|cmd)$/ }
66
+ ri = glob(%w(bin/**/*.rb lib/**/*.rb)).reject { |e| e=~ /\.(bat|cmd)$/ }
67
+ libs = glob(%w{lib/**/*.rb})
68
+ tests = glob(%w{tests/**/*.rb})
69
+
70
+ def do_bins(bins, target, strip = 'bin/')
71
+ bins.each do |bf|
72
+ obf = bf.gsub(/#{strip}/, '')
73
+ install_binfile(bf, obf, target)
74
+ end
75
+ end
76
+
77
+ def do_libs(libs, strip = 'lib/')
78
+ libs.each do |lf|
79
+ olf = File.join(InstallOptions.site_dir, lf.gsub(/#{strip}/, ''))
80
+ op = File.dirname(olf)
81
+ File.makedirs(op, true)
82
+ File.chmod(0755, op)
83
+ File.install(lf, olf, 0755, true)
84
+ end
85
+ end
86
+
87
+ # Verify that all of the prereqs are installed
88
+ def check_prereqs
89
+ PREREQS.each { |pre|
90
+ begin
91
+ require pre
92
+ rescue LoadError
93
+ puts "Could not load %s; cannot install" % pre
94
+ end
95
+ }
96
+ end
97
+
98
+ ##
99
+ # Prepare the file installation.
100
+ #
101
+ def prepare_installation
102
+ # Only try to do docs if we're sure they have rdoc
103
+ if $haverdoc
104
+ InstallOptions.rdoc = true
105
+ if RUBY_PLATFORM == "i386-mswin32"
106
+ InstallOptions.ri = false
107
+ else
108
+ InstallOptions.ri = true
109
+ end
110
+ else
111
+ InstallOptions.rdoc = false
112
+ InstallOptions.ri = false
113
+ end
114
+ InstallOptions.tests = true
115
+
116
+ ARGV.options do |opts|
117
+ opts.banner = "Usage: #{File.basename($0)} [options]"
118
+ opts.separator ""
119
+ opts.on('--[no-]rdoc', 'Prevents the creation of RDoc output.', 'Default on.') do |onrdoc|
120
+ InstallOptions.rdoc = onrdoc
121
+ end
122
+ opts.on('--[no-]ri', 'Prevents the creation of RI output.', 'Default off on mswin32.') do |onri|
123
+ InstallOptions.ri = onri
124
+ end
125
+ opts.on('--[no-]tests', 'Prevents the execution of unit tests.', 'Default on.') do |ontest|
126
+ InstallOptions.tests = ontest
127
+ end
128
+ opts.on('--quick', 'Performs a quick installation. Only the', 'installation is done.') do |quick|
129
+ InstallOptions.rdoc = false
130
+ InstallOptions.ri = false
131
+ InstallOptions.tests = false
132
+ end
133
+ opts.on('--full', 'Performs a full installation. All', 'optional installation steps are run.') do |full|
134
+ InstallOptions.rdoc = true
135
+ InstallOptions.ri = true
136
+ InstallOptions.tests = true
137
+ end
138
+ opts.separator("")
139
+ opts.on_tail('--help', "Shows this help text.") do
140
+ $stderr.puts opts
141
+ exit
142
+ end
143
+
144
+ opts.parse!
145
+ end
146
+
147
+ bds = [".", ENV['TMP'], ENV['TEMP']]
148
+
149
+ version = [Config::CONFIG["MAJOR"], Config::CONFIG["MINOR"]].join(".")
150
+ ld = File.join(Config::CONFIG["libdir"], "ruby", version)
151
+
152
+ sd = Config::CONFIG["sitelibdir"]
153
+ if sd.nil?
154
+ sd = $:.find { |x| x =~ /site_ruby/ }
155
+ if sd.nil?
156
+ sd = File.join(ld, "site_ruby")
157
+ elsif sd !~ Regexp.quote(version)
158
+ sd = File.join(sd, version)
159
+ end
160
+ end
161
+
162
+ if (destdir = ENV['DESTDIR'])
163
+ bd = "#{destdir}#{Config::CONFIG['bindir']}"
164
+ sd = "#{destdir}#{sd}"
165
+ bds << bd
166
+
167
+ FileUtils.makedirs(bd)
168
+ FileUtils.makedirs(sd)
169
+ else
170
+ bds << Config::CONFIG['bindir']
171
+ end
172
+
173
+ InstallOptions.bin_dirs = bds.compact
174
+ InstallOptions.site_dir = sd
175
+ InstallOptions.bin_dir = bd
176
+ InstallOptions.lib_dir = ld
177
+ end
178
+
179
+ ##
180
+ # Build the rdoc documentation. Also, try to build the RI documentation.
181
+ #
182
+ def build_rdoc(files)
183
+ return unless $haverdoc
184
+ begin
185
+ r = RDoc::RDoc.new
186
+ r.document(["--main", "README", "--title",
187
+ "Puppet -- Site Configuration Management", "--line-numbers"] + files)
188
+ rescue RDoc::RDocError => e
189
+ $stderr.puts e.message
190
+ rescue Exception => e
191
+ $stderr.puts "Couldn't build RDoc documentation\n#{e.message}"
192
+ end
193
+ end
194
+
195
+ def build_ri(files)
196
+ return unless $haverdoc
197
+ begin
198
+ ri = RDoc::RDoc.new
199
+ #ri.document(["--ri-site", "--merge"] + files)
200
+ ri.document(["--ri-site"] + files)
201
+ rescue RDoc::RDocError => e
202
+ $stderr.puts e.message
203
+ rescue Exception => e
204
+ $stderr.puts "Couldn't build Ri documentation\n#{e.message}"
205
+ $stderr.puts "Continuing with install..."
206
+ end
207
+ end
208
+
209
+ def run_tests(test_list)
210
+ begin
211
+ require 'test/unit/ui/console/testrunner'
212
+ $:.unshift "lib"
213
+ test_list.each do |test|
214
+ next if File.directory?(test)
215
+ require test
216
+ end
217
+
218
+ tests = []
219
+ ObjectSpace.each_object { |o| tests << o if o.kind_of?(Class) }
220
+ tests.delete_if { |o| !o.ancestors.include?(Test::Unit::TestCase) }
221
+ tests.delete_if { |o| o == Test::Unit::TestCase }
222
+
223
+ tests.each { |test| Test::Unit::UI::Console::TestRunner.run(test) }
224
+ $:.shift
225
+ rescue LoadError
226
+ puts "Missing testrunner library; skipping tests"
227
+ end
228
+ end
229
+
230
+ ##
231
+ # Install file(s) from ./bin to Config::CONFIG['bindir']. Patch it on the way
232
+ # to insert a #! line; on a Unix install, the command is named as expected
233
+ # (e.g., bin/rdoc becomes rdoc); the shebang line handles running it. Under
234
+ # windows, we add an '.rb' extension and let file associations do their stuff.
235
+ def install_binfile(from, op_file, target)
236
+ tmp_dir = nil
237
+ InstallOptions.bin_dirs.each do |t|
238
+ if File.directory?(t) and File.writable?(t)
239
+ tmp_dir = t
240
+ break
241
+ end
242
+ end
243
+
244
+ fail "Cannot find a temporary directory" unless tmp_dir
245
+ tmp_file = File.join(tmp_dir, '_tmp')
246
+ ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
247
+
248
+ File.open(from) do |ip|
249
+ File.open(tmp_file, "w") do |op|
250
+ ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
251
+ op.puts "#!#{ruby}"
252
+ op.write ip.read
253
+ end
254
+ end
255
+
256
+ if Config::CONFIG["target_os"] =~ /win/io
257
+ installed_wrapper = false
258
+
259
+ if File.exists?("#{from}.bat")
260
+ FileUtils.install("#{from}.bat", File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
261
+ installed_wrapper = true
262
+ end
263
+
264
+ if File.exists?("#{from}.cmd")
265
+ FileUtils.install("#{from}.cmd", File.join(target, "#{op_file}.cmd"), :mode => 0755, :verbose => true)
266
+ installed_wrapper = true
267
+ end
268
+
269
+ if not installed_wrapper
270
+ tmp_file2 = File.join(tmp_dir, '_tmp_wrapper')
271
+ cwn = File.join(Config::CONFIG['bindir'], op_file)
272
+ cwv = CMD_WRAPPER.gsub('<ruby>', ruby.gsub(%r{/}) { "\\" }).gsub!('<command>', cwn.gsub(%r{/}) { "\\" } )
273
+
274
+ File.open(tmp_file2, "wb") { |cw| cw.puts cwv }
275
+ FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
276
+
277
+ File.unlink(tmp_file2)
278
+ installed_wrapper = true
279
+ end
280
+ end
281
+ FileUtils.install(tmp_file, File.join(target, op_file), :mode => 0755, :verbose => true)
282
+ File.unlink(tmp_file)
283
+ end
284
+
285
+ CMD_WRAPPER = <<-EOS
286
+ @echo off
287
+ if "%OS%"=="Windows_NT" goto WinNT
288
+ <ruby> -x "<command>" %1 %2 %3 %4 %5 %6 %7 %8 %9
289
+ goto done
290
+ :WinNT
291
+ <ruby> -x "<command>" %*
292
+ goto done
293
+ :done
294
+ EOS
295
+
296
+ check_prereqs
297
+ prepare_installation
298
+
299
+ run_tests(tests) if InstallOptions.tests
300
+ #build_rdoc(rdoc) if InstallOptions.rdoc
301
+ #build_ri(ri) if InstallOptions.ri
302
+ do_bins(bins, Config::CONFIG['bindir'])
303
+ do_libs(libs)