native-package-installer 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
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
+ class ArchLinux
19
+ Platform.register(self)
20
+
21
+ class << self
22
+ def current_platform?
23
+ ExecutableFinder.exist?("pacman")
24
+ end
25
+ end
26
+
27
+ def package(spec)
28
+ spec[:arch_linux]
29
+ end
30
+
31
+ def install_command
32
+ "pacman -S --noconfirm"
33
+ end
34
+
35
+ def need_super_user_priviledge?
36
+ true
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ # Copyright (C) 2013 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
+ class Debian
19
+ Platform.register(self)
20
+
21
+ class << self
22
+ def current_platform?
23
+ File.exist?("/etc/debian_version")
24
+ end
25
+ end
26
+
27
+ def package(spec)
28
+ spec[:debian]
29
+ end
30
+
31
+ def install_command
32
+ "apt install -V -y"
33
+ end
34
+
35
+ def need_super_user_priviledge?
36
+ true
37
+ end
38
+ end
39
+ end
40
+ end
@@ -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/redhat"
17
+
18
+ class NativePackageInstaller
19
+ module Platform
20
+ class Fedora < RedHat
21
+ Platform.register(self)
22
+
23
+ class << self
24
+ def current_platform?
25
+ File.exist?("/etc/fedora-release")
26
+ end
27
+ end
28
+
29
+ def package(spec)
30
+ spec[:fedora] || super
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,40 @@
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
+ class Homebrew
19
+ Platform.register(self)
20
+
21
+ class << self
22
+ def current_platform?
23
+ ExecutableFinder.exist?("brew")
24
+ end
25
+ end
26
+
27
+ def package(spec)
28
+ spec[:homebrew]
29
+ end
30
+
31
+ def install_command
32
+ "brew install"
33
+ end
34
+
35
+ def need_super_user_priviledge?
36
+ false
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
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
+ class MacPorts
19
+ Platform.register(self)
20
+
21
+ class << self
22
+ def current_platform?
23
+ ExecutableFinder.exist?("port")
24
+ end
25
+ end
26
+
27
+ def package(spec)
28
+ spec[:macports]
29
+ end
30
+
31
+ def install_command
32
+ "port install -y"
33
+ end
34
+
35
+ def need_super_user_priviledge?
36
+ true
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,41 @@
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
+ class RedHat
19
+ Platform.register(self)
20
+
21
+ class << self
22
+ def current_platform?
23
+ File.exist?("/etc/redhat-release")
24
+ end
25
+ end
26
+
27
+ def package(spec)
28
+ spec[:redhat]
29
+ end
30
+
31
+
32
+ def install_command
33
+ "yum install -y"
34
+ end
35
+
36
+ def need_super_user_priviledge?
37
+ true
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,40 @@
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
+ class SUSE
19
+ Platform.register(self)
20
+
21
+ class << self
22
+ def current_platform?
23
+ File.exist?("/etc/SuSE-release")
24
+ end
25
+ end
26
+
27
+ def package(spec)
28
+ spec[:suse] || spec[:fedora] || spec[:redhat]
29
+ end
30
+
31
+ def install_command
32
+ "zypper --non-interactive install"
33
+ end
34
+
35
+ def need_super_user_priviledge?
36
+ true
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,28 @@
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
+ class Unknown
19
+ def package(spec)
20
+ nil
21
+ end
22
+
23
+ def need_super_user_priviledge?
24
+ false
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
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
+ class NativePackageInstaller
17
+ VERSION = "1.0.0"
18
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2013 Ruby-GNOME2 Project Team
4
+ #
5
+ # This library is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ $VERBOSE = true
19
+
20
+ require "test-unit"
21
+ require "test/unit/rr"
22
+
23
+ exit(Test::Unit::AutoRunner.run(true))
@@ -0,0 +1,90 @@
1
+ # Copyright (C) 2013 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 "fileutils"
17
+
18
+ require "native-package-installer/executable-finder"
19
+
20
+ class ExecutableFinderTest < Test::Unit::TestCase
21
+ def setup
22
+ @original_path = ENV["PATH"]
23
+ setup_base_dir
24
+ setup_path
25
+ end
26
+
27
+ def setup_base_dir
28
+ @base_dir = File.join(File.dirname(__FILE__), "tmp")
29
+ FileUtils.rm_rf(@base_dir)
30
+ FileUtils.mkdir_p(@base_dir)
31
+ end
32
+
33
+ def teardown_base_dir
34
+ FileUtils.rm_rf(@base_dir)
35
+ end
36
+
37
+ def setup_path
38
+ paths = [
39
+ File.join(@base_dir, "nonexistent"),
40
+ File.join(@base_dir, "bin"),
41
+ File.join(@base_dir, "sbin"),
42
+ ]
43
+ ENV["PATH"] = paths.join(File::PATH_SEPARATOR)
44
+ end
45
+
46
+ def teardown
47
+ teardown_base_dir
48
+ ENV["PATH"] = @original_path
49
+ end
50
+
51
+ private
52
+ def create_finder(basename)
53
+ NativePackageInstaller::ExecutableFinder.new(basename)
54
+ end
55
+
56
+ class TestFind < self
57
+ def test_found
58
+ finder = create_finder("ls")
59
+ ls = File.join(@base_dir, "bin", "ls")
60
+ stub(File).stat(ls) do
61
+ stat = stub(Object.new)
62
+ stat.file? {true}
63
+ stat.executable? {true}
64
+ stat
65
+ end
66
+ stub(File).stat.with_any_args do
67
+ raise Errno::ENOENT
68
+ end
69
+ assert_equal(ls, finder.find)
70
+ end
71
+ end
72
+
73
+ class TestExist < self
74
+ def test_true
75
+ finder = create_finder("ls")
76
+ stub(finder).find do
77
+ File.join(@base_dir, "bin", "ls")
78
+ end
79
+ assert_true(finder.exist?)
80
+ end
81
+
82
+ def test_false
83
+ finder = create_finder("ls")
84
+ stub(finder).find do
85
+ nil
86
+ end
87
+ assert_false(finder.exist?)
88
+ end
89
+ end
90
+ end