package_manager 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/pkg-find-available +1 -1
- data/bin/pkg-find-installed +1 -1
- data/bin/pkg-install +1 -1
- data/bin/pkg-install-file +7 -1
- data/bin/pkg-list-contents +1 -1
- data/bin/pkg-provides +20 -0
- data/bin/pkg-uninstall +20 -0
- data/lib/package_manager.rb +1 -2
- data/lib/package_manager/apt.rb +6 -0
- data/lib/package_manager/base.rb +105 -23
- data/lib/package_manager/dpkg.rb +4 -0
- data/lib/package_manager/rpm.rb +4 -0
- data/lib/package_manager/yum.rb +4 -0
- metadata +10 -4
data/bin/pkg-find-available
CHANGED
data/bin/pkg-find-installed
CHANGED
data/bin/pkg-install
CHANGED
data/bin/pkg-install-file
CHANGED
@@ -10,5 +10,11 @@ pkg-install-file: Install a package from a file
|
|
10
10
|
Usage: #{ $0 } [options]
|
11
11
|
EOT
|
12
12
|
|
13
|
+
if ARGV.size < 1
|
14
|
+
$stderr.puts 'No file name supplied' if ARGV.size < 1
|
15
|
+
$stderr.puts usage
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
|
13
19
|
pkg = PackageManager::Base.load
|
14
|
-
puts pkg.install_file( ARGV )
|
20
|
+
puts pkg.install_file( ARGV[ 0 ] )
|
data/bin/pkg-list-contents
CHANGED
data/bin/pkg-provides
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
ROOT_PATH = File.dirname( File.dirname( File.expand_path( __FILE__ ) ) )
|
4
|
+
LIB_PATH = File.join( ROOT_PATH, 'lib' )
|
5
|
+
$:.unshift( LIB_PATH )
|
6
|
+
require 'package_manager'
|
7
|
+
|
8
|
+
usage = <<EOT
|
9
|
+
pkg-provides: Find the package a file comes from
|
10
|
+
Usage: #{ $0 } [options]
|
11
|
+
EOT
|
12
|
+
|
13
|
+
if ARGV.size < 1
|
14
|
+
$stderr.puts 'No file name supplied' if ARGV.size < 1
|
15
|
+
$stderr.puts usage
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
|
19
|
+
pkg = PackageManager::Base.load
|
20
|
+
puts pkg.provides( ARGV )
|
data/bin/pkg-uninstall
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
ROOT_PATH = File.dirname( File.dirname( File.expand_path( __FILE__ ) ) )
|
4
|
+
LIB_PATH = File.join( ROOT_PATH, 'lib' )
|
5
|
+
$:.unshift( LIB_PATH )
|
6
|
+
require 'package_manager'
|
7
|
+
|
8
|
+
usage = <<EOT
|
9
|
+
pkg-uninstall: Uninstall the named package
|
10
|
+
Usage: #{ $0 } [options]
|
11
|
+
EOT
|
12
|
+
|
13
|
+
if ARGV.size < 1
|
14
|
+
$stderr.puts 'No package name supplied'
|
15
|
+
$stderr.puts usage
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
|
19
|
+
pkg = PackageManager::Base.load
|
20
|
+
puts pkg.uninstall( ARGV[ 0 ] )
|
data/lib/package_manager.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'rubygems' if RUBY_VERSION < '1.9'
|
2
2
|
require 'package_manager/base'
|
3
|
-
require 'package_manager/port'
|
4
3
|
|
5
4
|
module PackageManager
|
6
5
|
|
7
6
|
module VERSION #:nodoc:
|
8
7
|
MAJOR = 0
|
9
8
|
MINOR = 0
|
10
|
-
TINY =
|
9
|
+
TINY = 3
|
11
10
|
|
12
11
|
STRING = [ MAJOR, MINOR, TINY ].join('.')
|
13
12
|
end
|
data/lib/package_manager/apt.rb
CHANGED
data/lib/package_manager/base.rb
CHANGED
@@ -1,47 +1,129 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
# Pre-declare Base class, so we can load derived classes for class factory
|
4
|
+
module PackageManager
|
5
|
+
class Base; end
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'package_manager/apt'
|
9
|
+
require 'package_manager/dpkg'
|
10
|
+
require 'package_manager/fink'
|
11
|
+
require 'package_manager/port'
|
12
|
+
require 'package_manager/rpm'
|
13
|
+
require 'package_manager/yum'
|
14
|
+
|
1
15
|
module PackageManager
|
2
16
|
|
3
17
|
class Base
|
4
18
|
|
5
19
|
attr_reader :name
|
6
20
|
|
7
|
-
|
8
|
-
|
21
|
+
KNOWN_PACKAGE_MANAGERS = { 'apt' => Apt,
|
22
|
+
'dpkg' => Dpkg,
|
23
|
+
'fink' => Fink,
|
24
|
+
'port' => Port,
|
25
|
+
'rpm' => Rpm,
|
26
|
+
'yum' => Yum }
|
27
|
+
|
28
|
+
def self.load( package_manager = guess_package_manager )
|
29
|
+
raise 'Unknown package manager' if KNOWN_PACKAGE_MANAGERS[ package_manager ].nil?
|
30
|
+
KNOWN_PACKAGE_MANAGERS[ package_manager ].new
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns an array of matches
|
34
|
+
def find_available( package_match )
|
35
|
+
run_command( find_available_command, package_match ).split("\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns an array of matches
|
39
|
+
def find_installed( package_match )
|
40
|
+
run_command( find_installed_command, package_match ).split("\n").uniq
|
9
41
|
end
|
10
42
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
run_command( command, argv[ 0 ] )
|
43
|
+
# Returns an array of file names
|
44
|
+
def list_contents( package )
|
45
|
+
run_command( list_contents_command, package ).split("\n")
|
15
46
|
end
|
16
47
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
48
|
+
# Returns true if the package installed successfully
|
49
|
+
def install( package )
|
50
|
+
run_command( install_command, package )
|
51
|
+
$?.exitstatus == 0
|
21
52
|
end
|
22
53
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
run_command(
|
54
|
+
# Returns true if the package installed successfully
|
55
|
+
def install_file( file )
|
56
|
+
raise 'The file '#{ file }' does not exist' if ! File.exist?( file )
|
57
|
+
run_command( install_file_command, file )
|
58
|
+
$?.exitstatus == 0
|
27
59
|
end
|
28
60
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
61
|
+
# Returns true if the package uninstalled successfully
|
62
|
+
def uninstall( package )
|
63
|
+
run_command( uninstall_command, package )
|
64
|
+
$?.exitstatus == 0
|
33
65
|
end
|
34
66
|
|
35
|
-
|
36
|
-
|
37
|
-
raise
|
38
|
-
run_command(
|
67
|
+
# Returns the package name if found, or an empty string
|
68
|
+
def provides( file )
|
69
|
+
raise 'The file '#{ file }' does not exist' if ! File.exist?( file )
|
70
|
+
run_command( provides_command, file )
|
39
71
|
end
|
40
72
|
|
41
73
|
private
|
42
74
|
|
43
75
|
def run_command( command, *args )
|
44
|
-
`#{ command } #{ args.join( ' ' ) }
|
76
|
+
`#{ command } #{ args.join( ' ' ) }`.chomp
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.guess_package_manager
|
80
|
+
case operating_system
|
81
|
+
when 'linux'
|
82
|
+
linux_package_manager
|
83
|
+
when 'darwin'
|
84
|
+
darwin_package_manager
|
85
|
+
else
|
86
|
+
raise 'Unhandled operating system'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.operating_system
|
91
|
+
platforms = Gem.platforms
|
92
|
+
raise 'Unexpected response from Gem.platforms' unless platforms.respond_to?( :size )
|
93
|
+
raise 'Expected Array of 2 values' unless platforms.size == 2
|
94
|
+
raise 'Unexpected value returned by Gem.platforms' unless platforms[ 1 ].respond_to?( :os )
|
95
|
+
platforms[ 1 ].os
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.linux_package_manager
|
99
|
+
case
|
100
|
+
when program_installed?( 'apt-get' )
|
101
|
+
'apt'
|
102
|
+
when program_installed?( 'yum' )
|
103
|
+
'yum'
|
104
|
+
when program_installed?( 'rpm' )
|
105
|
+
'rpm'
|
106
|
+
else
|
107
|
+
raise "Unknown or missing package manager system"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# TODO: Add brew
|
112
|
+
def self.darwin_package_manager
|
113
|
+
# Be opinionated and prefer Mac Ports if both it and Fink are installed
|
114
|
+
case
|
115
|
+
when program_installed?( 'port' )
|
116
|
+
'port'
|
117
|
+
when program_installed?( 'apt-get' )
|
118
|
+
'fink'
|
119
|
+
else
|
120
|
+
raise "Unknown or missing package manager system"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.program_installed?( program )
|
125
|
+
`which '#{ program }'`
|
126
|
+
$?.exitstatus == 0
|
45
127
|
end
|
46
128
|
|
47
129
|
end
|
data/lib/package_manager/dpkg.rb
CHANGED
data/lib/package_manager/rpm.rb
CHANGED
data/lib/package_manager/yum.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: package_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joe Yates
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-10 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -42,6 +42,8 @@ executables:
|
|
42
42
|
- pkg-install
|
43
43
|
- pkg-install-file
|
44
44
|
- pkg-list-contents
|
45
|
+
- pkg-provides
|
46
|
+
- pkg-uninstall
|
45
47
|
extensions: []
|
46
48
|
|
47
49
|
extra_rdoc_files:
|
@@ -51,6 +53,8 @@ extra_rdoc_files:
|
|
51
53
|
- bin/pkg-install
|
52
54
|
- bin/pkg-install-file
|
53
55
|
- bin/pkg-list-contents
|
56
|
+
- bin/pkg-provides
|
57
|
+
- bin/pkg-uninstall
|
54
58
|
- lib/package_manager/apt.rb
|
55
59
|
- lib/package_manager/base.rb
|
56
60
|
- lib/package_manager/dpkg.rb
|
@@ -67,6 +71,8 @@ files:
|
|
67
71
|
- bin/pkg-install
|
68
72
|
- bin/pkg-install-file
|
69
73
|
- bin/pkg-list-contents
|
74
|
+
- bin/pkg-provides
|
75
|
+
- bin/pkg-uninstall
|
70
76
|
- lib/package_manager/apt.rb
|
71
77
|
- lib/package_manager/base.rb
|
72
78
|
- lib/package_manager/dpkg.rb
|