]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/services/servicemenudeinstallation
Merge branch 'Applications/19.04'
[dolphin.git] / src / settings / services / servicemenudeinstallation
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
21 require 'fileutils'
22
23 ARCHIVE = ARGV[0]
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)}")
40 exit(0)
41 end
42 dir = "#{ARCHIVE}-dir"
43
44 deinstaller = nil
45 %w[deinstall.sh deinstall].find do |script|
46 deinstaller = Dir.glob("#{dir}/**/#{script}")[0]
47 end
48
49 installer = nil
50 %w[install-it.sh install-it installKDE4.sh installKDE4 install.sh install].find do |script|
51 installer = Dir.glob("#{dir}/**/#{script}")[0]
52 end
53
54 Dir.chdir(dir) do
55 deinstalled = false
56
57 [deinstaller, installer].uniq.compact.each { |f| File.chmod(0o700, f) }
58
59 if deinstaller
60 puts "[servicemenudeinstallation]: Trying to run deinstaller #{deinstaller}"
61 deinstalled = system(deinstaller)
62 elsif installer
63 puts "[servicemenudeinstallation]: Trying to run installer #{installer}"
64 %w[--remove --delete --uninstall --deinstall].any? do |arg|
65 deinstalled = system(installer, arg)
66 end
67 end
68
69 fail unless deinstalled
70 end
71
72 FileUtils.rm_r(dir)