tpkg 2.3.3 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +20 -0
  5. data/Portfile +39 -0
  6. data/Portfile.template +39 -0
  7. data/README.md +43 -0
  8. data/Rakefile +468 -18
  9. data/bin/gem2tpkg +2 -2
  10. data/bin/tpkg +18 -13
  11. data/bin/tpkg_uploader +132 -0
  12. data/ca.pem +1 -0
  13. data/control +7 -0
  14. data/depend +3 -0
  15. data/externals-etch/authorized_keys +40 -0
  16. data/externals-etch/group +9 -0
  17. data/externals-etch/iptables +38 -0
  18. data/externals-etch/limits +30 -0
  19. data/externals-etch/nfs +30 -0
  20. data/externals-etch/sudo +30 -0
  21. data/externals-etch/supplemental_groups +8 -0
  22. data/externals-etch/sysctl +30 -0
  23. data/externals-etch/user +41 -0
  24. data/externals/group +39 -0
  25. data/externals/supplemental_groups +48 -0
  26. data/externals/user +39 -0
  27. data/lib/tpkg.rb +260 -991
  28. data/lib/tpkg/os.rb +164 -0
  29. data/lib/tpkg/os/debian.rb +159 -0
  30. data/lib/tpkg/os/freebsd.rb +113 -0
  31. data/lib/tpkg/os/macosx.rb +113 -0
  32. data/lib/tpkg/os/redhat.rb +173 -0
  33. data/lib/tpkg/os/solaris.rb +101 -0
  34. data/lib/tpkg/os/windows.rb +26 -0
  35. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify.rb +67 -0
  36. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/errors.rb +127 -0
  37. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/kwalify.schema.yaml +58 -0
  38. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/main.rb +442 -0
  39. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/messages.rb +173 -0
  40. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/meta-validator.rb +275 -0
  41. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/base.rb +127 -0
  42. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/yaml.rb +841 -0
  43. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/rule.rb +559 -0
  44. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-java.eruby +222 -0
  45. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-php.eruby +104 -0
  46. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-ruby.eruby +113 -0
  47. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/types.rb +156 -0
  48. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util.rb +158 -0
  49. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/assert-text-equal.rb +46 -0
  50. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hash-interface.rb +18 -0
  51. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hashlike.rb +51 -0
  52. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/option-parser.rb +220 -0
  53. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb +57 -0
  54. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/testcase-helper.rb +112 -0
  55. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/validator.rb +282 -0
  56. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/yaml-parser.rb +870 -0
  57. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh.rb +219 -0
  58. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/agent.rb +179 -0
  59. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/constants.rb +18 -0
  60. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/key_manager.rb +219 -0
  61. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb +60 -0
  62. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
  63. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
  64. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/password.rb +39 -0
  65. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/publickey.rb +92 -0
  66. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/pageant.rb +183 -0
  67. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/session.rb +134 -0
  68. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffer.rb +340 -0
  69. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffered_io.rb +198 -0
  70. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/config.rb +205 -0
  71. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/channel.rb +630 -0
  72. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/constants.rb +33 -0
  73. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/session.rb +597 -0
  74. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/term.rb +178 -0
  75. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/errors.rb +85 -0
  76. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/key_factory.rb +102 -0
  77. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/known_hosts.rb +129 -0
  78. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/loggable.rb +61 -0
  79. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/packet.rb +102 -0
  80. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/prompt.rb +93 -0
  81. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/command.rb +75 -0
  82. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/errors.rb +14 -0
  83. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/http.rb +94 -0
  84. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks4.rb +70 -0
  85. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks5.rb +142 -0
  86. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/ruby_compat.rb +43 -0
  87. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/service/forward.rb +288 -0
  88. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test.rb +89 -0
  89. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/channel.rb +129 -0
  90. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/extensions.rb +152 -0
  91. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/kex.rb +44 -0
  92. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb +51 -0
  93. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/packet.rb +81 -0
  94. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/remote_packet.rb +38 -0
  95. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/script.rb +157 -0
  96. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/socket.rb +64 -0
  97. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/algorithms.rb +384 -0
  98. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/cipher_factory.rb +97 -0
  99. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/constants.rb +30 -0
  100. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac.rb +31 -0
  101. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/abstract.rb +79 -0
  102. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5.rb +12 -0
  103. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
  104. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/none.rb +15 -0
  105. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1.rb +13 -0
  106. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
  107. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/identity_cipher.rb +55 -0
  108. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex.rb +13 -0
  109. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
  110. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
  111. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb +127 -0
  112. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/packet_stream.rb +235 -0
  113. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/server_version.rb +71 -0
  114. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/session.rb +276 -0
  115. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/state.rb +206 -0
  116. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/lenient.rb +30 -0
  117. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/null.rb +12 -0
  118. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/strict.rb +53 -0
  119. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/version.rb +62 -0
  120. data/lib/tpkg/version.rb +3 -0
  121. data/man/man1/cpan2tpkg.1 +82 -0
  122. data/man/man1/gem2tpkg.1 +120 -0
  123. data/man/man1/tpkg.1 +411 -0
  124. data/pkginfo +8 -0
  125. data/postinstall.solaris +11 -0
  126. data/postremove.solaris +16 -0
  127. data/schema/schema-1.0.5.yml +0 -0
  128. data/schema/schema-1.0.6.yml +0 -0
  129. data/schema/schema-1.0.7.yml +0 -0
  130. data/schema/schema-1.0.8.yml +0 -0
  131. data/schema/schema-1.0.9.yml +0 -0
  132. data/schema/schema.yml +0 -0
  133. data/schema/tpkg-1.0.0.dtd +0 -0
  134. data/schema/tpkg-1.0.1.dtd +0 -0
  135. data/schema/tpkg-1.0.2.dtd +0 -0
  136. data/schema/tpkg-1.0.3.dtd +0 -0
  137. data/schema/tpkg-1.0.4.dtd +0 -0
  138. data/schema/tpkg-1.0.5.dtd +0 -0
  139. data/schema/tpkg-1.0.6.dtd +0 -0
  140. data/schema/tpkg-1.0.7.dtd +0 -0
  141. data/schema/tpkg-1.0.8.dtd +0 -0
  142. data/schema/tpkg-1.0.9.dtd +0 -0
  143. data/schema/tpkg.dtd +0 -0
  144. data/test/TODO +30 -0
  145. data/test/premadetestpkg/pkg_without_file_metadata-1.0-1.tpkg +0 -0
  146. data/test/test_checksum.rb +53 -0
  147. data/test/test_compress.rb +55 -0
  148. data/test/test_conflict.rb +41 -0
  149. data/test/test_crontabs.rb +398 -0
  150. data/test/test_dependency.rb +1113 -0
  151. data/test/test_downgrade.rb +80 -0
  152. data/test/test_download.rb +95 -0
  153. data/test/test_encrypt.rb +136 -0
  154. data/test/test_filemetadata.rb +131 -0
  155. data/test/test_initscript.rb +93 -0
  156. data/test/test_install.rb +186 -0
  157. data/test/test_lock.rb +82 -0
  158. data/test/test_make.rb +410 -0
  159. data/test/test_metadata.rb +805 -0
  160. data/test/test_misc.rb +379 -0
  161. data/test/test_options.rb +1711 -0
  162. data/test/test_os.rb +193 -0
  163. data/test/test_os_debian.rb +99 -0
  164. data/test/test_os_freebsd.rb +89 -0
  165. data/test/test_os_macosx.rb +79 -0
  166. data/test/test_os_redhat.rb +124 -0
  167. data/test/test_os_solaris.rb +85 -0
  168. data/test/test_os_windows.rb +26 -0
  169. data/test/test_query.rb +134 -0
  170. data/test/test_remove.rb +539 -0
  171. data/test/test_tar.rb +99 -0
  172. data/test/test_unpack.rb +977 -0
  173. data/test/test_upgrade.rb +398 -0
  174. data/test/test_version.rb +54 -0
  175. data/test/testcmds/crontab +14 -0
  176. data/test/testcmds/debian/apt-cache +145 -0
  177. data/test/testcmds/debian/dpkg-query +16 -0
  178. data/test/testcmds/freebsd/pkg_info +13 -0
  179. data/test/testcmds/macosx/port +35 -0
  180. data/test/testcmds/redhat/rpmbuild +6 -0
  181. data/test/testcmds/redhat/yum +90 -0
  182. data/test/testcmds/solaris/pkginfo +25 -0
  183. data/test/testcmds/solaris/pkgutil +36 -0
  184. data/test/testpkg/reloc/encfile +2 -0
  185. data/test/testpkg/reloc/file +2 -0
  186. data/test/testpkg/reloc/precryptfile +1 -0
  187. data/test/testpkg/reloc/precryptfile.plaintext +3 -0
  188. data/test/testpkg/tpkg-bad-ownergroup.xml +25 -0
  189. data/test/testpkg/tpkg-bad-ownergroup.yml +18 -0
  190. data/test/testpkg/tpkg-default-perms.xml +28 -0
  191. data/test/testpkg/tpkg-default-perms.yml +20 -0
  192. data/test/testpkg/tpkg-good-ownergroup.xml +25 -0
  193. data/test/testpkg/tpkg-good-ownergroup.yml +18 -0
  194. data/test/testpkg/tpkg-nativedeps.yml +13 -0
  195. data/test/testpkg/tpkg-nofiles.xml +14 -0
  196. data/test/testpkg/tpkg-nofiles.yml +9 -0
  197. data/test/testpkg/tpkg.xml +35 -0
  198. data/test/testpkg/tpkg.yml +25 -0
  199. data/test/tpkgtest.rb +300 -0
  200. data/tpkg.conf +16 -0
  201. data/tpkg.gemspec +24 -0
  202. data/tpkg.spec +28 -0
  203. data/tpkg.xml +17 -0
  204. data/tpkg_profile.sh +32 -0
  205. metadata +306 -31
