┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/settings/services/servicemenudeinstallation
diff options
context:
space:
mode:
Diffstat (limited to 'src/settings/services/servicemenudeinstallation')
-rwxr-xr-xsrc/settings/services/servicemenudeinstallation95
1 files changed, 65 insertions, 30 deletions
diff --git a/src/settings/services/servicemenudeinstallation b/src/settings/services/servicemenudeinstallation
index 5e4234262..9e090e2cd 100755
--- a/src/settings/services/servicemenudeinstallation
+++ b/src/settings/services/servicemenudeinstallation
@@ -1,37 +1,72 @@
#!/usr/bin/env ruby
+
+# Copyright (C) 2009 Jonathan Schmidt-Dominé <[email protected]>
+# Copyright (C) 2019 Harald Sitter <[email protected]>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the
+# Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
require 'fileutils'
-archive = ARGV[0]
-if archive[(archive.length - 8)..(archive.length)] == ".desktop"
- FileUtils.rm(`qtpaths --writable-path GenericDataLocation`.strip! + "/kservices5/ServiceMenus/" + File.basename(archive))
- exit(0)
+
+ARCHIVE = ARGV[0]
+
+# @param log_msg [String] error that gets logged to CLI
+def fail(log_msg: nil)
+ # FIXME: this is not translated...
+ msg = 'Dolphin service menu installation failed'
+ warn log_msg if log_msg
+ system('kdialog', '--passivepopup', msg, '15')
+ abort
end
-dir = archive + "-dir"
-# try: deinstall.sh
-# try: deinstall
-# try: installKDE4.sh
-# try: installKDE4
-# try: install.sh
-# try: install
-while true
- dd = Dir.new(dir)
- break if dd.count != 3
- odir = dir
- for entry in dd
- dir += "/" + entry if entry != "." && entry != ".."
- end
- if !File.directory? dir
- dir = odir
- break
- end
+
+if ARCHIVE.end_with?('.desktop')
+ data_location = `qtpaths --writable-path GenericDataLocation`.strip
+ unless $?.success?
+ fail(log_msg: "Could not get GenericDataLocation #{data_location}")
+ end
+ FileUtils.rm("#{data_location}/kservices5/ServiceMenus/#{File.basename(ARCHIVE)}")
+ exit(0)
end
-Dir.chdir(dir)
-def fail()
- system("kdialog --passivepopup \"Deinstallation failed\" 15")
- exit(-1)
+dir = "#{ARCHIVE}-dir"
+
+deinstaller = nil
+%w[deinstall.sh deinstall].find do |script|
+ deinstaller = Dir.glob("#{dir}/**/#{script}")[0]
end
-if !((File.exist?(file = "./deinstall.sh") || File.exist?(file = "./deinstall")) && system(file))
- fail() if !File.exist?(file = "./installKDE4.sh") && !File.exist?(file = "./installKDE4") && !File.exist?(file = "./install.sh") && !File.exist?(file = "./install")
-File.new(file).chmod(0700)
- fail() if !system(file + " --remove") && !system(file + " --delete") && !system(file + " --uninstall") && !system(file + " --deinstall")
+
+installer = nil
+%w[install-it.sh install-it installKDE4.sh installKDE4 install.sh install].find do |script|
+ installer = Dir.glob("#{dir}/**/#{script}")[0]
+end
+
+Dir.chdir(dir) do
+ deinstalled = false
+
+ [deinstaller, installer].uniq.compact.each { |f| File.chmod(0o700, f) }
+
+ if deinstaller
+ puts "[servicemenudeinstallation]: Trying to run deinstaller #{deinstaller}"
+ deinstalled = system(deinstaller)
+ elsif installer
+ puts "[servicemenudeinstallation]: Trying to run installer #{installer}"
+ %w[--remove --delete --uninstall --deinstall].any? do |arg|
+ deinstalled = system(installer, arg)
+ end
+ end
+
+ fail unless deinstalled
end
+
FileUtils.rm_r(dir)