forked from AppImage/appimage.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.py
More file actions
49 lines (37 loc) · 1.38 KB
/
Copy pathworker.py
File metadata and controls
49 lines (37 loc) · 1.38 KB
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
#!/usr/bin/env python3
import os, sys
import requests # It is an extra dependency but it allows us to download only the portion of the file that is needed to check the magic
def main() -> None:
# Get the URL to the AppImage
f = open(sys.argv[1], "r")
url = f.readline()
f.close()
print(url)
if not url.startswith("http"):
print("%s seems not to contain a URL, exiting" % (sys.argv[1]))
exit(1)
req = requests.get(url, stream=True)
print("Status %s" % (r.status_code))
req.raise_for_status()
print(r.headers['Content-Type'])
# Check the file type. Since we are using requests with "stream=True", not the whole file will be downloaded for this
header = req.raw.read(8+3)
tag = header[8:8+3]
if tag == b'AI\x01':
print("Found valid type-1 AppImage signature")
elif tag == b'AI\x02':
print("Found valid type-2 AppImage signature")
else:
raise SystemExit(
"cannot process {!a}: AppImage signature not found".format(
url))
# If 0x414902 then extract desktop file like so:
# export TARGET_APPIMAGE = filename
# ./runtime --appimage-extract '*.desktop'
# ...
# If 0x414901 then loop-mount with fuseiso
# ...
# Run some checks
# Export data from the desktop file to "database file"
if __name__ == "__main__":
main()