-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmkspm
More file actions
executable file
·66 lines (57 loc) · 2.09 KB
/
mkspm
File metadata and controls
executable file
·66 lines (57 loc) · 2.09 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python3
import os
import sys
import subprocess
import hashlib
def calculate_sha256(file_path):
sha256_hash = hashlib.sha256()
with open(file_path, "rb") as file:
for byte_block in iter(lambda: file.read(4096), b""):
sha256_hash.update(byte_block)
return sha256_hash.hexdigest()
def fetch_and_hash(url, output_dir):
temp_file_path = "/tmp/temp"
command = f"curl -o {temp_file_path} {url}"
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.returncode == 0:
sha256_hash = calculate_sha256(temp_file_path)
os.remove(temp_file_path)
return sha256_hash
else:
print(f"Error: Could not fetch URL. Please check if it's valid: {result.returncode}")
sys.exit(1)
def create_spm_file(package_name, package_info):
template_lines = [
"[info]",
f"name = {package_name}",
"version = 0.0.1",
"type = src",
f"url = {package_info['url']}",
f"sha256 = {package_info['sha256']}",
"\n[description]",
f"{package_info.get('description', '')}",
"\n[makedeps]",
*[f"{dep}" for dep in package_info.get('makedeps', [])],
"\n[dependencies]",
*[f"{dep}" for dep in package_info.get('dependencies', [])],
"\n[download]",
f"{package_info.get('download', '')}",
"\n[install]",
*[f"{step}" for step in package_info.get('install', [])]
]
with open(f'{package_name}.ecmp', 'w') as file:
file.write('\n'.join(template_lines))
if __name__ == "__main__":
if len(sys.argv) < 3:
print("Usage: mkspm <package_name> <package_url>")
sys.exit(1)
package_name = sys.argv[1]
package_url = sys.argv[2]
package_info = {
'url': package_url,
'sha256': fetch_and_hash(package_url, "/tmp"),
'download': 'curl -L $URL | tar -xz',
'install': ['./configure', 'make', 'make DESTDIR=$BUILD_ROOT install']
}
create_spm_file(package_name, package_info)
print(f'Successfully created {package_name}.ecmp.')