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
#!/usr/bin/python3
import sys, requests, tarfile, io
arch="x86_64"

if len(sys.argv) != 2:
	print('Proper usage is "alpine-installer [APK URL | Package Name]"')
	exit()

def download(url):
	print(f'Downloading {url}')
	apk = requests.get(url)
	apk_tar = io.BytesIO(apk.content)
	tar = tarfile.open(fileobj=apk_tar)
	files = []
	print("Which file(s) do you want, seperate indexes by spaces")
	for member in tar.getmembers():
		print(f'[{len(files)}] {member}')
		files.append(member)
	
	get = input("File indexes: ").split()

	for file in get:
		f = open(tar.getnames()[int(file)].split("/")[-1], "wb")
		f.write(tar.extractfile(files[int(file)]).read())
		f.close()
        


arg=sys.argv[1]
if arg.find("http") != -1 and arg.find(":") != -1:
	print(f'Detected {arg} to be a URL, downloading now')
	download(arg)
else:
    search=arg
    print(f'Detected {arg} to be a search term, downloading indexes now')
    indexes_file = open("/etc/apk/repositories", "r")
    indexes = indexes_file.read().split("\n")[:-1] 
    indexes_file.close()
    matches = []
    for index in indexes:
        apks_file = requests.get(f'{index}/{arch}/')
        apks = apks_file.text.split("\n")[5:-3]
        for apk in apks:
            name=apk.split("</a>")[0].split('">')[1]

            if name.find(search) != -1:
                matches.append(f'{index}/{arch}/{name}')
    print("Please type the index of the package you wish to download")
    for i, match in enumerate(matches):
        print(f'[{i}] {match}')
    index = input("Package index: ")
    download(matches[int(index)])