]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/services/servicemenuinstallation
make services GHNS work with store.kde.org
[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 "application/x-gtar" => :"tar -zxf %s -C %s",
44 "file/tgz" => :"tar -zxf %s -C %s",
45 "multipart/x-tar-gz" => :"tar -zxf %s -C %s",
46 "application/x-gunzip" => :"tar -zxf %s -C %s",
47 "application/gzipped" => :"tar -zxf %s -C %s",
48 "gzip/document" => :"tar -zxf %s -C %s",
49 "application/x-bz2 " => :"tar -jxf %s -C %s",
50 "application/x-gtar" => :"tar -xf %s -C %s",
51 "multipart/x-tar" => :"tar -xf %s -C %s"
52 }
53 def uncompress(filename, output)
54 system(sprintf($archivetypes[mimeType(filename)].to_s, filename, output))
55 end
56 dir = archive + "-dir"
57 if File.exist?(dir)
58 FileUtils.rm_r(dir)
59 end
60 FileUtils.mkdir(dir)
61 exit(-1) if !uncompress(archive, dir)
62 # try: install-it.sh
63 # try: install-it
64 # try: installKDE4.sh
65 # try: installKDE4
66 # try: install.sh
67 # try: install
68 while true
69 dd = Dir.new(dir)
70 break if dd.count != 3
71 odir = dir
72 for entry in dd
73 dir += "/" + entry if entry != "." && entry != ".."
74 end
75 if !File.directory? dir
76 dir = odir
77 break
78 end
79 end
80 Dir.chdir(dir)
81 def fail()
82 system("kdialog --passivepopup \"Installation failed\" 15")
83 exit(-1)
84 end
85 if !((File.exist?(file = "./install-it.sh") || File.exist?(file = "./install-it")) && system(file))
86 fail() if !File.exist?(file = "./installKDE4.sh") && !File.exist?(file = "./installKDE4") && !File.exist?(file = "./install.sh") && !File.exist?(file = "./install")
87 File.new(file).chmod(0700)
88 fail() if !system(file + " --local") && !system(file + "--local-install") && !system(file + " --install")
89 end