@@ -0,0 +1,164 @@
1
+ # tpkg package management system
2
+ # License: MIT (http://www.opensource.org/licenses/mit-license.php)
3
+
4
+ begin
5
+ # Try loading facter w/o gems first so that we don't introduce a
6
+ # dependency on rubygems if it is not needed.
7
+ require 'facter'
8
+ rescue LoadError
9
+ require 'rubygems'
10
+ require 'facter'
11
+ end
12
+
13
+ class Tpkg::OS
14
+ @@implementations = []
15
+ def self.register_implementation(impl)
16
+ @@implementations << impl
17
+ end
18
+ Dir.glob(File.expand_path('os/*.rb', File.dirname(__FILE__))).each {|d| require d}
19
+ def self.create(options={})
20
+ impl = @@implementations.detect{|i| i.supported?} || raise(NotImplementedError)
21
+ impl.new(options)
22
+ end
23
+
24
+ def initialize(options={})
25
+ @debug = options[:debug]
26
+ @os = nil
27
+ @os_name = nil
28
+ @os_version = nil
29
+ @arch = nil
30
+ Facter.loadfacts
31
+ end
32
+
33
+ #
34
+ # OS-specific classes should (must?) implement these methods
35
+ #
36
+
37
+ # Given info for a init script from a package's metadata return an array
38
+ # of paths where that init script should linked to on the system
39
+ def init_links(installed_path, tpkgfile)
40
+ # I think users would rather have packages install without their init
41
+ # scripts enabled than have them fail to install on platforms where we
42
+ # don't have init script support.
43
+ # raise NotImplementedError
44
+ warn "No init script support for OS #{os}"
45
+ []
46
+ end
47
+ def available_native_packages(pkgname)
48
+ raise NotImplementedError
49
+ end
50
+ def install_native_package(pkg)
51
+ raise NotImplementedError
52
+ end
53
+ def upgrade_native_package(pkg)
54
+ raise NotImplementedError
55
+ end
56
+ # Create and install a native stub package, if pkg has native
57
+ # dependencies, to express those dependencies to the native package
58
+ # system. This helps ensure that users don't inadvertently remove native
59
+ # packages that tpkg packages depend on.
60
+ def stub_native_pkg(pkg)
61
+ # I think users would rather have packages install without a native stub
62
+ # than have them fail to install on platforms where we don't have native
63
+ # stub support.
64
+ # raise NotImplementedError
65
+ native_deps = pkg[:metadata].get_native_deps
66
+ if !native_deps.empty?
67
+ warn "No native stub support for OS #{os}"
68
+ end
69
+ end
70
+ # Remove the native dependency stub package (if there is one) associated
71
+ # with pkg
72
+ def remove_native_stub_pkg(pkg)
73
+ # raise NotImplementedError
74
+ warn "No native stub support for OS #{os}"
75
+ end
76
+ # This rarely works as-is, most platforms need something more specific
77
+ def os_version
78
+ if !@os_version
79
+ if Facter['operatingsystemrelease'] &&
80
+ Facter['operatingsystemrelease'].value &&
81
+ !Facter['operatingsystemrelease'].value.empty?
82
+ @os_version = Facter['operatingsystemrelease'].value
83
+ else
84
+ raise "Unable to determine proper OS value on this platform"
85
+ end
86
+ end
87
+ @os_version.dup
88
+ end
89
+ # This also rarely works as-is
90
+ def native_pkg_to_install_string(pkg)
91
+ name = pkg[:metadata][:name]
92
+ version = pkg[:metadata][:version]
93
+ package_version = pkg[:metadata][:package_version]
94
+ pkgname = "#{name}-#{version}"
95
+ if package_version
96
+ pkgname << "-#{package_version}"
97
+ end
98
+ pkgname
99
+ end
100
+
101
+ #
102
+ # These methods have implementations that work in most cases, but
103
+ # OS-specific classes may modify these definitions if needed.
104
+ #
105
+
106
+ def os
107
+ if !@os
108
+ @os = "#{os_name}-#{os_version}"
109
+ end
110
+ @os.dup
111
+ end
112
+ def os_name
113
+ if !@os_name
114
+ @os_name = Facter['operatingsystem'].value
115
+ end
116
+ @os_name.dup
117
+ end
118
+ def arch
119
+ if !@arch
120
+ @arch = Facter['hardwaremodel'].value
121
+ end
122
+ @arch.dup
123
+ end
124
+ def fqdn
125
+ # Note that we intentionally do not cache the fqdn. The hostname of a
126
+ # machine can change at any time and it would be unexpected if the user
127
+ # had to restart a tpkg-based application to pick up a hostname change.
128
+ if Facter['fqdn'] && Facter['fqdn'].value
129
+ Facter['fqdn'].value
130
+ else
131
+ Facter['hostname'].value << '.' << Facter['domain'].value
132
+ end
133
+ end
134
+ # Systems with cron.d support should override this
135
+ def cron_dot_d_directory
136
+ end
137
+ # Should sudo be on by default?
138
+ def sudo_default?
139
+ true
140
+ end
141
+
142
+ #
143
+ # Utility methods
144
+ #
145
+
146
+ def sys_v_init_links(installed_path, tpkgfile, default_levels, init_directory)
147
+ start = '99'
148
+ if tpkgfile[:init][:start]
149
+ start = tpkgfile[:init][:start]
150
+ end
151
+ levels = default_levels
152
+ if tpkgfile[:init][:levels]
153
+ levels = tpkgfile[:init][:levels]
154
+ # In case the user specified levels in yaml as string/integer
155
+ # instead of array
156
+ if !levels.kind_of?(Array)
157
+ levels = levels.to_s.split(//)
158
+ end
159
+ end
160
+ levels.collect do |level|
161
+ File.join(init_directory, "rc#{level}.d", 'S' + start.to_s + File.basename(installed_path))
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,159 @@
1
+ # tpkg package management system
2
+ # License: MIT (http://www.opensource.org/licenses/mit-license.php)
3
+
4
+ class Tpkg::OS::Debian < Tpkg::OS
5
+ def self.supported?
6
+ Facter.loadfacts
7
+ ['Debian', 'Ubuntu'].include?(Facter['operatingsystem'].value)
8
+ end
9
+ register_implementation(self)
10
+
11
+ def initialize(options={})
12
+ @dpkgquerycmd = options[:dpkgquerycmd] || options[:testcmd] || 'dpkg-query'
13
+ @aptcachecmd = options[:aptcachecmd] || options[:testcmd] || 'apt-cache'
14
+ @aptgetcmd = options[:aptgetcmd] || options[:testcmd] || 'apt-get'
15
+ super
16
+ end
17
+
18
+ def init_links(installed_path, tpkgfile)
19
+ sys_v_init_links(installed_path, tpkgfile, ['2', '3', '4', '5'], '/etc')
20
+ end
21
+ def cron_dot_d_directory
22
+ '/etc/cron.d'
23
+ end
24
+ def available_native_packages(pkgname)
25
+ native_packages = []
26
+ # The default 'dpkg -l' format has an optional third column for errors
27
+ # which makes it hard to parse reliably, so we specify a custom format.
28
+ cmd = "#{@dpkgquerycmd} -W -f='${Package} ${Version} ${Status}\n' #{pkgname}"
29
+ puts "available_native_packages running #{cmd}" if @debug
30
+ stderr_first_line = nil
31
+ Open3.popen3(cmd) do |stdin, stdout, stderr|
32
+ stdin.close
33
+ stdout.each_line do |line|
34
+ name, debversion, status = line.split(' ', 3)
35
+ # Seems to be Debian convention that if the package has a
36
+ # package version you seperate that from the upstream version
37
+ # with a hyphen.
38
+ version = nil
39
+ package_version = nil
40
+ if debversion =~ /-/
41
+ version, package_version = debversion.split('-', 2)
42
+ else
43
+ version = debversion
44
+ end
45
+ # We want packages with a state of "installed". However,
46
+ # there's also a state of "not-installed", and the state
47
+ # field contains several space-seperated values, so we have
48
+ # to be somewhat careful to pick out "installed".
49
+ if status.split(' ').include?('installed')
50
+ pkg = Tpkg.pkg_for_native_package(name, version, package_version, :native_installed)
51
+ native_packages << pkg
52
+ end
53
+ end
54
+ stderr_first_line = stderr.gets
55
+ end
56
+ # FIXME: popen3 doesn't set $?
57
+ if !$?.success?
58
+ # Ignore 'no matching packages', raise anything else
59
+ if stderr_first_line !~ 'No packages found matching'
60
+ raise "available_native_packages error running dpkg-query"
61
+ end
62
+ end
63
+
64
+ cmd = "#{@aptcachecmd} show #{pkgname}"
65
+ puts "available_native_packages running '#{cmd}'" if @debug
66
+ stderr_first_line = nil
67
+ Open3.popen3(cmd) do |stdin, stdout, stderr|
68
+ stdin.close
69
+ name = nil
70
+ version = nil
71
+ package_version = nil
72
+ skip = false
73
+ stdout.each_line do |line|
74
+ if line =~ /^Package: (.*)/
75
+ name = $1
76
+ version = nil
77
+ package_version = nil
78
+ skip = false
79
+ elsif line =~ /Status: (.*)/
80
+ # Packages with status are coming from dpkg rather than apt. They're
81
+ # either already installed (and thus captured by the dpkg-query
82
+ # above) or uninstalled and not really available. This seems to be
83
+ # a new feature of apt-get in Debian 7. On older systems these
84
+ # packages don't show up in apt-get show, which is why we still need
85
+ # the dpkg-query command above.
86
+ skip = true
87
+ elsif line =~ /^Version: (.*)/ && !skip
88
+ debversion = $1
89
+ # Seems to be Debian convention that if the package has a
90
+ # package version you seperate that from the upstream version
91
+ # with a hyphen.
92
+ if debversion =~ /-/
93
+ version, package_version = debversion.split('-', 2)
94
+ else
95
+ version = debversion
96
+ end
97
+ pkg = Tpkg.pkg_for_native_package(name, version, package_version, :native_available)
98
+ native_packages << pkg
99
+ end
100
+ end
101
+ stderr_first_line = stderr.gets
102
+ end
103
+ # FIXME: popen3 doesn't set $?
104
+ if !$?.success?
105
+ # Ignore 'no matching packages', raise anything else
106
+ if stderr_first_line !~ 'No packages found'
107
+ raise "available_native_packages error running apt-cache"
108
+ end
109
+ end
110
+ native_packages
111
+ end
112
+ def native_pkg_to_install_string(pkg)
113
+ name = pkg[:metadata][:name]
114
+ version = pkg[:metadata][:version]
115
+ package_version = pkg[:metadata][:package_version]
116
+ pkgname = "#{name}=#{version}"
117
+ if package_version
118
+ pkgname << "-#{package_version}"
119
+ end
120
+ pkgname
121
+ end
122
+ def install_native_package(pkg)
123
+ pkgname = native_pkg_to_install_string(pkg)
124
+ cmd = "#{@aptgetcmd} -y install #{pkgname}"
125
+ puts "Running '#{cmd}' to install native package" if @debug
126
+ system(cmd)
127
+ end
128
+ def upgrade_native_package(pkg)
129
+ pkgname = native_pkg_to_install_string(pkg)
130
+ cmd = "#{@aptgetcmd} -y install #{pkgname}"
131
+ puts "Running '#{cmd}' to upgrade native package" if @debug
132
+ system(cmd)
133
+ end
134
+
135
+ def os_version
136
+ if !@os_version
137
+ if Facter['lsbmajdistrelease'] &&
138
+ Facter['lsbmajdistrelease'].value &&
139
+ !Facter['lsbmajdistrelease'].value.empty?
140
+ lsbmajdistrelease = Facter['lsbmajdistrelease'].value
141
+ # Normal wheezy beta returns 'testing', but Raspian on the
142
+ # Raspberry Pi returns this uglier string. Normalize it.
143
+ if lsbmajdistrelease == 'testing/unstable'
144
+ lsbmajdistrelease = 'testing'
145
+ end
146
+ @os_version = lsbmajdistrelease
147
+ elsif Facter['lsbdistrelease'] &&
148
+ Facter['lsbdistrelease'].value &&
149
+ !Facter['lsbdistrelease'].value.empty? &&
150
+ # Work around lack of lsbmajdistrelease on older versions of Ubuntu
151
+ # due to older version of facter. Support for lsbmajdistrelease on
152
+ # Ubuntu was added in facter 1.5.3, but there's no good way to force
153
+ # older Ubuntu systems to a newer version of facter.
154
+ @os_version = Facter['lsbdistrelease'].value.split('.').first
155
+ end
156
+ end
157
+ super
158
+ end
159
+ end
@@ -0,0 +1,113 @@
1
+ # tpkg package management system
2
+ # License: MIT (http://www.opensource.org/licenses/mit-license.php)
3
+
4
+ require 'erb'
5
+
6
+ class Tpkg::OS::FreeBSD < Tpkg::OS
7
+ def self.supported?
8
+ Facter.loadfacts
9
+ Facter['operatingsystem'].value == 'FreeBSD'
10
+ end
11
+ register_implementation(self)
12
+
13
+ def initialize(options={})
14
+ @pkginfocmd = options[:pkginfocmd] || options[:testcmd] || 'pkg_info'
15
+ @pkgaddcmd = options[:pkgaddcmd] || options[:testcmd] || 'pkg_add'
16
+ @pkgdeletecmd = options[:pkgdeletecmd] || options[:testcmd] || 'pkg_delete'
17
+ # pkg_add -r defaults to the Latest/ directory, which just has generic
18
+ # versionless symlinks like curl.tbz. We want to use the All/ directory
19
+ # so that we can specify a versioned file like curl-7.24.0.tbz.
20
+ @packagesite = options[:packagesite] ||
21
+ 'ftp://ftp.freebsd.org/pub/FreeBSD/ports/<%= arch %>/packages-<%= os_version %>-stable/All/'
22
+ super
23
+ end
24
+
25
+ def packagesite
26
+ url = ERB.new(@packagesite).result(binding)
27
+ # pkg_add expects the URL to end with a /
28
+ url << '/' if (url[-1] != '/')
29
+ url
30
+ end
31
+
32
+ def init_links(installed_path, tpkgfile)
33
+ links = []
34
+ init_directory = '/usr/local/etc/rc.d'
35
+ if tpkgfile[:init][:levels] && tpkgfile[:init][:levels].empty?
36
+ # User doesn't want the init script linked in to auto-start
37
+ else
38
+ links << File.join(init_directory, File.basename(installed_path))
39
+ end
40
+ links
41
+ end
42
+ def available_native_packages(pkgname)
43
+ native_packages = []
44
+ cmd = "#{@pkginfocmd} -E #{pkgname}-*"
45
+ puts "available_native_packages running '#{cmd}'" if @debug
46
+ Open3.popen3(cmd) do |stdin, stdout, stderr|
47
+ stdin.close
48
+ stdout.each_line do |line|
49
+ fbversion = line.sub("#{pkgname}-", '').chomp
50
+ # Seems to be FreeBSD convention that if the package has a
51
+ # package version you seperate that from the upstream version
52
+ # with an underscore.
53
+ version, package_version = fbversion.split('_', 2)
54
+ native_packages <<
55
+ Tpkg.pkg_for_native_package(
56
+ pkgname, version, package_version, :native_installed)
57
+ end
58
+ stderr_first_line = stderr.gets
59
+ end
60
+ # FIXME: popen3 doesn't set $?
61
+ if !$?.success?
62
+ # Ignore 'no matching packages', raise anything else
63
+ if stderr_first_line !~ 'No match'
64
+ raise "available_native_packages error running pkg_info"
65
+ end
66
+ end
67
+ # FIXME: FreeBSD available packages
68
+ # We could either poke around in the ports tree (if installed), or
69
+ # try to recreate the URL "pkg_add -r" would use and pull a
70
+ # directory listing.
71
+ native_packages
72
+ end
73
+ def native_pkg_to_install_string(pkg)
74
+ name = pkg[:metadata][:name]
75
+ version = pkg[:metadata][:version]
76
+ package_version = pkg[:metadata][:package_version]
77
+ pkgname = "#{name}-#{version}"
78
+ if package_version
79
+ pkgname << "_#{package_version}"
80
+ end
81
+ pkgname
82
+ end
83
+ def install_native_package(pkg)
84
+ pkgname = native_pkg_to_install_string(pkg)
85
+ cmd = "PACKAGESITE=#{packagesite} #{@pkgaddcmd} -r #{pkgname}"
86
+ puts "Running '#{cmd}' to install native package" if @debug
87
+ system('sh', '-c', cmd)
88
+ end
89
+ def upgrade_native_package(pkg)
90
+ pkgname = native_pkg_to_install_string(pkg)
91
+ # This is not very ideal. It would be better to download the
92
+ # new package, and if the download is successful remove the
93
+ # old package and install the new one. The way we're doing it
94
+ # here we risk leaving the system with neither version
95
+ # installed if the download of the new package fails.
96
+ # However, the FreeBSD package tools don't make it easy to
97
+ # handle things properly.
98
+ deletecmd = "#{@pkgdeletecmd} #{pkgname}"
99
+ addcmd = "PACKAGESITE=#{packagesite} #{@pkgaddcmd} -r #{pkgname}"
100
+ puts "Running '#{deletecmd}' and '#{addcmd}' to upgrade native package" if @debug
101
+ system(deletecmd)
102
+ system('sh', '-c', addcmd)
103
+ end
104
+
105
+ def os_version
106
+ if !@os_version
107
+ # Extract 7 from 7.1-RELEASE, for example
108
+ fbver = Facter['operatingsystemrelease'].value
109
+ @os_version = fbver.split('.').first
110
+ end
111
+ super
112
+ end
113
+ end
@@ -0,0 +1,113 @@
1
+ # tpkg package management system
2
+ # License: MIT (http://www.opensource.org/licenses/mit-license.php)
3
+
4
+ class Tpkg::OS::MacOSX < Tpkg::OS
5
+ def self.supported?
6
+ Facter.loadfacts
7
+ Facter['operatingsystem'].value == 'Darwin'
8
+ end
9
+ register_implementation(self)
10
+
11
+ def initialize(options={})
12
+ @portcmd = options[:portcmd] || options[:testcmd] || '/opt/local/bin/port'
13
+ super
14
+ end
15
+
16
+ def available_native_packages(pkgname)
17
+ native_packages = []
18
+ if File.exist?(@portcmd)
19
+ # Ports can also have an "epoch" number, but that appears to be
20
+ # invisible from the command line
21
+ # http://guide.macports.org/#reference.keywords
22
+ cmd = "#{@portcmd} installed #{pkgname}"
23
+ puts "available_native_packages running '#{cmd}'" if @debug
24
+ IO.popen(cmd) do |pipe|
25
+ pipe.each_line do |line|
26
+ next if line =~ /The following ports are currently installed/
27
+ next if line =~ /None of the specified ports are installed/
28
+ next if line !~ /\(active\)/
29
+ name, portversion = line.split(' ')
30
+ portversion.sub!(/^@/, '')
31
+ # Remove variant names
32
+ portversion.sub!(/\+.*/, '')
33
+ version, package_version = portversion.split('_', 2)
34
+ pkg = Tpkg.pkg_for_native_package(name, version, package_version, :native_installed)
35
+ native_packages << pkg
36
+ end
37
+ end
38
+ if !$?.success?
39
+ raise "available_native_packages error running port"
40
+ end
41
+ cmd = "#{@portcmd} list #{pkgname}"
42
+ puts "available_native_packages running '#{cmd}'" if @debug
43
+ IO.popen(cmd) do |pipe|
44
+ pipe.each_line do |line|
45
+ name, version = line.split(' ')
46
+ version.sub!(/^@/, '')
47
+ package_version = nil
48
+ pkg = Tpkg.pkg_for_native_package(name, version, package_version, :native_available)
49
+ native_packages << pkg
50
+ end
51
+ end
52
+ if !$?.success?
53
+ raise "available_native_packages error running port"
54
+ end
55
+ else
56
+ # Fink, Homebrew support would be nice
57
+ raise "No supported native package tool available on #{os}"
58
+ end
59
+ native_packages
60
+ end
61
+ def native_pkg_to_install_string(pkg)
62
+ pkgname = nil
63
+ if File.exist?(@portcmd)
64
+ pkgname = pkg[:metadata][:name]
65
+ # MacPorts doesn't support installing a specific version (AFAIK)
66
+ if pkg[:metadata][:version]
67
+ warn "Ignoring version with MacPorts"
68
+ end
69
+ if pkg[:metadata][:package_version]
70
+ warn "Ignoring package version with MacPorts"
71
+ end
72
+ else
73
+ # Fink, Homebrew support would be nice
74
+ raise "No supported native package tool available on #{os}"
75
+ end
76
+ pkgname
77
+ end
78
+ def install_native_package(pkg)
79
+ pkgname = native_pkg_to_install_string(pkg)
80
+ if File.exist?(@portcmd)
81
+ cmd = "#{@portcmd} install #{pkgname}"
82
+ puts "Running '#{cmd}' to install native package" if @debug
83
+ system(cmd)
84
+ else
85
+ # Fink, Homebrew support would be nice
86
+ raise "No supported native package tool available on #{os}"
87
+ end
88
+ end
89
+ def upgrade_native_package(pkg)
90
+ pkgname = native_pkg_to_install_string(pkg)
91
+ if File.exist?(@portcmd)
92
+ cmd = "#{@portcmd} upgrade #{pkgname}"
93
+ puts "Running '#{cmd}' to upgrade native package" if @debug
94
+ system(cmd)
95
+ else
96
+ # Fink, Homebrew support would be nice
97
+ raise "No supported native package tool available on #{os}"
98
+ end
99
+ end
100
+
101
+ def os_version
102
+ if !@os_version
103
+ if Facter['macosx_productversion'] &&
104
+ Facter['macosx_productversion'].value &&
105
+ !Facter['macosx_productversion'].value.empty?
106
+ macver = Facter['macosx_productversion'].value
107
+ # Extract 10.5 from 10.5.6, for example
108
+ @os_version = macver.split('.')[0,2].join('.')
109
+ end
110
+ end
111
+ super
112
+ end
113
+ end