#!/usr/bin/env ruby # Copyright (C) 2009 Jonathan Schmidt-Dominé # Copyright (C) 2019 Harald Sitter # # 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] # @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 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 = "#{ARCHIVE}-dir" deinstaller = nil %w[deinstall.sh deinstall].find do |script| deinstaller = Dir.glob("#{dir}/**/#{script}")[0] end 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)