uberinstaller 1.0.0
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.
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +7 -0
- data/TODO +14 -0
- data/bin/uberinstaller +6 -0
- data/lib/uberinstaller.rb +24 -0
- data/lib/uberinstaller/cli.rb +51 -0
- data/lib/uberinstaller/commander.rb +112 -0
- data/lib/uberinstaller/config.rb +55 -0
- data/lib/uberinstaller/exception.rb +40 -0
- data/lib/uberinstaller/exceptions/command_not_processable.rb +13 -0
- data/lib/uberinstaller/exceptions/invalid_folder.rb +13 -0
- data/lib/uberinstaller/exceptions/invalid_json.rb +13 -0
- data/lib/uberinstaller/exceptions/invalid_local_package.rb +13 -0
- data/lib/uberinstaller/exceptions/invalid_package.rb +13 -0
- data/lib/uberinstaller/exceptions/invalid_ppa.rb +13 -0
- data/lib/uberinstaller/exceptions/invalid_url.rb +13 -0
- data/lib/uberinstaller/exceptions/json_file_not_found.rb +13 -0
- data/lib/uberinstaller/exceptions/json_parse_error.rb +13 -0
- data/lib/uberinstaller/exceptions/missing_local_package.rb +13 -0
- data/lib/uberinstaller/exceptions/missing_url.rb +13 -0
- data/lib/uberinstaller/exceptions/multiple_local_files_not_supported.rb +13 -0
- data/lib/uberinstaller/exceptions/multiple_repositories_not_supported.rb +13 -0
- data/lib/uberinstaller/exceptions/no_preprocessor_exception.rb +13 -0
- data/lib/uberinstaller/exceptions/parser_argument_error.rb +13 -0
- data/lib/uberinstaller/exceptions/wrong_architecture.rb +13 -0
- data/lib/uberinstaller/exceptions/wrong_version.rb +13 -0
- data/lib/uberinstaller/installer.rb +284 -0
- data/lib/uberinstaller/logger.rb +113 -0
- data/lib/uberinstaller/package_manager.rb +27 -0
- data/lib/uberinstaller/package_managers/apt.rb +18 -0
- data/lib/uberinstaller/package_managers/base.rb +87 -0
- data/lib/uberinstaller/package_managers/dpkg.rb +15 -0
- data/lib/uberinstaller/package_managers/git.rb +15 -0
- data/lib/uberinstaller/parser.rb +51 -0
- data/lib/uberinstaller/platform.rb +103 -0
- data/lib/uberinstaller/runner.rb +218 -0
- data/lib/uberinstaller/utils.rb +13 -0
- data/lib/uberinstaller/version.rb +3 -0
- data/uberinstaller.gemspec +35 -0
- metadata +243 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Uberinstaller
|
4
|
+
module Exception
|
5
|
+
|
6
|
+
# When package with :type => :git has no :folder
|
7
|
+
class InvalidFolder < Exception
|
8
|
+
def initialize(name)
|
9
|
+
super "#{name} :folder attribute invalid or missing", false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Uberinstaller
|
4
|
+
module Exception
|
5
|
+
|
6
|
+
# When package with :type => :git :url attribute does not respond 200 http status on check
|
7
|
+
class InvalidJson < Exception
|
8
|
+
def initialize(name)
|
9
|
+
super "#{name} :json seems to not be a valid string, please check", false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Uberinstaller
|
4
|
+
module Exception
|
5
|
+
|
6
|
+
# When package with :type => :local :pkg is not valid
|
7
|
+
class InvalidLocalPackage < Exception
|
8
|
+
def initialize(name)
|
9
|
+
super "#{name} :pkg seems not to be a valid local package", false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Uberinstaller
|
4
|
+
module Exception
|
5
|
+
|
6
|
+
# When package with :type => system has no :pkg specified
|
7
|
+
class InvalidPackage < Exception
|
8
|
+
def initialize(name)
|
9
|
+
super "#{name} has a system installation but invalid :pkg is specified, skipping", false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Uberinstaller
|
4
|
+
module Exception
|
5
|
+
|
6
|
+
# When package with :type => system has an invalid :ppa
|
7
|
+
class InvalidPpa < Exception
|
8
|
+
def initialize(name)
|
9
|
+
super "#{name} has an invalid ppa, skipping", false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Uberinstaller
|
4
|
+
module Exception
|
5
|
+
|
6
|
+
# When package with :type => :git :url attribute does not respond 200 http status on check
|
7
|
+
class InvalidUrl < Exception
|
8
|
+
def initialize(name)
|
9
|
+
super "#{name} :url seems to not be a valid repo, please check", false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Uberinstaller
|
4
|
+
module Exception
|
5
|
+
|
6
|
+
# When package with :type => :local has no :pkg attribute
|
7
|
+
class MissingLocalPackage < Exception
|
8
|
+
def initialize(name)
|
9
|
+
super "#{name} :pkg seems not to be a valid local package", false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Uberinstaller
|
4
|
+
module Exception
|
5
|
+
|
6
|
+
# When :url for a :type => :git package is not a String
|
7
|
+
class MultipleLocalFilesNotSupported < Exception
|
8
|
+
def initialize()
|
9
|
+
super "Specify multiple local packages for one package is not supported"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Uberinstaller
|
4
|
+
module Exception
|
5
|
+
|
6
|
+
# When :url for a :type => :git package is not a String
|
7
|
+
class MultipleRepositoriesNotSupported < Exception
|
8
|
+
def initialize(name)
|
9
|
+
super "Specify multiple git repositories for one package is not supported"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Uberinstaller
|
4
|
+
module Exception
|
5
|
+
|
6
|
+
# When package with :type => system has no :pkg specified
|
7
|
+
class NoPreprocessorException < Exception
|
8
|
+
def initialize(name)
|
9
|
+
super "Does not exist a valid preprocessor for #{name} type", false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Uberinstaller
|
4
|
+
module Exception
|
5
|
+
|
6
|
+
# Error when file passed to JSON parser does not exists
|
7
|
+
class ParserArgumentError < Exception
|
8
|
+
def initialize(file)
|
9
|
+
super "Cannot find #{file}, probably a mistyped path?"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Uberinstaller
|
4
|
+
module Exception
|
5
|
+
|
6
|
+
# Architecture in JSON file different from current OS
|
7
|
+
class WrongArchitecture < Exception
|
8
|
+
def initialize(arch)
|
9
|
+
super "Installation file requires #{arch} architecture"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Uberinstaller
|
4
|
+
module Exception
|
5
|
+
|
6
|
+
# OS version in JSON file different from current OS version ( by codename or number )
|
7
|
+
class WrongVersion < Exception
|
8
|
+
def initialize(version)
|
9
|
+
super "Installation file requires a different version. Version required: #{version}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,284 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'uberinstaller/logger'
|
4
|
+
require 'uberinstaller/config'
|
5
|
+
require 'uberinstaller/exception'
|
6
|
+
require 'uberinstaller/package_manager'
|
7
|
+
|
8
|
+
require 'octokit'
|
9
|
+
|
10
|
+
module Uberinstaller
|
11
|
+
class Installer
|
12
|
+
include Loggable
|
13
|
+
|
14
|
+
# Initialize the class
|
15
|
+
#
|
16
|
+
# @param pkg_name [String] the name of the package
|
17
|
+
# @param pkg_body [Hash] an Hash containing the parsed information for the package
|
18
|
+
def initialize(pkg_name, pkg_body)
|
19
|
+
@name = pkg_name
|
20
|
+
@body = pkg_body
|
21
|
+
|
22
|
+
# an Hash containing private processing info for the class
|
23
|
+
@meta = Hash.new
|
24
|
+
@meta[:installable] = true
|
25
|
+
|
26
|
+
if @body.has_key? :skip and @body[:skip]
|
27
|
+
logger.warn "#{@name} has :skip option active, skipping "
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Return if the package is installable
|
32
|
+
#
|
33
|
+
# @return [bool] true if the package can be installed, false otherwise
|
34
|
+
def installable?
|
35
|
+
@body[:skip] ? false : true
|
36
|
+
end
|
37
|
+
|
38
|
+
# Perform package validation based upon installation type
|
39
|
+
#
|
40
|
+
# @param type [String] the installation type
|
41
|
+
def validate(type)
|
42
|
+
case type
|
43
|
+
when 'system' then validate_system
|
44
|
+
when 'git' then validate_git
|
45
|
+
when 'local' then validate_local
|
46
|
+
when 'json' then validate_json
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Perform package installation based upon installation type, only if installable? is true
|
51
|
+
#
|
52
|
+
# @param type [String] the installation type
|
53
|
+
def install(type)
|
54
|
+
return unless installable?
|
55
|
+
|
56
|
+
case type
|
57
|
+
when 'git' then install_git
|
58
|
+
when 'local' then install_local
|
59
|
+
when 'system' then install_system
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Perform package preprocessing based upon installation type, only if installable? is true
|
64
|
+
#
|
65
|
+
# @param type [String] the installation type
|
66
|
+
def preprocess(type)
|
67
|
+
return unless installable?
|
68
|
+
|
69
|
+
case type
|
70
|
+
when 'git' then preprocess_git
|
71
|
+
when 'local' then preprocess_local
|
72
|
+
when 'system' then preprocess_system
|
73
|
+
when 'json' then preprocess_json
|
74
|
+
else raise Exception::NoPreprocessorException, type
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
# The remote package manager object
|
81
|
+
#
|
82
|
+
# @return [Object] an instance of a PackageManager
|
83
|
+
def remote_package_manager
|
84
|
+
@remote_package_manager ||= PackageManager.new 'remote'
|
85
|
+
end
|
86
|
+
|
87
|
+
# The local package manager object
|
88
|
+
#
|
89
|
+
# @return [Object] an instance of a PackageManager
|
90
|
+
def local_package_manager
|
91
|
+
@local_package_manager ||= PackageManager.new 'local'
|
92
|
+
end
|
93
|
+
|
94
|
+
# The git package manager object
|
95
|
+
#
|
96
|
+
# @return [Object] an instance of a PackageManager
|
97
|
+
def git_package_manager
|
98
|
+
@git_package_manager ||= PackageManager.new 'git'
|
99
|
+
end
|
100
|
+
|
101
|
+
# Install a package using the system package manager
|
102
|
+
def install_system
|
103
|
+
logger.debug 'Sytem type installation'
|
104
|
+
|
105
|
+
if @body[:system][:pkg].kind_of?(Array)
|
106
|
+
@body[:system][:pkg].each { |pkg| remote_package_manager.install pkg }
|
107
|
+
elsif @body[:system][:pkg].kind_of?(String)
|
108
|
+
remote_package_manager.install @body[:system][:pkg]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Preprocess a system type package.
|
113
|
+
#
|
114
|
+
# Launch validation and on success add the ppa to the system, if any
|
115
|
+
def preprocess_system
|
116
|
+
logger.debug 'Sytem type preprocess'
|
117
|
+
|
118
|
+
begin
|
119
|
+
validate 'system'
|
120
|
+
rescue Exception => e
|
121
|
+
@body[:skip] = true
|
122
|
+
raise e
|
123
|
+
else
|
124
|
+
remote_package_manager.add_repository @body[:system][:ppa] if @body[:system].has_key? :ppa
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Validate a system type package
|
129
|
+
#
|
130
|
+
# Check if package has a :pkg key and if if is valid; check if package has a :ppa key and perform validation on the ppa string.
|
131
|
+
#
|
132
|
+
# @raise [Uberinstaller::Exception::InvalidPackage] if the package is not valid
|
133
|
+
# @raise [Uberinstaller::Exception::InvalidPpa] if the ppa is not valid
|
134
|
+
def validate_system
|
135
|
+
logger.debug 'Sytem type validation'
|
136
|
+
|
137
|
+
if !@body[:system].has_key? :pkg or !valid_pkg?
|
138
|
+
raise Uberinstaller::Exception::InvalidPackage, @name
|
139
|
+
end
|
140
|
+
|
141
|
+
if @body[:system].has_key? :ppa
|
142
|
+
raise Uberinstaller::Exception::InvalidPpa, @name unless valid_repository? @body[:system][:ppa]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# Install a package using the Git package manager
|
147
|
+
def install_git
|
148
|
+
if @body[:git][:url].kind_of?(String)
|
149
|
+
git_package_manager.install @body[:git][:url] + " " + @body[:git][:folder]
|
150
|
+
else
|
151
|
+
raise Exception::MultipleRepositoriesNotSupported
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
# Preprocess a git type package
|
156
|
+
#
|
157
|
+
# Launch validation
|
158
|
+
def preprocess_git
|
159
|
+
logger.debug 'Git type preprocess'
|
160
|
+
begin
|
161
|
+
validate 'git'
|
162
|
+
rescue Exception => e
|
163
|
+
@body[:skip] = true
|
164
|
+
raise e
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# Validate a git type package
|
169
|
+
#
|
170
|
+
# Check for :folder and :url keys and perform validation on :url
|
171
|
+
#
|
172
|
+
# @raise [Uberinstaller::Exception::InvalidFolder] if no :folder is specified
|
173
|
+
# @raise [Uberinstaller::Exception::MissingUrl] if no :url is specified
|
174
|
+
# @raise [Uberinstaller::Exception::Invalid] if :url is not a valid Github repository
|
175
|
+
def validate_git
|
176
|
+
logger.debug 'Git type validation'
|
177
|
+
|
178
|
+
if !@body[:git].has_key? :folder
|
179
|
+
raise Uberinstaller::Exception::InvalidFolder, @name
|
180
|
+
end
|
181
|
+
|
182
|
+
if !@body[:git].has_key? :url
|
183
|
+
raise Uberinstaller::Exception::MissingUrl, @name
|
184
|
+
# else
|
185
|
+
# repo_url = @body[:git][:url].split('github.com')[1].split('.git')[0]
|
186
|
+
# repo_url[0] = ''
|
187
|
+
|
188
|
+
# begin
|
189
|
+
# Octokit.repo repo_url
|
190
|
+
# rescue
|
191
|
+
# raise Uberinstaller::Exception::InvalidUrl, @name
|
192
|
+
# end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# Install a package using the Local package manager
|
197
|
+
def install_local
|
198
|
+
if @body[:local][:pkg].kind_of?(String)
|
199
|
+
if File.extname(@body[:local][:pkg]) == '.deb'
|
200
|
+
local_package_manager.install @body[:local][:pkg]
|
201
|
+
else
|
202
|
+
pkg_path = File.join Config.local_pkg_path, @body[:local][:pkg]
|
203
|
+
`sudo ./#{pkg_path}`
|
204
|
+
end
|
205
|
+
else
|
206
|
+
raise Exception::MultipleLocalFilesNotSupported
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
# Preprocess a local type package
|
211
|
+
#
|
212
|
+
# Launch validation
|
213
|
+
def preprocess_local
|
214
|
+
logger.debug 'Local type preprocess'
|
215
|
+
begin
|
216
|
+
validate 'local'
|
217
|
+
rescue Exception => e
|
218
|
+
@body[:skip] = true
|
219
|
+
raise e
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
# Validate local type package
|
224
|
+
#
|
225
|
+
# @raise [Uberinstaller::Exception::MissingLocalPackage] if the local package has no :pkg
|
226
|
+
# @raise [Uberinstaller::Exception::InvalidLocalPackage] if the local package has an invalid :pkg
|
227
|
+
def validate_local
|
228
|
+
logger.debug 'Local type validation'
|
229
|
+
|
230
|
+
if !@body[:local].has_key? :pkg
|
231
|
+
raise Exception::MissingLocalPackage, @name
|
232
|
+
else
|
233
|
+
raise Exception::InvalidLocalPackage, @name if !valid_local_pkg?
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def preprocess_json
|
238
|
+
logger.debug 'JSON type validation'
|
239
|
+
validate 'json'
|
240
|
+
end
|
241
|
+
|
242
|
+
def validate_json
|
243
|
+
if @body[:json].kind_of? String
|
244
|
+
file = File.join Config::json_path, @body[:json] + '.json'
|
245
|
+
raise Exception::JsonFileNotFound, @body[:json] unless File.exists? file
|
246
|
+
else
|
247
|
+
raise Exception::InvalidJson, @name
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
###
|
252
|
+
|
253
|
+
# Check if the string is a valid repository
|
254
|
+
#
|
255
|
+
# TODO: chack for repo, not only ppa
|
256
|
+
# @param repository [String] a valid string repository/PPA URL
|
257
|
+
#
|
258
|
+
# @return [bool] true if the string is a valid repository, false otherwise
|
259
|
+
def valid_repository?(repository)
|
260
|
+
logger.debug 'Validate repository'
|
261
|
+
repository =~ /ppa:[a-z0-9-]+(\/[a-z0-9-]+)?/
|
262
|
+
end
|
263
|
+
|
264
|
+
# Check if a system package is valid
|
265
|
+
#
|
266
|
+
# A package is valid when the :pkg key is a non-empty string or a non-empty array
|
267
|
+
#
|
268
|
+
# @return [bool] true if the package is valid, false otherwise
|
269
|
+
def valid_pkg?
|
270
|
+
logger.debug 'Validate :pkg'
|
271
|
+
!(@body[:system][:pkg].empty? or @body[:system][:pkg].any? { |a| a.empty? })
|
272
|
+
end
|
273
|
+
|
274
|
+
# Check if a local package is valid
|
275
|
+
#
|
276
|
+
# A local package is valid when :pkg key is a string corresponding to a existing file path
|
277
|
+
#
|
278
|
+
# @return [bool] true if the package is validw, false otherwise
|
279
|
+
def valid_local_pkg?
|
280
|
+
logger.debug 'Validate local pkg'
|
281
|
+
File.file?(File.join Uberinstaller::Config.local_pkg_path, @body[:local][:pkg])
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|