native-package-installer 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +9 -0
- data/Rakefile +35 -0
- data/doc/text/gpl-3.txt +674 -0
- data/doc/text/lgpl-3.txt +165 -0
- data/lib/native-package-installer.rb +154 -0
- data/lib/native-package-installer/executable-finder.rb +81 -0
- data/lib/native-package-installer/platform.rb +44 -0
- data/lib/native-package-installer/platform/alt-linux.rb +34 -0
- data/lib/native-package-installer/platform/arch-linux.rb +40 -0
- data/lib/native-package-installer/platform/debian.rb +40 -0
- data/lib/native-package-installer/platform/fedora.rb +34 -0
- data/lib/native-package-installer/platform/homebrew.rb +40 -0
- data/lib/native-package-installer/platform/macports.rb +40 -0
- data/lib/native-package-installer/platform/redhat.rb +41 -0
- data/lib/native-package-installer/platform/suse.rb +40 -0
- data/lib/native-package-installer/platform/unknown.rb +28 -0
- data/lib/native-package-installer/version.rb +18 -0
- data/test/run-test.rb +23 -0
- data/test/test-executable-finder.rb +90 -0
- metadata +128 -0
data/doc/text/lgpl-3.txt
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# Copyright (C) 2017 Ruby-GNOME2 Project Team
|
2
|
+
#
|
3
|
+
# This library is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require "shellwords"
|
17
|
+
|
18
|
+
require "native-package-installer/version"
|
19
|
+
|
20
|
+
require "native-package-installer/executable-finder"
|
21
|
+
require "native-package-installer/platform"
|
22
|
+
|
23
|
+
class NativePackageInstaller
|
24
|
+
class << self
|
25
|
+
def install(spec)
|
26
|
+
new(spec).install
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(spec)
|
31
|
+
@spec = spec
|
32
|
+
@platform = Platform.detect
|
33
|
+
end
|
34
|
+
|
35
|
+
def install
|
36
|
+
return true if windows?
|
37
|
+
|
38
|
+
package = @platform.package(@spec)
|
39
|
+
return false if package.nil?
|
40
|
+
|
41
|
+
package_name, *options = package
|
42
|
+
package_command_line = [package_name, *options].join(" ")
|
43
|
+
|
44
|
+
install_command = "#{@platform.install_command} #{package_command_line}"
|
45
|
+
if have_priviledge?
|
46
|
+
sudo = nil
|
47
|
+
else
|
48
|
+
sudo = ExecutableFinder.find("sudo")
|
49
|
+
end
|
50
|
+
|
51
|
+
installing_message = "installing '#{package_name}' native package... "
|
52
|
+
log_message("%s", installing_message)
|
53
|
+
failed_to_get_super_user_priviledge = false
|
54
|
+
if have_priviledge?
|
55
|
+
succeeded = run_command(install_command)
|
56
|
+
else
|
57
|
+
if sudo
|
58
|
+
prompt = "[sudo] password for %u to install <#{package_name}>: "
|
59
|
+
sudo_options = "-p #{Shellwords.escape(prompt)}"
|
60
|
+
install_command = "#{sudo} #{sudo_options} #{install_command}"
|
61
|
+
succeeded = run_command(install_command)
|
62
|
+
else
|
63
|
+
succeeded = false
|
64
|
+
failed_to_get_super_user_priviledge = true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
if failed_to_get_super_user_priviledge
|
69
|
+
result_message = "require super user privilege"
|
70
|
+
else
|
71
|
+
result_message = succeeded ? "succeeded" : "failed"
|
72
|
+
end
|
73
|
+
show_postpone_message do
|
74
|
+
"#{installing_message}#{result_message}\n"
|
75
|
+
end
|
76
|
+
log_message("#{result_message}\n")
|
77
|
+
|
78
|
+
error_message = nil
|
79
|
+
unless succeeded
|
80
|
+
if failed_to_get_super_user_priviledge
|
81
|
+
error_message = <<-MESSAGE
|
82
|
+
{package_name}' native package is required.
|
83
|
+
n the following command as super user to install required native package:
|
84
|
+
\# #{install_command}
|
85
|
+
MESSAGE
|
86
|
+
else
|
87
|
+
error_message = <<-MESSAGE
|
88
|
+
iled to run '#{install_command}'.
|
89
|
+
MESSAGE
|
90
|
+
end
|
91
|
+
end
|
92
|
+
if error_message
|
93
|
+
log_message("%s", error_message)
|
94
|
+
show_message("%s", error_message)
|
95
|
+
end
|
96
|
+
|
97
|
+
show_message("--------------------\n\n")
|
98
|
+
|
99
|
+
succeeded
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
def windows?
|
104
|
+
/mswin|mingw|cygwin/ === RUBY_PLATFORM
|
105
|
+
end
|
106
|
+
|
107
|
+
def super_user?
|
108
|
+
Process.uid.zero?
|
109
|
+
end
|
110
|
+
|
111
|
+
def have_priviledge?
|
112
|
+
return true unless @platform.need_super_user_priviledge?
|
113
|
+
super_user?
|
114
|
+
end
|
115
|
+
|
116
|
+
def with_mkmf?
|
117
|
+
Object.const_defined?(:MakeMakefile)
|
118
|
+
end
|
119
|
+
|
120
|
+
def run_command(command_line)
|
121
|
+
if with_mkmf?
|
122
|
+
xsystem(command_line)
|
123
|
+
else
|
124
|
+
system(command_line)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def log_message(format, *args)
|
129
|
+
if with_mkmf?
|
130
|
+
message(format, *args)
|
131
|
+
else
|
132
|
+
printf(format, *args)
|
133
|
+
$stdout.flush
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def show_message(format, *args)
|
138
|
+
if with_mkmf?
|
139
|
+
MakeMakefile::Logging.message(format, *args)
|
140
|
+
else
|
141
|
+
printf(format, *args)
|
142
|
+
$stdout.flush
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def show_postpone_message(&block)
|
147
|
+
if with_mkmf?
|
148
|
+
MakeMakefile::Logging.postpone(&block)
|
149
|
+
else
|
150
|
+
print(yield)
|
151
|
+
$stdout.flush
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Copyright (C) 2013-2017 Ruby-GNOME2 Project Team
|
2
|
+
#
|
3
|
+
# This library is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require "rbconfig"
|
17
|
+
|
18
|
+
class NativePackageInstaller
|
19
|
+
class ExecutableFinder
|
20
|
+
class << self
|
21
|
+
def find(basename)
|
22
|
+
new(basename).find
|
23
|
+
end
|
24
|
+
|
25
|
+
def exist?(basename)
|
26
|
+
new(basename).exist?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(basename)
|
31
|
+
@basename = basename
|
32
|
+
end
|
33
|
+
|
34
|
+
def find
|
35
|
+
extensions = detect_extensions
|
36
|
+
paths.each do |path|
|
37
|
+
executable_file = File.join(path, @basename)
|
38
|
+
return executable_file if executable?(executable_file)
|
39
|
+
extensions.each do |extension|
|
40
|
+
executable_file_with_extension = executable_file + extension
|
41
|
+
if executable?(executable_file_with_extension)
|
42
|
+
return executable_file_with_extension
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def exist?
|
50
|
+
not find.nil?
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def paths
|
55
|
+
path_env = ENV["PATH"]
|
56
|
+
if path_env
|
57
|
+
path_env.split(File::PATH_SEPARATOR)
|
58
|
+
else
|
59
|
+
["/usr/local/bin", "/usr/bin", "/bin"]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def detect_extensions
|
64
|
+
exts = RbConfig::CONFIG["EXECUTABLE_EXTS"]
|
65
|
+
return exts.split if exts
|
66
|
+
ext = RbConfig::CONFIG["EXEEXT"]
|
67
|
+
return [ext] if ext
|
68
|
+
[]
|
69
|
+
end
|
70
|
+
|
71
|
+
def executable?(path)
|
72
|
+
begin
|
73
|
+
stat = File.stat(path)
|
74
|
+
rescue SystemCallError
|
75
|
+
false
|
76
|
+
else
|
77
|
+
stat.file? and stat.executable?
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Copyright (C) 2017 Ruby-GNOME2 Project Team
|
2
|
+
#
|
3
|
+
# This library is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
class NativePackageInstaller
|
17
|
+
module Platform
|
18
|
+
PLATFORM_CLASSES = []
|
19
|
+
|
20
|
+
class << self
|
21
|
+
def register(platform_class)
|
22
|
+
PLATFORM_CLASSES << platform_class
|
23
|
+
end
|
24
|
+
|
25
|
+
def detect
|
26
|
+
platform_class = PLATFORM_CLASSES.find do |platform_class|
|
27
|
+
platform_class.current_platform?
|
28
|
+
end
|
29
|
+
platform_class ||= Unkown
|
30
|
+
platform_class.new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
require "native-package-installer/platform/debian"
|
37
|
+
require "native-package-installer/platform/fedora"
|
38
|
+
require "native-package-installer/platform/redhat"
|
39
|
+
require "native-package-installer/platform/suse"
|
40
|
+
require "native-package-installer/platform/alt-linux"
|
41
|
+
require "native-package-installer/platform/arch-linux"
|
42
|
+
require "native-package-installer/platform/homebrew"
|
43
|
+
require "native-package-installer/platform/macports"
|
44
|
+
require "native-package-installer/platform/unknown"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Copyright (C) 2017 Ruby-GNOME2 Project Team
|
2
|
+
#
|
3
|
+
# This library is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require "native-package-installer/platform/debian"
|
17
|
+
|
18
|
+
class NativePackageInstaller
|
19
|
+
module Platform
|
20
|
+
class ALTLinux < Debian
|
21
|
+
Platform.register(self)
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def current_platform?
|
25
|
+
File.exist?("/etc/altlinux-release")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def package(spec)
|
30
|
+
spec[:alt_linux]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|