tpkg 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +1 -1
  2. data/bin/tpkg +36 -4
  3. data/lib/tpkg.rb +59 -7
  4. metadata +17 -42
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ spec = Gem::Specification.new do |s|
5
5
  s.add_dependency('facter')
6
6
  s.add_dependency('net-ssh')
7
7
  s.add_dependency('ddao-kwalify')
8
- s.version = '2.0.0'
8
+ s.version = '2.0.1'
9
9
  s.authors = ['Darren Dao', 'Jason Heiss']
10
10
  s.email = 'tpkg-users@lists.sourceforge.net'
11
11
  s.homepage = 'http://tpkg.sourceforge.net'
data/bin/tpkg CHANGED
@@ -9,6 +9,7 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
9
9
 
10
10
  require 'optparse'
11
11
  require 'tpkg'
12
+ require 'etc'
12
13
 
13
14
  #
14
15
  # Parse the command line options
@@ -60,7 +61,8 @@ opts.on('--extract', '-x', '=DIRECTORY', 'Extract the metadata for a directory o
60
61
  @action = :extract
61
62
  @action_value = opt
62
63
  end
63
- opts.on('--install', '-i', '=PACKAGES', 'Install one or more packages', Array) do |opt|
64
+ installexample = " --install pkgname=version=package_version\n (Example: tpkg --install hive=2.1) Will install hive version 2.1"
65
+ opts.on('--install', '-i', '=PACKAGES', "Install one or more packages\n#{installexample}", Array) do |opt|
64
66
  @rerun_with_sudo = true
65
67
  @action = :install
66
68
  @action_value = opt
@@ -220,6 +222,9 @@ end
220
222
  opts.on('--qenv', "Display machine's information") do |opt|
221
223
  @action = :query_env
222
224
  end
225
+ opts.on('--qconf', "Display tpkg's configuration settings") do |opt|
226
+ @action = :query_conf
227
+ end
223
228
  opts.on('--source', '=NAME', 'Sources where packages are located', Array) do |opt|
224
229
  @tpkg_options["sources"] = opt
225
230
  end
@@ -332,8 +337,24 @@ def instantiate_tpkg(options = {})
332
337
  # if they don't realize there's an environment variable set.
333
338
  warn "Using base '#{base}' base from $TPKG_HOME"
334
339
  end
335
-
336
- tpkg = Tpkg.new(:base => base, :sources => sources, :report_server => report_server, :lockforce => @lockforce, :force => @force)
340
+ if !@sudo
341
+ curruid = Etc.getpwuid.uid
342
+ if curruid == 0
343
+ puts "** ERROR **\n--no-sudo cannot be used as 'root' user or with sudo command."
344
+ exit 1
345
+ end
346
+ if !File::exists?(File.join(ENV['HOME'], ".tpkg.conf"))
347
+ puts "** ERROR **\nWhen specifying --no-sudo, #{File.join(ENV['HOME'], ".tpkg.conf")} and custom 'base' dir with write privileges is required\n" and exit 1
348
+ elsif base == '/home/t'
349
+ puts "** ERROR **\nWhen specifying --no-sudo, custom base dir with write privileges is required\n" and exit 1
350
+ end
351
+ baseuid = File.stat(base).uid
352
+ if baseuid != curruid
353
+ puts "** ERROR **\nbase dir (#{base}) not owned by you.\n"
354
+ exit 1
355
+ end
356
+ end
357
+ tpkg = Tpkg.new(:base => base, :sources => sources, :report_server => report_server, :lockforce => @lockforce, :force => @force, :sudo => @sudo)
337
358
  end
338
359
 
339
360
  passphrase_callback = lambda do | package |
@@ -503,7 +524,7 @@ when :query_list_files
503
524
  if File.exist?(@action_value)
504
525
  fip = Tpkg::files_in_package(@action_value)
505
526
  tpkg.normalize_paths(fip)
506
- puts "#{pkgfile}:"
527
+ puts "#{@action_value}:"
507
528
  fip[:normalized].each { |file| puts file }
508
529
  else
509
530
  pkgfiles = []
@@ -629,6 +650,17 @@ when :query_tpkg_metadata
629
650
  when :query_env
630
651
  puts "Operating System: #{Tpkg::get_os}"
631
652
  puts "Architecture: #{Tpkg::get_arch}"
653
+ when :query_conf
654
+ # This is somewhat arbitrarily limited to the options read from the
655
+ # tpkg.conf config files. The reason it exists at all is that it is
656
+ # difficult for users to programatically find out what these will be set to
657
+ # without recreating all of our logic about deciding which config files to
658
+ # read, which order to read them in, what environment variables override the
659
+ # config files, etc.
660
+ tpkg = instantiate_tpkg(@tpkg_options)
661
+ puts "Base: #{tpkg.base}"
662
+ puts "Sources: #{tpkg.sources.inspect}"
663
+ puts "Report server: #{tpkg.report_server}"
632
664
  when :query_history
633
665
  tpkg = instantiate_tpkg(@tpkg_options)
634
666
  tpkg.installation_history
data/lib/tpkg.rb CHANGED
@@ -56,7 +56,7 @@ require 'kwalify' # for validating yaml
56
56
 
57
57
  class Tpkg
58
58
 
59
- VERSION = '2.0.0'
59
+ VERSION = '2.0.1'
60
60
  CONFIGDIR = '/etc'
61
61
 
62
62
  GENERIC_ERR = 1
@@ -1126,7 +1126,7 @@ class Tpkg
1126
1126
  metadata = data[:metadata]
1127
1127
  if (metadata && metadata[:files] && metadata[:files][:file_defaults] && metadata[:files][:file_defaults][:posix])
1128
1128
  uid = Tpkg::lookup_uid(metadata[:files][:file_defaults][:posix][:owner]) if metadata[:files][:file_defaults][:posix][:owner]
1129
- gid = Tpkg::lookup_uid(metadata[:files][:file_defaults][:posix][:group]) if metadata[:files][:file_defaults][:posix][:group]
1129
+ gid = Tpkg::lookup_gid(metadata[:files][:file_defaults][:posix][:group]) if metadata[:files][:file_defaults][:posix][:group]
1130
1130
  perms = metadata[:files][:file_defaults][:posix][:perms] if metadata[:files][:file_defaults][:posix][:perms]
1131
1131
  end
1132
1132
 
@@ -1134,7 +1134,7 @@ class Tpkg
1134
1134
  file_metadata = data[:file_metadata]
1135
1135
  if file_metadata && file_metadata[:posix]
1136
1136
  uid = Tpkg::lookup_uid(file_metadata[:posix][:owner]) if file_metadata[:posix][:owner]
1137
- gid = Tpkg::lookup_uid(file_metadata[:posix][:group]) if file_metadata[:posix][:group]
1137
+ gid = Tpkg::lookup_gid(file_metadata[:posix][:group]) if file_metadata[:posix][:group]
1138
1138
  perms = file_metadata[:posix][:perms] if file_metadata[:posix][:perms]
1139
1139
  end
1140
1140
  return perms, uid, gid
@@ -1233,6 +1233,10 @@ class Tpkg
1233
1233
  if options.has_key?(:force)
1234
1234
  @force = options[:force]
1235
1235
  end
1236
+ @sudo = true
1237
+ if options.has_key?(:sudo)
1238
+ @sudo = options[:sudo]
1239
+ end
1236
1240
 
1237
1241
  @file_system_root = '/' # Not sure if this needs to be more portable
1238
1242
  # This option is only intended for use by the test suite
@@ -1293,6 +1297,14 @@ class Tpkg
1293
1297
  @available_packages_cache = {}
1294
1298
  end
1295
1299
 
1300
+ attr_reader :base
1301
+ attr_reader :sources
1302
+ attr_reader :report_server
1303
+ attr_reader :lockforce
1304
+ attr_reader :force
1305
+ attr_reader :sudo
1306
+ attr_reader :file_system_root
1307
+
1296
1308
  def source_to_local_directory(source)
1297
1309
  source_as_directory = source.gsub(/[^a-zA-Z0-9]/, '')
1298
1310
  File.join(@sources_directory, source_as_directory)
@@ -2774,6 +2786,11 @@ class Tpkg
2774
2786
 
2775
2787
  def install_crontabs(metadata)
2776
2788
  crontab_destinations(metadata).each do |crontab, destination|
2789
+ if !@sudo && (destination[destination.keys.first] =~ /\/var\/spool\/cron/)
2790
+ install_crontab_bycmd(metadata, crontab, destination)
2791
+ next
2792
+ end
2793
+
2777
2794
  begin
2778
2795
  if destination[:link]
2779
2796
  install_crontab_link(metadata, crontab, destination)
@@ -2868,8 +2885,25 @@ class Tpkg
2868
2885
  # FIXME: On Solaris we should bounce cron or use the crontab
2869
2886
  # command, otherwise cron won't pick up the changes
2870
2887
  end
2888
+ def install_crontab_bycmd(metadata, crontab, destination)
2889
+ oldcron = `crontab -l`
2890
+ tmpf = '/tmp/tpkg_cron.' + rand.to_s
2891
+ tmpfh = File.open(tmpf,'w')
2892
+ tmpfh.write(oldcron) unless oldcron.empty?
2893
+ tmpfh.puts "### TPKG START - #{@base} - #{File.basename(metadata[:filename].to_s)}"
2894
+ tmpfh.write File.readlines(crontab)
2895
+ tmpfh.puts "### TPKG END - #{@base} - #{File.basename(metadata[:filename].to_s)}"
2896
+ tmpfh.close
2897
+ `crontab #{tmpf}`
2898
+ FileUtils.rm(tmpf)
2899
+ end
2871
2900
  def remove_crontabs(metadata)
2872
2901
  crontab_destinations(metadata).each do |crontab, destination|
2902
+ if !@sudo && (destination[destination.keys.first] =~ /\/var\/spool\/cron/)
2903
+ remove_crontab_bycmd(metadata, crontab, destination)
2904
+ next
2905
+ end
2906
+
2873
2907
  begin
2874
2908
  if destination[:link]
2875
2909
  remove_crontab_link(metadata, crontab, destination)
@@ -2937,6 +2971,24 @@ class Tpkg
2937
2971
  # command, otherwise cron won't pick up the changes
2938
2972
  end
2939
2973
  end
2974
+ def remove_crontab_bycmd(metadata, crontab, destination)
2975
+ oldcron = `crontab -l`
2976
+ tmpf = '/tmp/tpkg_cron.' + rand.to_s
2977
+ tmpfh = File.open(tmpf,'w')
2978
+ skip = false
2979
+ oldcron.each do |line|
2980
+ if line == "### TPKG START - #{@base} - #{File.basename(metadata[:filename].to_s)}\n"
2981
+ skip = true
2982
+ elsif line == "### TPKG END - #{@base} - #{File.basename(metadata[:filename].to_s)}\n"
2983
+ skip = false
2984
+ elsif !skip
2985
+ tmpfh.write(line)
2986
+ end
2987
+ end
2988
+ tmpfh.close
2989
+ `crontab #{tmpf}`
2990
+ FileUtils.rm(tmpf)
2991
+ end
2940
2992
 
2941
2993
  def run_preinstall(package_file, workdir)
2942
2994
  if File.exist?(File.join(workdir, 'tpkg', 'preinstall'))
@@ -3222,7 +3274,7 @@ class Tpkg
3222
3274
 
3223
3275
  if !all_requests_satisfied
3224
3276
  puts errors.join("\n")
3225
- raise "Unable to satisfy the request(s)"
3277
+ raise "Unable to satisfy the request(s). Try running with --debug for more info"
3226
3278
  end
3227
3279
  end
3228
3280
 
@@ -3412,7 +3464,7 @@ class Tpkg
3412
3464
  #solution_packages = best_solution(requirements.dup, packages.dup)
3413
3465
  solution_packages = best_solution(requirements, packages, core_packages)
3414
3466
  if !solution_packages
3415
- raise "Unable to resolve dependencies"
3467
+ raise "Unable to resolve dependencies. Try running with --debug for more info"
3416
3468
  end
3417
3469
 
3418
3470
  success = handle_conflicting_pkgs(installed_packages, solution_packages, options)
@@ -3634,7 +3686,7 @@ class Tpkg
3634
3686
  solution_packages = best_solution(requirements, packages, core_packages)
3635
3687
 
3636
3688
  if solution_packages.nil?
3637
- raise "Unable to find solution for upgrading. Please verify that you specified the correct package(s) for upgrade."
3689
+ raise "Unable to find solution for upgrading. Please verify that you specified the correct package(s) for upgrade. Try running with --debug for more info"
3638
3690
  end
3639
3691
 
3640
3692
  success = handle_conflicting_pkgs(installed_packages, solution_packages, options)
@@ -4387,7 +4439,7 @@ class Tpkg
4387
4439
  parse_requests(requests, requirements, packages)
4388
4440
  packages = packages.values.flatten
4389
4441
  if packages.size < 1
4390
- puts "Unable to find any packages that satisfy your request."
4442
+ puts "Unable to find any packages that satisfy your request. Try running with --debug for more info"
4391
4443
  Dir.chdir(original_dir)
4392
4444
  return GENERIC_ERR
4393
4445
  end
metadata CHANGED
@@ -1,13 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tpkg
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease: false
6
- segments:
7
- - 2
8
- - 0
9
- - 0
10
- version: 2.0.0
4
+ version: 2.0.1
11
5
  platform: ruby
12
6
  authors:
13
7
  - Darren Dao
@@ -16,51 +10,39 @@ autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
12
 
19
- date: 2010-08-23 00:00:00 -07:00
13
+ date: 2010-10-22 00:00:00 -07:00
20
14
  default_executable:
21
15
  dependencies:
22
16
  - !ruby/object:Gem::Dependency
23
17
  name: facter
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
26
- none: false
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
27
21
  requirements:
28
22
  - - ">="
29
23
  - !ruby/object:Gem::Version
30
- hash: 3
31
- segments:
32
- - 0
33
24
  version: "0"
34
- type: :runtime
35
- version_requirements: *id001
25
+ version:
36
26
  - !ruby/object:Gem::Dependency
37
27
  name: net-ssh
38
- prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
41
31
  requirements:
42
32
  - - ">="
43
33
  - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
34
  version: "0"
48
- type: :runtime
49
- version_requirements: *id002
35
+ version:
50
36
  - !ruby/object:Gem::Dependency
51
37
  name: ddao-kwalify
52
- prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
54
- none: false
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
55
41
  requirements:
56
42
  - - ">="
57
43
  - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
44
  version: "0"
62
- type: :runtime
63
- version_requirements: *id003
45
+ version:
64
46
  description:
65
47
  email: tpkg-users@lists.sourceforge.net
66
48
  executables:
@@ -111,28 +93,21 @@ rdoc_options: []
111
93
  require_paths:
112
94
  - lib
113
95
  required_ruby_version: !ruby/object:Gem::Requirement
114
- none: false
115
96
  requirements:
116
97
  - - ">="
117
98
  - !ruby/object:Gem::Version
118
- hash: 31
119
- segments:
120
- - 1
121
- - 8
122
99
  version: "1.8"
100
+ version:
123
101
  required_rubygems_version: !ruby/object:Gem::Requirement
124
- none: false
125
102
  requirements:
126
103
  - - ">="
127
104
  - !ruby/object:Gem::Version
128
- hash: 3
129
- segments:
130
- - 0
131
105
  version: "0"
106
+ version:
132
107
  requirements: []
133
108
 
134
109
  rubyforge_project: tpkg
135
- rubygems_version: 1.3.7
110
+ rubygems_version: 1.3.5
136
111
  signing_key:
137
112
  specification_version: 3
138
113
  summary: tpkg Application Packaging & Deployment