From 4afe5aefd5c7efc427ee37a78f8618959d4330c3 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 6 Dec 2017 22:32:24 +0100 Subject: [PATCH 1/5] nightly: create app metadata using template of parsed data --- fdroidserver/nightly.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fdroidserver/nightly.py b/fdroidserver/nightly.py index 50c859f4..75c05645 100644 --- a/fdroidserver/nightly.py +++ b/fdroidserver/nightly.py @@ -28,6 +28,7 @@ import shutil import subprocess import sys import tempfile +import yaml from urllib.parse import urlparse from argparse import ArgumentParser @@ -264,6 +265,18 @@ Last updated: {date}'''.format(repo_git_base=repo_git_base, except subprocess.CalledProcessError: pass + app_url = clone_url[:-len(NIGHTLY)] + template = dict() + template['AuthorName'] = clone_url.split('/')[4] + template['AuthorWebSite'] = '/'.join(clone_url.split('/')[:4]) + template['Categories'] = ['nightly'] + template['SourceCode'] = app_url + template['IssueTracker'] = app_url + '/issues' + template['Summary'] = 'Nightly build of ' + urlparse(app_url).path[1:] + template['Description'] = template['Summary'] + with open('template.yml', 'w') as fp: + yaml.dump(template, fp) + subprocess.check_call(['fdroid', 'update', '--rename-apks', '--create-metadata', '--verbose'], cwd=repo_basedir) common.local_rsync(options, repo_basedir + '/metadata/', git_mirror_metadatadir + '/') From 5d54446efcbbb275a5f5bff5faf778f7a84c2528 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 6 Dec 2017 22:33:46 +0100 Subject: [PATCH 2/5] update: do not replace Name/Summary from template unless blank `fdroid nightly` needs this change so it can set the Summary using the template. --- fdroidserver/update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fdroidserver/update.py b/fdroidserver/update.py index 71c4e430..097513bf 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -1670,7 +1670,7 @@ def create_metadata_from_template(apk): with open('template.yml') as f: metatxt = f.read() if 'name' in apk and apk['name'] != '': - metatxt = re.sub(r'^(((Auto)?Name|Summary):).*$', + metatxt = re.sub(r'''^(((Auto)?Name|Summary):)[ '"\.]*$''', r'\1 ' + apk['name'], metatxt, flags=re.IGNORECASE | re.MULTILINE) From c823d4c4a8e7ab6adcca5d5620e4fc6b6061eb59 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 6 Dec 2017 22:42:11 +0100 Subject: [PATCH 3/5] nightly: fix QR icon.png generation --- fdroidserver/nightly.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fdroidserver/nightly.py b/fdroidserver/nightly.py index 75c05645..37d3e8be 100644 --- a/fdroidserver/nightly.py +++ b/fdroidserver/nightly.py @@ -192,9 +192,7 @@ Last updated: {date}'''.format(repo_git_base=repo_git_base, icon_path = os.path.join(git_mirror_path, 'icon.png') try: import qrcode - img = qrcode.make(repo_url) - with open(icon_path, 'wb') as fp: - fp.write(img) + qrcode.make(repo_url).save(icon_path) except Exception: exampleicon = os.path.join(common.get_examples_dir(), 'fdroid-icon.png') shutil.copy(exampleicon, icon_path) From 5d56841f8a73824289ccbefa948d3c906cc44302 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 6 Dec 2017 23:20:00 +0100 Subject: [PATCH 4/5] nightly: prompt user to create a debug.keystore if its not there #423 --- fdroidserver/nightly.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fdroidserver/nightly.py b/fdroidserver/nightly.py index 37d3e8be..d4e4a4e3 100644 --- a/fdroidserver/nightly.py +++ b/fdroidserver/nightly.py @@ -290,6 +290,16 @@ Last updated: {date}'''.format(repo_git_base=repo_git_base, shutil.rmtree(os.path.dirname(ssh_private_key_file)) else: + if not os.path.isfile(KEYSTORE_FILE): + androiddir = os.path.dirname(KEYSTORE_FILE) + if not os.path.exists(androiddir): + os.mkdir(androiddir) + logging.info(_('created {path}').format(path=androiddir)) + logging.error(_('{path} does not exist! Create it by running:').format(path=KEYSTORE_FILE) + + '\n keytool -genkey -v -keystore ' + KEYSTORE_FILE + ' -storepass android \\' + + '\n -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000 \\' + + '\n -dname "CN=Android Debug,O=Android,C=US"') + sys.exit(1) ssh_dir = os.path.join(os.getenv('HOME'), '.ssh') os.makedirs(os.path.dirname(ssh_dir), exist_ok=True) privkey = _ssh_key_from_debug_keystore() From 7b52722d12dce6a23002b1dbb3ee6ed74e766551 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 7 Dec 2017 15:04:39 +0100 Subject: [PATCH 5/5] nightly: replace / from fingerprint in SSH key filename, fixes #423 The SSH key fingerprint is used in the filename. The base64 used for SSH key fingerprints includes /. Not all keys will end up having a / in them. For those that do, this will crash since the ssh key filename ends up being non-existent dirs: $ fdroid nightly Importing keystore /home/mhoffmann/.android/debug.keystore to /tmp/.cqswaeo8/.keystore.p12... MAC verified OK writing RSA key CRITICAL: Unknown exception found! Traceback (most recent call last): File "/usr/lib/python3.6/shutil.py", line 544, in move os.rename(src, real_dst) FileNotFoundError: [Errno 2] No such file or directory: '/tmp/.cqswaeo8/.privkey' -> '/tmp/.cqswaeo8/debug_keystore_PZtS/4Tzk4dpzKiX9AAf1GrhAVi9U7UE1aYEHr6evKo_id_rsa' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/mhoffmann/projects/oss/fdroidserver/fdroid", line 156, in main() File "/home/mhoffmann/projects/oss/fdroidserver/fdroid", line 132, in main mod.main() File "/home/mhoffmann/projects/oss/fdroidserver/fdroidserver/nightly.py", line 284, in main privkey = _ssh_key_from_debug_keystore() File "/home/mhoffmann/projects/oss/fdroidserver/fdroidserver/nightly.py", line 73, in _ssh_key_from_debug_keystore shutil.move(privkey, ssh_private_key_file) File "/usr/lib/python3.6/shutil.py", line 558, in move copy_function(src, real_dst) File "/usr/lib/python3.6/shutil.py", line 257, in copy2 copyfile(src, dst, follow_symlinks=follow_symlinks) File "/usr/lib/python3.6/shutil.py", line 121, in copyfile with open(dst, 'wb') as fdst: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/.cqswaeo8/debug_keystore_PZtS/4Tzk4dpzKiX9AAf1GrhAVi9U7UE1aYEHr6evKo_id_rsa' --- fdroidserver/nightly.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fdroidserver/nightly.py b/fdroidserver/nightly.py index d4e4a4e3..249cd2e4 100644 --- a/fdroidserver/nightly.py +++ b/fdroidserver/nightly.py @@ -70,7 +70,8 @@ def _ssh_key_from_debug_keystore(): rsakey = paramiko.RSAKey.from_private_key_file(privkey) fingerprint = base64.b64encode(hashlib.sha256(rsakey.asbytes()).digest()).decode('ascii').rstrip('=') - ssh_private_key_file = os.path.join(tmp_dir, 'debug_keystore_' + fingerprint + '_id_rsa') + ssh_private_key_file = os.path.join(tmp_dir, 'debug_keystore_' + + fingerprint.replace('/', '_') + '_id_rsa') shutil.move(privkey, ssh_private_key_file) pub = rsakey.get_name() + ' ' + rsakey.get_base64() + ' ' + ssh_private_key_file