Changeset View
Changeset View
Standalone View
Standalone View
src/settings/services/servicemenudeinstallation
1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby | ||
---|---|---|---|---|---|
2 | | ||||
3 | # Copyright (C) 2009 Jonathan Schmidt-Dominé <devel@the-user.org> | ||||
4 | # Copyright (C) 2019 Harald Sitter <sitter@kde.org> | ||||
5 | # | ||||
6 | # This program is free software; you can redistribute it and/or modify | ||||
7 | # it under the terms of the GNU General Public License as published by | ||||
8 | # the Free Software Foundation; either version 2 of the License, or | ||||
9 | # (at your option) any later version. | ||||
10 | # | ||||
11 | # This program is distributed in the hope that it will be useful, | ||||
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
14 | # GNU General Public License for more details. | ||||
15 | # | ||||
16 | # You should have received a copy of the GNU General Public License | ||||
17 | # along with this program; if not, write to the | ||||
18 | # Free Software Foundation, Inc., | ||||
19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||
20 | | ||||
2 | require 'fileutils' | 21 | require 'fileutils' | ||
3 | archive = ARGV[0] | 22 | | ||
4 | if archive[(archive.length - 8)..(archive.length)] == ".desktop" | 23 | ARCHIVE = ARGV[0] | ||
5 | FileUtils.rm(`qtpaths --writable-path GenericDataLocation`.strip! + "/kservices5/ServiceMenus/" + File.basename(archive)) | 24 | | ||
25 | # @param log_msg [String] error that gets logged to CLI | ||||
26 | def fail(log_msg: nil) | ||||
27 | # FIXME: this is not translated... | ||||
28 | msg = 'Dolphin service menu installation failed' | ||||
29 | warn log_msg if log_msg | ||||
30 | system('kdialog', '--passivepopup', msg, '15') | ||||
31 | abort | ||||
32 | end | ||||
33 | | ||||
34 | if ARCHIVE.end_with?('.desktop') | ||||
35 | data_location = `qtpaths --writable-path GenericDataLocation`.strip | ||||
36 | unless $?.success? | ||||
37 | fail(log_msg: "Could not get GenericDataLocation #{data_location}") | ||||
38 | end | ||||
39 | FileUtils.rm("#{data_location}/kservices5/ServiceMenus/#{File.basename(ARCHIVE)}") | ||||
6 | exit(0) | 40 | exit(0) | ||
7 | end | 41 | end | ||
8 | dir = archive + "-dir" | 42 | dir = "#{ARCHIVE}-dir" | ||
9 | # try: deinstall.sh | 43 | | ||
10 | # try: deinstall | 44 | deinstaller = nil | ||
11 | # try: installKDE4.sh | 45 | %w[deinstall.sh deinstall].find do |script| | ||
12 | # try: installKDE4 | 46 | deinstaller = Dir.glob("#{dir}/**/#{script}")[0] | ||
13 | # try: install.sh | 47 | end | ||
14 | # try: install | 48 | | ||
15 | while true | 49 | installer = nil | ||
16 | dd = Dir.new(dir) | 50 | %w[install-it.sh install-it installKDE4.sh installKDE4 install.sh install].find do |script| | ||
17 | break if dd.count != 3 | 51 | installer = Dir.glob("#{dir}/**/#{script}")[0] | ||
18 | odir = dir | 52 | end | ||
19 | for entry in dd | 53 | | ||
20 | dir += "/" + entry if entry != "." && entry != ".." | 54 | Dir.chdir(dir) do | ||
21 | end | 55 | deinstalled = false | ||
22 | if !File.directory? dir | 56 | | ||
23 | dir = odir | 57 | [deinstaller, installer].uniq.compact.each { |f| File.chmod(0o700, f) } | ||
24 | break | 58 | | ||
25 | end | 59 | if deinstaller | ||
26 | end | 60 | puts "[servicemenudeinstallation]: Trying to run deinstaller #{deinstaller}" | ||
27 | Dir.chdir(dir) | 61 | deinstalled = system(deinstaller) | ||
28 | def fail() | 62 | elsif installer | ||
29 | system("kdialog --passivepopup \"Deinstallation failed\" 15") | 63 | puts "[servicemenudeinstallation]: Trying to run installer #{installer}" | ||
30 | exit(-1) | 64 | %w[--remove --delete --uninstall --deinstall].any? do |arg| | ||
31 | end | 65 | deinstalled = system(installer, arg) | ||
32 | if !((File.exist?(file = "./deinstall.sh") || File.exist?(file = "./deinstall")) && system(file)) | 66 | end | ||
33 | fail() if !File.exist?(file = "./installKDE4.sh") && !File.exist?(file = "./installKDE4") && !File.exist?(file = "./install.sh") && !File.exist?(file = "./install") | 67 | end | ||
34 | File.new(file).chmod(0700) | 68 | | ||
35 | fail() if !system(file + " --remove") && !system(file + " --delete") && !system(file + " --uninstall") && !system(file + " --deinstall") | 69 | fail unless deinstalled | ||
36 | end | 70 | end | ||
71 | | ||||
37 | FileUtils.rm_r(dir) | 72 | FileUtils.rm_r(dir) |