This repository has been archived by the owner on Jun 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy patharch2appimage.py
249 lines (181 loc) · 6.72 KB
/
arch2appimage.py
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import re
import os
import sys
import time
import glob
import shutil
from config import *
from utils import Utils
if os.path.exists(APP_DIR):
print(f"{APP_DIR}/ already exists. Please remove it then run the script again.")
sys.exit(1)
print("\nConvert any Arch linux package (official/AUR) to AppImage!!")
utils = Utils()
main_pkg = None
while True:
main_pkg = utils.user_text(
"Enter the name of the package (leave empty to quit)")
if not main_pkg:
print("Exiting...")
sys.exit(1)
main_pkg_url = utils.get_pkg(main_pkg)
if main_pkg_url:
break
print("Package not found. Please check the name and try again\n")
print()
os.mkdir(APP_DIR)
utils.download(main_pkg_url, "download", main_pkg)
utils.extract_zst("download", APP_DIR)
utils.rm("download")
desktop_file = glob.glob(os.path.join(
APP_DIR, "usr/share/applications/*.desktop"))
if not desktop_file:
print("No .desktop file was found in the package.")
desktop_file = utils.user_path(
"Please enter the path to a .desktop file", required=True)
elif len(desktop_file) == 1:
desktop_file = desktop_file[0]
else:
desktop_file = utils.user_select(
"Select the .desktop file to be used", desktop_file)
while True:
vfd, msg = utils.validate_desktop_file(desktop_file)
if vfd:
break
print(f"\n.desktop file validation failed due to the error below:\n{msg}")
desktop_file = utils.user_path(
"Please enter the path to a valid .desktop file", required=True)
utils.copy_file(desktop_file, APP_DIR)
with open(desktop_file, "r") as f:
icon_name = re.findall('Icon=(.*)', f.read())
icon_name = icon_name[0] if icon_name else None
icon_file = None
if not icon_name:
print("The .desktop file doesn't have an Icon attribute")
icon_file = utils.user_path(
"Please enter the path to the icon file to be used", required=True)
if icon_file is not None:
icon_name = ".".join(icon_file.split("/")[-1].split(".")[:-1])
utils.set_icon_desktop_file(desktop_file, icon_name)
else:
i_files = os.path.join(APP_DIR, "usr/share/icons/**/*.*")
icon_file = glob.glob(i_files, recursive=True)
if not icon_file:
print(f"No icon file was found in {APP_DIR}/usr/share/icons/")
icon_file = utils.user_path(
"Please enter the path to the icon file to be used", required=True)
elif len(icon_file) == 1:
icon_file = icon_file[0]
else:
icon_file = utils.user_select(
"Please select the icon file to be used", sorted(icon_file))
utils.copy_file(icon_file, APP_DIR)
file_name = icon_file.split("/")[-1]
file_ext = file_name.split(".")[-1]
if file_name != f"{icon_name}.{file_ext}":
os.rename(
os.path.join(APP_DIR, file_name),
os.path.join(APP_DIR, f"{icon_name}.{file_ext}")
)
pkgs = {}
with open(os.path.join(APP_DIR, ".PKGINFO"), "r") as f:
lines = f.read().splitlines()
for line in lines:
line = line.strip()
if line.startswith("depend ="):
pkgs[line.replace("depend =", "").strip()] = None
while True:
not_found = []
for pkg in pkgs:
if pkgs[pkg]:
continue
if url := utils.get_pkg(pkg):
pkgs[pkg] = url
else:
not_found.append(pkg)
print("\nThese packages (and their dependencies) will be downloaded:")
for i, p in enumerate(pkgs):
if pkgs[p]:
print(f"{i+1}. {p}")
if not_found:
print("\nThese packages could not be found: " + " ".join(not_found))
new_pkgs = utils.user_text("If you would like to add additional packages " +
"please enter them below (space seperated). Leave empty to start downloading")
if not new_pkgs.strip():
break
for i in new_pkgs.split(" "):
if i not in pkgs:
pkgs[i] = None
for name, url in pkgs.items():
if url:
utils.download(url, "download", name)
utils.extract_zst("download", APP_DIR)
utils.rm("download")
files_to_delete = [".BUILDINFO", ".MTREE", ".PKGINFO", ".INSTALL"]
for i in files_to_delete:
utils.rm(os.path.join(APP_DIR, i))
utils.copy_file(os.path.join(RES_DIR, "AppRun"), APP_DIR)
utils.make_executable(os.path.join(APP_DIR, "AppRun"))
ldp_file = os.path.join(RES_DIR, "libunionpreload.so")
if utils.user_confirm("Would you like to download the latest \
libunionpreload.so? If you select No the existing one will be used."):
utils.download(LDP_URL, ldp_file, "libunionpreload.so")
utils.copy_file(ldp_file, APP_DIR)
utils.make_executable(os.path.join(APP_DIR, "libunionpreload.so"))
while True:
print("AppDir is ready. Please take a look into the directory to ensure everything is OK.")
print("Exec the AppRun (command './AppRun') to test if everything works.")
yn = utils.user_confirm(
"What would you like to do next?",
"Build the AppImage",
"Add more packages"
)
if yn:
break
pkgs = {}
while True:
new_pkgs = utils.user_text("If you would like to add additional packages " +
"please enter them below (space seperated). Leave empty to start downloading")
if not new_pkgs.strip():
break
for i in new_pkgs.split(" "):
if i not in pkgs:
pkgs[i] = None
not_found = []
for pkg in pkgs:
if pkgs[pkg]:
continue
if url := utils.get_pkg(pkg):
pkgs[pkg] = url
else:
not_found.append(pkg)
print("\nThese packages will be downloaded:")
for i, p in enumerate(pkgs):
if pkgs[p]:
print(f"{i+1}. {p}")
if not_found:
print("\nThese packages could not be found: " + " ".join(not_found))
if pkgs:
for name, url in pkgs.items():
if url:
utils.download(url, "download", name)
utils.extract_zst("download", APP_DIR)
utils.rm("download")
appimagetool = os.path.join(RES_DIR, "appimagetool")
if utils.user_confirm("Would you like to download the \
latest AppImageTool? If you select No the existing one will be used."):
utils.download(APPIMAGETOOL_URL, appimagetool, "AppImageTool")
utils.make_executable(appimagetool)
while True:
print("Running AppImageTool...\n")
if not os.path.exists(OUT_DIR):
os.mkdir(OUT_DIR)
cmd = f"./{appimagetool} -n {APP_DIR} {OUT_DIR}/{main_pkg}-{ARCH}.AppImage"
utils.run_cmd(cmd)
time.sleep(5)
yn = utils.user_confirm("Would you like to re-build it?")
if not yn:
break
if utils.user_confirm(f"Would you like to remove {APP_DIR}/"):
shutil.rmtree(APP_DIR)
print("Exiting...")