chiark / gitweb /
added 'mirrors' option to config for giving official mirror URLs
authorHans-Christoph Steiner <hans@eds.org>
Tue, 16 Feb 2016 22:43:23 +0000 (23:43 +0100)
committerHans-Christoph Steiner <hans@eds.org>
Wed, 17 Feb 2016 09:40:07 +0000 (10:40 +0100)
serverwebroot has long supported uploading to multiple servers, this bit of
metadata communicates those official mirrors to the client so that it can
automatically do something useful with that information.

closes #14 https://gitlab.com/fdroid/fdroidserver/issues/14

examples/config.py
fdroidserver/update.py
tests/run-tests

index 339e99609267558fcf7157284772a93f3f49d164..54c326fe584736f3d0731f40dfc49e58222e5aa3 100644 (file)
@@ -149,6 +149,18 @@ The repository of older versions of applications from the main demo repository.
 #     'bar.info:/var/www/fdroid',
 #     }
 
+# Any mirrors of this repo, for example all of the servers declared in
+# serverwebroot, will automatically be used by the client.  If one
+# mirror is not working, then the client will try another.  If the
+# client has Tor enabled, then the client will prefer mirrors with
+# .onion addresses. This base URL will be used for both the main repo
+# and the archive, if it is enabled.  So these URLs should end in the
+# 'fdroid' base of the F-Droid part of the web server like serverwebroot.
+#
+# mirrors = {
+#     'https://foo.bar/fdroid',
+#     'http://foobarfoobarfoobar.onion/fdroid',
+# }
 
 # optionally specific which identity file to use when using rsync over SSH
 #
index 6bbf0fae9686d2f3fd30b719b59e3400a3faaaea..bf264121709826ae01819193432795be3d02aa21 100644 (file)
@@ -27,6 +27,7 @@ import socket
 import zipfile
 import hashlib
 import pickle
+import urlparse
 from datetime import datetime, timedelta
 from xml.dom.minidom import Document
 from argparse import ArgumentParser
@@ -760,6 +761,15 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
 
     repoel = doc.createElement("repo")
 
+    mirrorcheckfailed = False
+    for mirror in config.get('mirrors', []):
+        base = os.path.basename(urlparse.urlparse(mirror).path.rstrip('/'))
+        if config.get('nonstandardwebroot') is not True and base != 'fdroid':
+            logging.error("mirror '" + mirror + "' does not end with 'fdroid'!")
+            mirrorcheckfailed = True
+    if mirrorcheckfailed:
+        sys.exit(1)
+
     if archive:
         repoel.setAttribute("name", config['archive_name'])
         if config['repo_maxage'] != 0:
@@ -767,6 +777,9 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
         repoel.setAttribute("icon", os.path.basename(config['archive_icon']))
         repoel.setAttribute("url", config['archive_url'])
         addElement('description', config['archive_description'], doc, repoel)
+        urlbasepath = os.path.basename(urlparse.urlparse(config['archive_url']).path)
+        for mirror in config.get('mirrors', []):
+            addElement('mirror', urlparse.urljoin(mirror, urlbasepath), doc, repoel)
 
     else:
         repoel.setAttribute("name", config['repo_name'])
@@ -775,8 +788,11 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
         repoel.setAttribute("icon", os.path.basename(config['repo_icon']))
         repoel.setAttribute("url", config['repo_url'])
         addElement('description', config['repo_description'], doc, repoel)
+        urlbasepath = os.path.basename(urlparse.urlparse(config['repo_url']).path)
+        for mirror in config.get('mirrors', []):
+            addElement('mirror', urlparse.urljoin(mirror, urlbasepath), doc, repoel)
 
-    repoel.setAttribute("version", "14")
+    repoel.setAttribute("version", "15")
     repoel.setAttribute("timestamp", str(int(time.time())))
 
     nosigningkey = False
index dfdda5ad01ff39f935c079d40a46a427cd9358bc..de9c9a1532247bf017210027da4075898b75f24b 100755 (executable)
@@ -129,6 +129,7 @@ cd $REPOROOT
 
 $fdroid init
 sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
+echo "mirrors = {'https://foo.bar/fdroid', 'http://secret.onion/fdroid'}" >> config.py
 mkdir metadata
 cp $WORKSPACE/tests/urzip.apk repo/
 cp $WORKSPACE/tests/metadata/info.guardianproject.urzip.txt metadata/