This repository was archived by the owner on Oct 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfdroid_backup_aio.py
158 lines (131 loc) · 4.98 KB
/
fdroid_backup_aio.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
## F-Droid Backup Script, to be used with bash scripts.
## TODO: Find more sane way of detecting if pycurl finished
import pycurl
from xml.dom import minidom
import re
import time
regex_line_start = r"(?:^|\n)\s*"
regex_line_end = r"(?:$)"
repo_url = "https://f-droid.org/repo/"
## Begin Download of F-Droid Repo Files for backup.
with open('index.xml', 'wb') as f:
c = pycurl.Curl()
c.setopt(c.URL, (repo_url + 'index.xml'))
c.setopt(c.WRITEDATA, f)
c.perform()
c.close()
with open('index.jar', 'wb') as f:
c = pycurl.Curl()
c.setopt(c.URL, (repo_url + 'index.jar'))
c.setopt(c.WRITEDATA, f)
c.perform()
c.close()
with open('categories.txt', 'wb') as f:
c = pycurl.Curl()
c.setopt(c.URL, (repo_url + 'categories.txt'))
c.setopt(c.WRITEDATA, f)
c.perform()
c.close()
with open('latestapps.dat', 'wb') as f:
c = pycurl.Curl()
c.setopt(c.URL, (repo_url + 'latestapps.dat'))
c.setopt(c.WRITEDATA, f)
c.perform()
c.close()
time.sleep(120) ## Eventually internet might be fast enough so we don't need to wait 2 mins before continuing. lulz.
## Parse index.xml for APK Names to download and make the download list.
def getAPK(xml):
"""
Print out all apk found in xml
"""
doc = minidom.parse(xml)
node = doc.documentElement
fdroidNode = doc.firstChild
counter = 0
app = fdroidNode.getElementsByTagName("apkname")
hashes = fdroidNode.getElementsByTagName("hash")
hashvalues = []
for thehash in hashes:
hashObj = hashes[counter].firstChild.data.encode('ascii', 'ignore')
counter += 1
hashvalues.append(hashObj)
list(set(hashObj))
counter = 0
apknames = []
for application in app:
apkObj = app[counter].firstChild.data.encode('ascii', 'ignore')
counter += 1
apknames.append(apkObj)
list(set(apknames))
result = [ item for tup in zip(hashvalues,apknames) for item in tup ]
f = open( 'hash.txt', 'w' )
f.write("\t".join(result)) ## Join APK and SHA256 hashes so that we can check for integrity later. (Required for grepping during re-dump/refresh script)
f.close()
f = open( 'download_apk.txt', 'w' )
## Magical Regex to create downloadable url's
add_fdroid_url = [re.sub(regex_line_start, repo_url, string) for string in apknames]
append_asc_extension = [re.sub(regex_line_end, '.asc', string) for string in add_fdroid_url]
##
f.write("\n".join(add_fdroid_url)) ## Convert list to line breaks, prepend the url, and print to file.
f.close()
with open("download_apk.txt", "a") as f:
f.write("\n".join(append_asc_extension)) ## Append .asc signatures to same file.
f.close()
f = open( 'apk.txt', 'w' )
f.write("\n".join(apknames)) ## Print only apk names (Required for grepping during re-dump/refresh script)
f.close()
f = open( 'apk.txt', 'a' )
f.write('\n' + "\n".join([re.sub(regex_line_end, '.asc', string) for string in apknames])) ## Append .asc signatures to same file.
f.close()
def getIcons(xml):
"""
Print out all icons found in xml
"""
doc = minidom.parse(xml)
node = doc.documentElement
fdroidNode = doc.firstChild
counter = 0
icon = fdroidNode.getElementsByTagName("icon")
iconsnames = []
for iconlocation in icon:
iconsObj = icon[counter].firstChild.data.encode('ascii', 'ignore')
counter += 1
iconsnames.append(iconsObj)
list(set(iconsnames))
## Magical Regex to create downloadable url's
add_fdroid_url = [re.sub(regex_line_start, (repo_url + 'icons/'), string) for string in iconsnames]
##
f = open( 'download_icons.txt', 'w' ) ## TIP: change this line to 'with open("download_apk.txt", "a") as f:' if you want all url's in single file.
f.write("\n".join(add_fdroid_url)) ## Convert list to line breaks, prepend the url, and print to file.
f.close()
f = open( 'icons.txt', 'w' )
f.write("\n".join(iconsnames)) ## Print only icon names (Required for grepping during re-dump/refresh script)
f.close()
def getSource(xml):
"""
Print out all source tarballs found in xml
"""
doc = minidom.parse(xml)
node = doc.documentElement
fdroidNode = doc.firstChild
counter = 0
source = fdroidNode.getElementsByTagName("srcname")
sourcenames = []
for sourcelocation in source:
sourceObj = source[counter].firstChild.data.encode('ascii', 'ignore')
counter += 1
sourcenames.append(sourceObj)
list(set(sourcenames))
## Magical Regex to create downloadable url's
add_fdroid_url = [re.sub(regex_line_start, repo_url, string) for string in sourcenames]
f = open( 'download_sources.txt', 'w' )
f.write("\n".join(add_fdroid_url)) ## Convert list to line breaks, prepend the url, and print to file.
f.close()
f = open( 'sources.txt', 'w' )
f.write("\n".join(sourcenames)) ## Print only source tarball names (Required for grepping during re-dump/refresh script)
f.close()
if __name__ == "__main__":
document = 'index.xml'
getAPK(document)
getIcons(document)
getSource(document)