ngauthier-aptinstaller 0.3.1 → 0.3.2

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.
@@ -13,13 +13,8 @@ Put something like this in config/aptinstaller.yml:
13
13
 
14
14
  ---
15
15
  packages:
16
- - executable: firefox
17
- - executable: MP4Box
18
- package: gpac
19
-
20
- The executable field is the name of the executable (i.e. $ MP4Box). If the package's name in the
21
- repositories is different from the executable, specify the package name with the "package"
22
- field (i.e. "gpac" which provides the MP4Box executable).
16
+ - name: firefox
17
+ - name: gpac
23
18
 
24
19
  ### Add to Preinitializer
25
20
 
@@ -1,3 +1,4 @@
1
1
  # TODO
2
2
  * Allow version requirements
3
3
  * Allow flag for "custom installation" when a package needs to be built from source
4
+ * Run aptitude show for all packages at once then parse to avoid multi-cmd overhead
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 3
3
- :patch: 1
3
+ :patch: 2
4
4
  :major: 0
@@ -5,14 +5,19 @@ class AptInstaller
5
5
  def self.autopkg(opts = {})
6
6
  config_yaml = self.read_yaml_file(opts[:config])
7
7
  packages = self.detect_packages_to_install(config_yaml['packages'])
8
- if packages.size > 0
8
+ if packages[:not_installed].size > 0
9
9
  $stderr.write "\nThe following packages are required by this program but not installed:\n\n"
10
- packages.each do |package|
11
- $stderr.write "\t* "+package['executable']
12
- $stderr.write " (provided by package \"#{package['package']}\")" if package['package']
13
- $stderr.write "\n"
10
+ packages[:not_installed].each do |package|
11
+ $stderr.write "\t* "+package['name']+"\n"
14
12
  end
15
- $stderr.write "\nYou can install them by running \"aptinstaller\" in the root of your project\n\n"
13
+ end
14
+ if packages[:out_of_date].size > 0
15
+
16
+ end
17
+
18
+ if packages[:not_installed].size + packages[:out_of_date].size > 0
19
+ $stderr.write "\nYou can install and upgrade automatically by "
20
+ $stderr.write "running \"aptinstaller\" in the root of your project\n\n"
16
21
  exit(1)
17
22
  end
18
23
  end
@@ -27,9 +32,14 @@ class AptInstaller
27
32
  $stderr.flush
28
33
  exit(1)
29
34
  end
30
- if packages.size > 0
31
- exec("apt-get install #{packages.collect{|p| p['package'] || p['executable'] }.join(" ")}")
32
- else
35
+ if packages[:not_installed].size > 0
36
+ pkg_str = packages[:not_installed].collect{|p| p['name']}.join(" ")
37
+ system "apt-get install #{pkg_str}"
38
+ end
39
+ if packages[:out_of_date].size > 0
40
+
41
+ end
42
+ if packages[:not_installed].size + packages[:out_of_date].size == 0
33
43
  puts "All dependencies are installed"
34
44
  end
35
45
  end
@@ -57,11 +67,26 @@ class AptInstaller
57
67
 
58
68
  def self.detect_packages_to_install(packages)
59
69
  not_installed = []
70
+ out_of_date = []
60
71
  packages.each do |package|
61
- exec = package['executable']
62
- pkg = package['package']
63
- not_installed.push(package) if `which #{exec}`.size == 0
72
+ not_installed.push(package) unless self.detect_package(package)
73
+ out_of_date.push(package) unless self.verify_version(package)
64
74
  end
65
- not_installed
75
+ {:not_installed => not_installed, :out_of_date => out_of_date}
76
+ end
77
+
78
+ def self.detect_package(package)
79
+ info = `aptitude show #{package['name']}`.split("\n")
80
+ meta = {}
81
+ info.each{|i|
82
+ i = i.split(": ")
83
+ meta[i[0]] = i[1]
84
+ }
85
+ return meta['State'] == 'installed'
86
+ end
87
+
88
+ def self.verify_version(package)
89
+ pkg_name = package['name']
90
+ return true if package['version'] == nil
66
91
  end
67
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ngauthier-aptinstaller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Gauthier