-
Notifications
You must be signed in to change notification settings - Fork 3
/
shashlik-install
executable file
·111 lines (88 loc) · 3.66 KB
/
shashlik-install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python3
import sys
import os
import subprocess
import re
import argparse
import shutil
import zipfile
import tempfile
from constants import SHASHLIK_INSTALL_DIR
parser = argparse.ArgumentParser()
parser.add_argument("apk", help="the APK to install")
args = parser.parse_args()
apk_path = args.apk
def message(msg):
print(msg)
subprocess.call(args=["Xdialog",
"--title", "Shashlik",
"--msgbox", msg, "0", "0"])
sys.exit(msg)
try:
aapt_output = subprocess.check_output(args=["/opt/shashlik/bin/aapt",
"dump",
"badging",
apk_path],
universal_newlines=True)
except:
message("Could not get APK info. Broken setup?")
apk_info = {}
#some lines are formatted as adsf:'awere'
#others are formatted as asdf: foo='awerwe' zzz='asdfwer'
#this script doesn't really work as user-permission comes up mulitple times, but it'll do for the bits we want
for line in aapt_output.split('\n'):
if (not ':' in line):
continue
[key,value] = line.split(':', 1)
apk_info[key] = value
r = re.compile(r"name='([^']*)'")
m = r.search(apk_info["package"])
if not m:
message("Could not extract package name")
package_name = m.group(1)
app_name = apk_info["application-label-uk"].strip("'")
icon_path=""
for size in [640, 480, 320, 240, 213, 160, 120]:
entry = "application-icon-" + str(size)
if entry in apk_info:
icon_path = apk_info[entry].strip("'")
break
if "native-code" in apk_info and not "x86" in apk_info["native-code"]:
#message("This package does not contain x86 native code, and can't run. Please find another APK built for x86")
print("This package does not contain x86 native code, and run with houdini.")
shashlik_dir = os.path.expanduser("~/.local/share/shashlik/")
try:
os.mkdir(shashlik_dir)
except:
pass
#copy APK for pending installation when we first run it
shutil.copyfile(apk_path, shashlik_dir + package_name + ".apk")
#write desktop file into a temp location
#desktop_file = tempfile.NamedTemporaryFile(delete=False, suffix=".desktop", prefix="shashlik-", dir="/tmp")
desktop_file = open(os.path.join("/tmp", "shashlik-" + package_name + ".desktop"), 'wb')
desktop_file.write(b"[Desktop Entry]\n")
desktop_file.write(str.encode("Name=%s\n" % app_name))
desktop_file.write(str.encode("Icon=%s/%s.png\n" % (shashlik_dir, package_name)))
desktop_file.write(str.encode("Exec=/opt/shashlik/bin/shashlik-run %s \"%s\"\n" % (package_name, app_name)))
desktop_file.write(b"Terminal=false\n")
desktop_file.write(b"Type=Application\n")
desktop_file.write(b"Encoding=UTF-8\n")
#os.rename(desktop_file.name, os.path.join("/tmp", "shashlik-" + package_name + ".desktop"))
#extract icon
if icon_path:
apk_zip = zipfile.ZipFile(apk_path)
icon_in = apk_zip.open(icon_path, "r")
icon_out = open(shashlik_dir + package_name + ".png", "wb")
icon_out.write(icon_in.read())
desktop_file.close()
#install desktop icon. xdg-desktop-menu is better than copying the file when dealing with categories
subprocess.call(["xdg-desktop-menu", "install", "/opt/shashlik/data/shashlik-apps.directory", desktop_file.name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
#Debian KDE Workaround for their frameworks "patches"
#See https://git.reviewboard.kde.org/r/127029/
#Remove after KDE Frameworks 5.20
try:
os.symlink(BaseDirectory.xdg_config_home + "/menus/applications-merged", BaseDirectory.xdg_config_home + "/menus/kf5-applications-merged")
except:
pass
os.unlink(desktop_file.name)
message("Successfully installed %s" % app_name)