]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/services/servicemenuinstallation
Remove duplicated entry
[dolphin.git] / src / settings / services / servicemenuinstallation
1 #!/usr/bin/env ruby
2 require 'pathname'
3 require 'fileutils'
4 archive = ARGV[0]
5 $servicedir = `qtpaths --writable-path GenericDataLocation`.strip! + "/kservices5/ServiceMenus/"
6 FileUtils.mkdir_p($servicedir) if !File.exist?($servicedir)
7 if archive[(archive.length - 8)..(archive.length - 1)] == ".desktop"
8 puts "Single-File Service-Menu"
9 puts archive
10 puts $servicedir
11 FileUtils.cp(archive, $servicedir);
12 exit(0)
13 end
14 def mimeType(filename)
15 IO.popen("file --mime-type -b " + filename).gets().strip!()
16 end
17 $archivetypes = { "application/x-tar" => :"tar -xf %s -C %s",
18 "application/tar" => :"tar -xf %s -C %s",
19 "application/x-gzip" => :"tar -zxf %s -C %s",
20 "application/gzip" => :"tar -zxf %s -C %s",
21 "application/x-gzip-compressed-tar" => :"tar -zxf %s -C %s",
22 "application/gzip-compressed-tar" => :"tar -zxf %s -C %s",
23 "application/x-gzip-compressed" => :"tar -zxf %s -C %s",
24 "application/gzip-compressed" => :"tar -zxf %s -C %s",
25 "application/bzip" => :"tar -jxf %s -C %s",
26 "application/bzip2" => :"tar -jxf %s -C %s",
27 "application/x-bzip" => :"tar -jxf %s -C %s",
28 "application/x-bzip2" => :"tar -jxf %s -C %s",
29 "application/bzip-compressed" => :"tar -jxf %s -C %s",
30 "application/bzip2-compressed" => :"tar -jxf %s -C %s",
31 "application/x-bzip-compressed" => :"tar -jxf %s -C %s",
32 "application/x-bzip2-compressed" => :"tar -jxf %s -C %s",
33 "application/bzip-compressed-tar" => :"tar -jxf %s -C %s",
34 "application/bzip2-compressed-tar" => :"tar -jxf %s -C %s",
35 "application/x-bzip-compressed-tar" => :"tar -jxf %s -C %s",
36 "application/x-bzip2-compressed-tar" => :"tar -jxf %s -C %s",
37 "application/zip" => :"unzip %s -d %s",
38 "application/x-zip" => :"unzip %s -d %s",
39 "application/x-zip-compressed" => :"unzip %s -d %s",
40 "multipart/x-zip" => :"unzip %s -d %s",
41 "application/tgz" => :"tar -zxf %s -C %s",
42 "application/x-compressed-gtar" => :"tar -zxf %s -C %s",
43 "file/tgz" => :"tar -zxf %s -C %s",
44 "multipart/x-tar-gz" => :"tar -zxf %s -C %s",
45 "application/x-gunzip" => :"tar -zxf %s -C %s",
46 "application/gzipped" => :"tar -zxf %s -C %s",
47 "gzip/document" => :"tar -zxf %s -C %s",
48 "application/x-bz2 " => :"tar -jxf %s -C %s",
49 "application/x-gtar" => :"tar -xf %s -C %s",
50 "multipart/x-tar" => :"tar -xf %s -C %s"
51 }
52 def uncompress(filename, output)
53 system(sprintf($archivetypes[mimeType(filename)].to_s, filename, output))
54 end
55 dir = archive + "-dir"
56 if File.exist?(dir)
57 FileUtils.rm_r(dir)
58 end
59 FileUtils.mkdir(dir)
60 exit(-1) if !uncompress(archive, dir)
61 # try: install-it.sh
62 # try: install-it
63 # try: installKDE4.sh
64 # try: installKDE4
65 # try: install.sh
66 # try: install
67 while true
68 dd = Dir.new(dir)
69 break if dd.count != 3
70 odir = dir
71 for entry in dd
72 dir += "/" + entry if entry != "." && entry != ".."
73 end
74 if !File.directory? dir
75 dir = odir
76 break
77 end
78 end
79 Dir.chdir(dir)
80 def fail()
81 system("kdialog --passivepopup \"Installation failed\" 15")
82 exit(-1)
83 end
84 if !((File.exist?(file = "./install-it.sh") || File.exist?(file = "./install-it")) && system(file))
85 fail() if !File.exist?(file = "./installKDE4.sh") && !File.exist?(file = "./installKDE4") && !File.exist?(file = "./install.sh") && !File.exist?(file = "./install")
86 File.new(file).chmod(0700)
87 fail() if !system(file + " --local") && !system(file + "--local-install") && !system(file + " --install")
88 end