2016-01-04 16:33:20 +01:00
|
|
|
#!/usr/bin/env python3
|
2010-10-22 00:26:38 +02:00
|
|
|
#
|
|
|
|
# update.py - part of the FDroid server tools
|
2016-08-16 21:02:15 +02:00
|
|
|
# Copyright (C) 2016, Blue Jay Wireless
|
|
|
|
# Copyright (C) 2014-2016, Hans-Christoph Steiner <hans@eds.org>
|
|
|
|
# Copyright (C) 2010-2015, Ciaran Gultnieks <ciaran@ciarang.com>
|
|
|
|
# Copyright (C) 2013-2014, Daniel Martí <mvdan@mvdan.cc>
|
2010-10-22 00:26:38 +02:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-11-28 21:09:07 +01:00
|
|
|
import copy
|
2010-10-22 00:26:38 +02:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import glob
|
2016-12-16 12:19:07 +01:00
|
|
|
import json
|
2010-10-22 00:26:38 +02:00
|
|
|
import re
|
2015-04-21 03:38:52 +02:00
|
|
|
import socket
|
2010-10-22 00:26:38 +02:00
|
|
|
import zipfile
|
2011-03-17 00:27:42 +01:00
|
|
|
import hashlib
|
2012-09-03 12:48:18 +02:00
|
|
|
import pickle
|
2017-03-16 17:45:10 +01:00
|
|
|
import platform
|
2016-01-04 18:02:36 +01:00
|
|
|
import urllib.parse
|
2015-07-21 01:42:40 +02:00
|
|
|
from datetime import datetime, timedelta
|
2010-10-22 00:26:38 +02:00
|
|
|
from xml.dom.minidom import Document
|
2015-09-04 11:37:05 +02:00
|
|
|
from argparse import ArgumentParser
|
2016-07-30 23:12:52 +02:00
|
|
|
|
|
|
|
import collections
|
2014-08-30 04:53:55 +02:00
|
|
|
from pyasn1.error import PyAsn1Error
|
|
|
|
from pyasn1.codec.der import decoder, encoder
|
|
|
|
from pyasn1_modules import rfc2315
|
2015-01-10 16:44:16 +01:00
|
|
|
from binascii import hexlify, unhexlify
|
2014-08-30 04:53:55 +02:00
|
|
|
|
2013-08-19 11:20:50 +02:00
|
|
|
from PIL import Image
|
2014-01-27 16:56:55 +01:00
|
|
|
import logging
|
2012-08-22 18:24:33 +02:00
|
|
|
|
2016-01-04 17:37:35 +01:00
|
|
|
from . import common
|
|
|
|
from . import metadata
|
2016-01-04 19:02:21 +01:00
|
|
|
from .common import FDroidPopen, FDroidPopenBytes, SdkToolsPopen
|
2016-01-04 17:37:35 +01:00
|
|
|
from .metadata import MetaDataException
|
2014-01-07 11:16:58 +01:00
|
|
|
|
2017-03-10 17:40:19 +01:00
|
|
|
METADATA_VERSION = 18
|
2016-06-15 16:34:10 +02:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
APK_NAME_PAT = re.compile(".*name='([a-zA-Z0-9._]*)'.*")
|
|
|
|
APK_VERCODE_PAT = re.compile(".*versionCode='([0-9]*)'.*")
|
|
|
|
APK_VERNAME_PAT = re.compile(".*versionName='([^']*)'.*")
|
|
|
|
APK_LABEL_PAT = re.compile(".*label='(.*?)'(\n| [a-z]*?=).*")
|
|
|
|
APK_ICON_PAT = re.compile(".*application-icon-([0-9]+):'([^']+?)'.*")
|
|
|
|
APK_ICON_PAT_NODPI = re.compile(".*icon='([^']+?)'.*")
|
|
|
|
APK_SDK_VERSION_PAT = re.compile(".*'([0-9]*)'.*")
|
|
|
|
APK_PERMISSION_PAT = \
|
|
|
|
re.compile(".*(name='(?P<name>.*?)')(.*maxSdkVersion='(?P<maxSdkVersion>.*?)')?.*")
|
|
|
|
APK_FEATURE_PAT = re.compile(".*name='([^']*)'.*")
|
|
|
|
|
2015-10-24 16:34:55 +02:00
|
|
|
screen_densities = ['640', '480', '320', '240', '160', '120']
|
2014-01-07 11:16:58 +01:00
|
|
|
|
2015-11-27 00:13:30 +01:00
|
|
|
all_screen_densities = ['0'] + screen_densities
|
|
|
|
|
2016-07-30 23:12:52 +02:00
|
|
|
UsesPermission = collections.namedtuple('UsesPermission', ['name', 'maxSdkVersion'])
|
|
|
|
UsesPermissionSdk23 = collections.namedtuple('UsesPermissionSdk23', ['name', 'maxSdkVersion'])
|
|
|
|
|
2014-05-02 05:39:33 +02:00
|
|
|
|
2014-01-07 17:01:51 +01:00
|
|
|
def dpi_to_px(density):
|
2014-01-07 12:06:39 +01:00
|
|
|
return (int(density) * 48) / 160
|
2014-01-07 11:16:58 +01:00
|
|
|
|
2014-05-02 05:39:33 +02:00
|
|
|
|
2014-01-07 17:01:51 +01:00
|
|
|
def px_to_dpi(px):
|
|
|
|
return (int(px) * 160) / 48
|
|
|
|
|
2014-05-02 05:39:33 +02:00
|
|
|
|
2014-01-07 12:06:39 +01:00
|
|
|
def get_icon_dir(repodir, density):
|
2015-11-27 00:13:30 +01:00
|
|
|
if density == '0':
|
2014-01-07 12:06:39 +01:00
|
|
|
return os.path.join(repodir, "icons")
|
2014-01-07 11:16:58 +01:00
|
|
|
return os.path.join(repodir, "icons-%s" % density)
|
|
|
|
|
2014-05-02 05:39:33 +02:00
|
|
|
|
2014-01-07 11:16:58 +01:00
|
|
|
def get_icon_dirs(repodir):
|
2015-10-24 16:34:55 +02:00
|
|
|
for density in screen_densities:
|
2014-01-07 12:06:39 +01:00
|
|
|
yield get_icon_dir(repodir, density)
|
2015-11-27 00:13:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_all_icon_dirs(repodir):
|
|
|
|
for density in all_screen_densities:
|
|
|
|
yield get_icon_dir(repodir, density)
|
2014-01-07 11:16:58 +01:00
|
|
|
|
2014-05-02 05:39:33 +02:00
|
|
|
|
2014-08-16 12:46:02 +02:00
|
|
|
def update_wiki(apps, sortedids, apks):
|
2013-05-10 16:04:59 +02:00
|
|
|
"""Update the wiki
|
2012-08-22 18:24:33 +02:00
|
|
|
|
2013-05-10 16:04:59 +02:00
|
|
|
:param apps: fully populated list of all applications
|
|
|
|
:param apks: all apks, except...
|
|
|
|
"""
|
2014-01-27 16:56:55 +01:00
|
|
|
logging.info("Updating wiki")
|
2012-08-22 18:24:33 +02:00
|
|
|
wikicat = 'Apps'
|
2013-10-09 15:39:00 +02:00
|
|
|
wikiredircat = 'App Redirects'
|
2012-08-22 18:24:33 +02:00
|
|
|
import mwclient
|
2013-10-31 16:37:39 +01:00
|
|
|
site = mwclient.Site((config['wiki_protocol'], config['wiki_server']),
|
2014-05-06 19:50:52 +02:00
|
|
|
path=config['wiki_path'])
|
2013-10-31 16:37:39 +01:00
|
|
|
site.login(config['wiki_user'], config['wiki_password'])
|
2012-08-22 18:24:33 +02:00
|
|
|
generated_pages = {}
|
2013-10-09 15:39:00 +02:00
|
|
|
generated_redirects = {}
|
2014-08-16 12:46:02 +02:00
|
|
|
|
|
|
|
for appid in sortedids:
|
2016-11-23 17:25:59 +01:00
|
|
|
app = metadata.App(apps[appid])
|
2014-08-16 12:46:02 +02:00
|
|
|
|
2012-08-22 18:24:33 +02:00
|
|
|
wikidata = ''
|
2015-11-28 13:09:47 +01:00
|
|
|
if app.Disabled:
|
|
|
|
wikidata += '{{Disabled|' + app.Disabled + '}}\n'
|
|
|
|
if app.AntiFeatures:
|
|
|
|
for af in app.AntiFeatures:
|
2013-11-17 13:16:24 +01:00
|
|
|
wikidata += '{{AntiFeature|' + af + '}}\n'
|
2015-11-28 13:09:47 +01:00
|
|
|
if app.RequiresRoot:
|
2015-07-24 01:33:08 +02:00
|
|
|
requiresroot = 'Yes'
|
|
|
|
else:
|
|
|
|
requiresroot = 'No'
|
2016-01-03 20:49:36 +01:00
|
|
|
wikidata += '{{App|id=%s|name=%s|added=%s|lastupdated=%s|source=%s|tracker=%s|web=%s|changelog=%s|donate=%s|flattr=%s|bitcoin=%s|litecoin=%s|license=%s|root=%s|author=%s|email=%s}}\n' % (
|
2014-08-16 12:46:02 +02:00
|
|
|
appid,
|
2015-11-28 13:09:47 +01:00
|
|
|
app.Name,
|
2016-11-28 21:10:58 +01:00
|
|
|
app.added.strftime('%Y-%m-%d') if app.added else '',
|
|
|
|
app.lastUpdated.strftime('%Y-%m-%d') if app.lastUpdated else '',
|
2015-11-28 13:09:47 +01:00
|
|
|
app.SourceCode,
|
|
|
|
app.IssueTracker,
|
|
|
|
app.WebSite,
|
|
|
|
app.Changelog,
|
|
|
|
app.Donate,
|
|
|
|
app.FlattrID,
|
|
|
|
app.Bitcoin,
|
|
|
|
app.Litecoin,
|
|
|
|
app.License,
|
2016-01-03 20:49:36 +01:00
|
|
|
requiresroot,
|
|
|
|
app.AuthorName,
|
|
|
|
app.AuthorEmail)
|
2012-08-26 12:58:18 +02:00
|
|
|
|
2015-11-28 13:09:47 +01:00
|
|
|
if app.Provides:
|
|
|
|
wikidata += "This app provides: %s" % ', '.join(app.Summary.split(','))
|
2013-12-31 10:47:50 +01:00
|
|
|
|
2015-11-28 13:09:47 +01:00
|
|
|
wikidata += app.Summary
|
2014-08-16 12:46:02 +02:00
|
|
|
wikidata += " - [https://f-droid.org/repository/browse/?fdid=" + appid + " view in repository]\n\n"
|
2012-08-26 12:58:18 +02:00
|
|
|
|
2012-08-22 18:24:33 +02:00
|
|
|
wikidata += "=Description=\n"
|
2015-11-28 13:09:47 +01:00
|
|
|
wikidata += metadata.description_wiki(app.Description) + "\n"
|
2012-08-22 18:24:33 +02:00
|
|
|
|
2013-11-15 11:00:04 +01:00
|
|
|
wikidata += "=Maintainer Notes=\n"
|
2015-11-28 13:09:47 +01:00
|
|
|
if app.MaintainerNotes:
|
|
|
|
wikidata += metadata.description_wiki(app.MaintainerNotes) + "\n"
|
2014-08-16 12:46:02 +02:00
|
|
|
wikidata += "\nMetadata: [https://gitlab.com/fdroid/fdroiddata/blob/master/metadata/{0}.txt current] [https://gitlab.com/fdroid/fdroiddata/commits/master/metadata/{0}.txt history]\n".format(appid)
|
2013-11-05 17:39:45 +01:00
|
|
|
|
2012-08-26 12:58:18 +02:00
|
|
|
# Get a list of all packages for this application...
|
2012-08-22 18:24:33 +02:00
|
|
|
apklist = []
|
|
|
|
gotcurrentver = False
|
2012-08-26 12:58:18 +02:00
|
|
|
cantupdate = False
|
2013-10-09 10:57:00 +02:00
|
|
|
buildfails = False
|
2012-08-22 18:24:33 +02:00
|
|
|
for apk in apks:
|
2016-11-29 13:40:21 +01:00
|
|
|
if apk['packageName'] == appid:
|
|
|
|
if str(apk['versionCode']) == app.CurrentVersionCode:
|
2012-08-22 18:24:33 +02:00
|
|
|
gotcurrentver = True
|
|
|
|
apklist.append(apk)
|
2012-08-26 12:58:18 +02:00
|
|
|
# Include ones we can't build, as a special case...
|
2015-11-28 17:55:27 +01:00
|
|
|
for build in app.builds:
|
|
|
|
if build.disable:
|
2016-11-23 17:52:04 +01:00
|
|
|
if build.versionCode == app.CurrentVersionCode:
|
2012-08-26 12:58:18 +02:00
|
|
|
cantupdate = True
|
2014-05-28 09:33:14 +02:00
|
|
|
# TODO: Nasty: vercode is a string in the build, and an int elsewhere
|
2016-11-29 13:40:21 +01:00
|
|
|
apklist.append({'versionCode': int(build.versionCode),
|
|
|
|
'versionName': build.versionName,
|
2015-11-28 17:55:27 +01:00
|
|
|
'buildproblem': "The build for this version was manually disabled. Reason: {0}".format(build.disable),
|
2014-05-06 19:50:52 +02:00
|
|
|
})
|
2013-10-09 10:48:06 +02:00
|
|
|
else:
|
|
|
|
builtit = False
|
|
|
|
for apk in apklist:
|
2016-11-29 13:40:21 +01:00
|
|
|
if apk['versionCode'] == int(build.versionCode):
|
2013-10-09 10:48:06 +02:00
|
|
|
builtit = True
|
|
|
|
break
|
|
|
|
if not builtit:
|
2013-10-09 10:57:00 +02:00
|
|
|
buildfails = True
|
2016-11-29 13:40:21 +01:00
|
|
|
apklist.append({'versionCode': int(build.versionCode),
|
|
|
|
'versionName': build.versionName,
|
2016-11-23 17:52:04 +01:00
|
|
|
'buildproblem': "The build for this version appears to have failed. Check the [[{0}/lastbuild_{1}|build log]].".format(appid, build.versionCode),
|
2014-05-06 19:50:52 +02:00
|
|
|
})
|
2015-11-28 13:09:47 +01:00
|
|
|
if app.CurrentVersionCode == '0':
|
2014-02-17 16:51:22 +01:00
|
|
|
cantupdate = True
|
2012-08-26 12:58:18 +02:00
|
|
|
# Sort with most recent first...
|
2016-11-29 13:40:21 +01:00
|
|
|
apklist = sorted(apklist, key=lambda apk: apk['versionCode'], reverse=True)
|
2012-08-26 12:58:18 +02:00
|
|
|
|
2012-08-22 18:24:33 +02:00
|
|
|
wikidata += "=Versions=\n"
|
|
|
|
if len(apklist) == 0:
|
2012-08-31 15:50:45 +02:00
|
|
|
wikidata += "We currently have no versions of this app available."
|
2012-08-22 18:24:33 +02:00
|
|
|
elif not gotcurrentver:
|
2012-08-31 15:50:45 +02:00
|
|
|
wikidata += "We don't have the current version of this app."
|
2012-09-15 00:15:28 +02:00
|
|
|
else:
|
|
|
|
wikidata += "We have the current version of this app."
|
2015-11-28 13:09:47 +01:00
|
|
|
wikidata += " (Check mode: " + app.UpdateCheckMode + ") "
|
|
|
|
wikidata += " (Auto-update mode: " + app.AutoUpdateMode + ")\n\n"
|
|
|
|
if len(app.NoSourceSince) > 0:
|
|
|
|
wikidata += "This application has partially or entirely been missing source code since version " + app.NoSourceSince + ".\n\n"
|
|
|
|
if len(app.CurrentVersion) > 0:
|
|
|
|
wikidata += "The current (recommended) version is " + app.CurrentVersion
|
|
|
|
wikidata += " (version code " + app.CurrentVersionCode + ").\n\n"
|
2012-09-21 17:07:18 +02:00
|
|
|
validapks = 0
|
2012-08-22 18:24:33 +02:00
|
|
|
for apk in apklist:
|
2016-11-29 13:40:21 +01:00
|
|
|
wikidata += "==" + apk['versionName'] + "==\n"
|
2012-08-26 12:58:18 +02:00
|
|
|
|
|
|
|
if 'buildproblem' in apk:
|
|
|
|
wikidata += "We can't build this version: " + apk['buildproblem'] + "\n\n"
|
|
|
|
else:
|
2012-09-21 17:07:18 +02:00
|
|
|
validapks += 1
|
2012-08-26 12:58:18 +02:00
|
|
|
wikidata += "This version is built and signed by "
|
2013-03-13 17:56:17 +01:00
|
|
|
if 'srcname' in apk:
|
2012-08-26 12:58:18 +02:00
|
|
|
wikidata += "F-Droid, and guaranteed to correspond to the source tarball published with it.\n\n"
|
|
|
|
else:
|
|
|
|
wikidata += "the original developer.\n\n"
|
2016-11-29 13:40:21 +01:00
|
|
|
wikidata += "Version code: " + str(apk['versionCode']) + '\n'
|
2012-08-22 18:24:33 +02:00
|
|
|
|
|
|
|
wikidata += '\n[[Category:' + wikicat + ']]\n'
|
2015-11-28 13:09:47 +01:00
|
|
|
if len(app.NoSourceSince) > 0:
|
2013-05-19 14:54:58 +02:00
|
|
|
wikidata += '\n[[Category:Apps missing source code]]\n'
|
2015-11-28 13:09:47 +01:00
|
|
|
if validapks == 0 and not app.Disabled:
|
2012-08-22 18:24:33 +02:00
|
|
|
wikidata += '\n[[Category:Apps with no packages]]\n'
|
2015-11-28 13:09:47 +01:00
|
|
|
if cantupdate and not app.Disabled:
|
2016-02-17 15:37:46 +01:00
|
|
|
wikidata += "\n[[Category:Apps we cannot update]]\n"
|
2015-11-28 13:09:47 +01:00
|
|
|
if buildfails and not app.Disabled:
|
2013-10-09 10:57:00 +02:00
|
|
|
wikidata += "\n[[Category:Apps with failing builds]]\n"
|
2015-11-28 13:09:47 +01:00
|
|
|
elif not gotcurrentver and not cantupdate and not app.Disabled and app.UpdateCheckMode != "Static":
|
2012-08-22 18:24:33 +02:00
|
|
|
wikidata += '\n[[Category:Apps to Update]]\n'
|
2015-11-28 13:09:47 +01:00
|
|
|
if app.Disabled:
|
2013-10-23 14:19:33 +02:00
|
|
|
wikidata += '\n[[Category:Apps that are disabled]]\n'
|
2015-11-28 13:09:47 +01:00
|
|
|
if app.UpdateCheckMode == 'None' and not app.Disabled:
|
2012-08-31 15:50:45 +02:00
|
|
|
wikidata += '\n[[Category:Apps with no update check]]\n'
|
2015-11-28 13:09:47 +01:00
|
|
|
for appcat in app.Categories:
|
2014-01-07 14:39:48 +01:00
|
|
|
wikidata += '\n[[Category:{0}]]\n'.format(appcat)
|
2012-08-26 12:58:18 +02:00
|
|
|
|
|
|
|
# We can't have underscores in the page name, even if they're in
|
|
|
|
# the package ID, because MediaWiki messes with them...
|
2014-08-16 12:46:02 +02:00
|
|
|
pagename = appid.replace('_', ' ')
|
2013-04-23 14:28:43 +02:00
|
|
|
|
|
|
|
# Drop a trailing newline, because mediawiki is going to drop it anyway
|
|
|
|
# and it we don't we'll think the page has changed when it hasn't...
|
|
|
|
if wikidata.endswith('\n'):
|
|
|
|
wikidata = wikidata[:-1]
|
|
|
|
|
2012-08-26 12:58:18 +02:00
|
|
|
generated_pages[pagename] = wikidata
|
2012-08-22 18:24:33 +02:00
|
|
|
|
|
|
|
# Make a redirect from the name to the ID too, unless there's
|
|
|
|
# already an existing page with the name and it isn't a redirect.
|
|
|
|
noclobber = False
|
2015-11-28 13:09:47 +01:00
|
|
|
apppagename = app.Name.replace('_', ' ')
|
2013-06-15 23:02:59 +02:00
|
|
|
apppagename = apppagename.replace('{', '')
|
|
|
|
apppagename = apppagename.replace('}', ' ')
|
2013-09-05 11:32:33 +02:00
|
|
|
apppagename = apppagename.replace(':', ' ')
|
2016-08-01 13:25:22 +02:00
|
|
|
apppagename = apppagename.replace('[', ' ')
|
|
|
|
apppagename = apppagename.replace(']', ' ')
|
2013-10-09 14:23:17 +02:00
|
|
|
# Drop double spaces caused mostly by replacing ':' above
|
|
|
|
apppagename = apppagename.replace(' ', ' ')
|
|
|
|
for expagename in site.allpages(prefix=apppagename,
|
2014-05-06 19:50:52 +02:00
|
|
|
filterredir='nonredirects',
|
|
|
|
generator=False):
|
2013-10-09 14:23:17 +02:00
|
|
|
if expagename == apppagename:
|
2012-08-22 18:24:33 +02:00
|
|
|
noclobber = True
|
|
|
|
# Another reason not to make the redirect page is if the app name
|
|
|
|
# is the same as it's ID, because that will overwrite the real page
|
|
|
|
# with an redirect to itself! (Although it seems like an odd
|
|
|
|
# scenario this happens a lot, e.g. where there is metadata but no
|
|
|
|
# builds or binaries to extract a name from.
|
2012-09-10 23:49:10 +02:00
|
|
|
if apppagename == pagename:
|
2012-08-22 18:24:33 +02:00
|
|
|
noclobber = True
|
|
|
|
if not noclobber:
|
2013-10-09 15:39:00 +02:00
|
|
|
generated_redirects[apppagename] = "#REDIRECT [[" + pagename + "]]\n[[Category:" + wikiredircat + "]]"
|
|
|
|
|
|
|
|
for tcat, genp in [(wikicat, generated_pages),
|
2014-05-06 19:50:52 +02:00
|
|
|
(wikiredircat, generated_redirects)]:
|
2013-10-09 15:39:00 +02:00
|
|
|
catpages = site.Pages['Category:' + tcat]
|
|
|
|
existingpages = []
|
|
|
|
for page in catpages:
|
|
|
|
existingpages.append(page.name)
|
|
|
|
if page.name in genp:
|
|
|
|
pagetxt = page.edit()
|
|
|
|
if pagetxt != genp[page.name]:
|
2014-02-22 11:00:29 +01:00
|
|
|
logging.debug("Updating modified page " + page.name)
|
2013-10-09 15:39:00 +02:00
|
|
|
page.save(genp[page.name], summary='Auto-updated')
|
|
|
|
else:
|
2014-02-22 11:00:29 +01:00
|
|
|
logging.debug("Page " + page.name + " is unchanged")
|
2012-08-22 18:24:33 +02:00
|
|
|
else:
|
2014-02-22 11:00:29 +01:00
|
|
|
logging.warn("Deleting page " + page.name)
|
2013-10-09 15:39:00 +02:00
|
|
|
page.delete('No longer published')
|
|
|
|
for pagename, text in genp.items():
|
2014-02-22 11:00:29 +01:00
|
|
|
logging.debug("Checking " + pagename)
|
2014-05-07 16:13:22 +02:00
|
|
|
if pagename not in existingpages:
|
2014-02-22 11:00:29 +01:00
|
|
|
logging.debug("Creating page " + pagename)
|
2013-10-09 15:39:00 +02:00
|
|
|
try:
|
|
|
|
newpage = site.Pages[pagename]
|
|
|
|
newpage.save(text, summary='Auto-created')
|
|
|
|
except:
|
2015-02-01 21:32:03 +01:00
|
|
|
logging.error("...FAILED to create page '{0}'".format(pagename))
|
2012-08-22 18:24:33 +02:00
|
|
|
|
2013-10-10 10:47:48 +02:00
|
|
|
# Purge server cache to ensure counts are up to date
|
|
|
|
site.pages['Repository Maintenance'].purge()
|
2012-08-22 18:24:33 +02:00
|
|
|
|
2014-05-02 05:39:33 +02:00
|
|
|
|
2013-05-09 21:09:17 +02:00
|
|
|
def delete_disabled_builds(apps, apkcache, repodirs):
|
|
|
|
"""Delete disabled build outputs.
|
2010-10-22 00:26:38 +02:00
|
|
|
|
2013-11-19 15:35:16 +01:00
|
|
|
:param apps: list of all applications, as per metadata.read_metadata
|
2013-05-09 21:09:17 +02:00
|
|
|
:param apkcache: current apk cache information
|
|
|
|
:param repodirs: the repo directories to process
|
|
|
|
"""
|
2016-01-04 17:02:28 +01:00
|
|
|
for appid, app in apps.items():
|
2016-11-23 17:25:59 +01:00
|
|
|
for build in app['builds']:
|
2015-11-28 17:55:27 +01:00
|
|
|
if not build.disable:
|
2015-11-27 00:23:59 +01:00
|
|
|
continue
|
2016-11-23 17:52:04 +01:00
|
|
|
apkfilename = appid + '_' + str(build.versionCode) + '.apk'
|
2015-11-27 00:23:59 +01:00
|
|
|
iconfilename = "%s.%s.png" % (
|
|
|
|
appid,
|
2016-11-23 17:52:04 +01:00
|
|
|
build.versionCode)
|
2015-11-27 00:23:59 +01:00
|
|
|
for repodir in repodirs:
|
|
|
|
files = [
|
|
|
|
os.path.join(repodir, apkfilename),
|
|
|
|
os.path.join(repodir, apkfilename + '.asc'),
|
|
|
|
os.path.join(repodir, apkfilename[:-4] + "_src.tar.gz"),
|
|
|
|
]
|
|
|
|
for density in all_screen_densities:
|
|
|
|
repo_dir = get_icon_dir(repodir, density)
|
|
|
|
files.append(os.path.join(repo_dir, iconfilename))
|
|
|
|
|
|
|
|
for f in files:
|
|
|
|
if os.path.exists(f):
|
|
|
|
logging.info("Deleting disabled build output " + f)
|
|
|
|
os.remove(f)
|
|
|
|
if apkfilename in apkcache:
|
|
|
|
del apkcache[apkfilename]
|
2012-02-26 15:18:58 +01:00
|
|
|
|
2014-05-02 05:39:33 +02:00
|
|
|
|
2014-01-07 12:06:39 +01:00
|
|
|
def resize_icon(iconpath, density):
|
|
|
|
|
2014-01-07 17:02:59 +01:00
|
|
|
if not os.path.isfile(iconpath):
|
|
|
|
return
|
|
|
|
|
2016-06-20 14:01:56 +02:00
|
|
|
fp = None
|
2013-08-21 22:47:48 +02:00
|
|
|
try:
|
2016-06-20 14:01:56 +02:00
|
|
|
fp = open(iconpath, 'rb')
|
|
|
|
im = Image.open(fp)
|
2014-01-07 17:01:51 +01:00
|
|
|
size = dpi_to_px(density)
|
2014-01-07 12:06:39 +01:00
|
|
|
|
|
|
|
if any(length > size for length in im.size):
|
2014-01-07 16:25:29 +01:00
|
|
|
oldsize = im.size
|
2014-01-07 12:06:39 +01:00
|
|
|
im.thumbnail((size, size), Image.ANTIALIAS)
|
2014-02-22 11:00:29 +01:00
|
|
|
logging.debug("%s was too large at %s - new size is %s" % (
|
2014-02-07 21:36:19 +01:00
|
|
|
iconpath, oldsize, im.size))
|
2013-08-21 22:47:48 +02:00
|
|
|
im.save(iconpath, "PNG")
|
2014-01-07 12:06:39 +01:00
|
|
|
|
2015-09-17 13:25:08 +02:00
|
|
|
except Exception as e:
|
2014-02-22 11:00:29 +01:00
|
|
|
logging.error("Failed resizing {0} - {1}".format(iconpath, e))
|
2013-08-19 11:30:54 +02:00
|
|
|
|
2016-06-20 14:01:56 +02:00
|
|
|
finally:
|
|
|
|
if fp:
|
|
|
|
fp.close()
|
|
|
|
|
2014-05-02 05:39:33 +02:00
|
|
|
|
2013-08-19 11:30:54 +02:00
|
|
|
def resize_all_icons(repodirs):
|
2013-08-19 11:36:26 +02:00
|
|
|
"""Resize all icons that exceed the max size
|
2013-08-19 11:30:54 +02:00
|
|
|
|
|
|
|
:param repodirs: the repo directories to process
|
|
|
|
"""
|
|
|
|
for repodir in repodirs:
|
2015-10-24 16:34:55 +02:00
|
|
|
for density in screen_densities:
|
2014-01-07 12:06:39 +01:00
|
|
|
icon_dir = get_icon_dir(repodir, density)
|
2014-01-07 12:24:15 +01:00
|
|
|
icon_glob = os.path.join(icon_dir, '*.png')
|
2014-01-07 12:06:39 +01:00
|
|
|
for iconpath in glob.glob(icon_glob):
|
2014-01-07 12:24:15 +01:00
|
|
|
resize_icon(iconpath, density)
|
2012-02-26 15:18:58 +01:00
|
|
|
|
2014-05-02 05:39:33 +02:00
|
|
|
|
2015-05-13 23:50:08 +02:00
|
|
|
# A signature block file with a .DSA, .RSA, or .EC extension
|
|
|
|
cert_path_regex = re.compile(r'^META-INF/.*\.(DSA|EC|RSA)$')
|
2014-08-30 04:53:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
def getsig(apkpath):
|
|
|
|
""" Get the signing certificate of an apk. To get the same md5 has that
|
|
|
|
Android gets, we encode the .RSA certificate in a specific format and pass
|
|
|
|
it hex-encoded to the md5 digest algorithm.
|
|
|
|
|
|
|
|
:param apkpath: path to the apk
|
|
|
|
:returns: A string containing the md5 of the signature of the apk or None
|
|
|
|
if an error occurred.
|
|
|
|
"""
|
|
|
|
|
|
|
|
cert = None
|
|
|
|
|
2014-08-30 06:45:12 +02:00
|
|
|
# verify the jar signature is correct
|
2016-02-11 20:43:55 +01:00
|
|
|
args = [config['jarsigner'], '-verify', apkpath]
|
2014-08-30 06:45:12 +02:00
|
|
|
p = FDroidPopen(args)
|
|
|
|
if p.returncode != 0:
|
|
|
|
logging.critical(apkpath + " has a bad signature!")
|
|
|
|
return None
|
|
|
|
|
2014-08-30 04:53:55 +02:00
|
|
|
with zipfile.ZipFile(apkpath, 'r') as apk:
|
|
|
|
|
|
|
|
certs = [n for n in apk.namelist() if cert_path_regex.match(n)]
|
|
|
|
|
|
|
|
if len(certs) < 1:
|
|
|
|
logging.error("Found no signing certificates on %s" % apkpath)
|
|
|
|
return None
|
|
|
|
if len(certs) > 1:
|
|
|
|
logging.error("Found multiple signing certificates on %s" % apkpath)
|
|
|
|
return None
|
|
|
|
|
|
|
|
cert = apk.read(certs[0])
|
|
|
|
|
|
|
|
content = decoder.decode(cert, asn1Spec=rfc2315.ContentInfo())[0]
|
|
|
|
if content.getComponentByName('contentType') != rfc2315.signedData:
|
|
|
|
logging.error("Unexpected format.")
|
|
|
|
return None
|
|
|
|
|
|
|
|
content = decoder.decode(content.getComponentByName('content'),
|
|
|
|
asn1Spec=rfc2315.SignedData())[0]
|
|
|
|
try:
|
|
|
|
certificates = content.getComponentByName('certificates')
|
|
|
|
except PyAsn1Error:
|
|
|
|
logging.error("Certificates not found.")
|
|
|
|
return None
|
|
|
|
|
|
|
|
cert_encoded = encoder.encode(certificates)[4:]
|
|
|
|
|
2016-01-04 18:51:39 +01:00
|
|
|
return hashlib.md5(hexlify(cert_encoded)).hexdigest()
|
2014-08-30 04:53:55 +02:00
|
|
|
|
|
|
|
|
2016-06-23 17:58:25 +02:00
|
|
|
def get_icon_bytes(apkzip, iconsrc):
|
|
|
|
'''ZIP has no official encoding, UTF-* and CP437 are defacto'''
|
|
|
|
try:
|
|
|
|
return apkzip.read(iconsrc)
|
|
|
|
except KeyError:
|
|
|
|
return apkzip.read(iconsrc.encode('utf-8').decode('cp437'))
|
|
|
|
|
|
|
|
|
2016-06-20 22:14:12 +02:00
|
|
|
def sha256sum(filename):
|
|
|
|
'''Calculate the sha256 of the given file'''
|
|
|
|
sha = hashlib.sha256()
|
|
|
|
with open(filename, 'rb') as f:
|
|
|
|
while True:
|
|
|
|
t = f.read(16384)
|
|
|
|
if len(t) == 0:
|
|
|
|
break
|
|
|
|
sha.update(t)
|
|
|
|
return sha.hexdigest()
|
|
|
|
|
|
|
|
|
2016-11-03 14:14:08 +01:00
|
|
|
def has_old_openssl(filename):
|
|
|
|
'''checks for known vulnerable openssl versions in the APK'''
|
|
|
|
|
|
|
|
# statically load this pattern
|
|
|
|
if not hasattr(has_old_openssl, "pattern"):
|
|
|
|
has_old_openssl.pattern = re.compile(b'.*OpenSSL ([01][0-9a-z.-]+)')
|
|
|
|
|
|
|
|
with zipfile.ZipFile(filename) as zf:
|
|
|
|
for name in zf.namelist():
|
|
|
|
if name.endswith('libcrypto.so') or name.endswith('libssl.so'):
|
|
|
|
lib = zf.open(name)
|
|
|
|
while True:
|
|
|
|
chunk = lib.read(4096)
|
|
|
|
if chunk == b'':
|
|
|
|
break
|
|
|
|
m = has_old_openssl.pattern.search(chunk)
|
|
|
|
if m:
|
|
|
|
version = m.group(1).decode('ascii')
|
|
|
|
if version.startswith('1.0.1') and version[5] >= 'r' \
|
|
|
|
or version.startswith('1.0.2') and version[5] >= 'f':
|
|
|
|
logging.debug('"%s" contains recent %s (%s)', filename, name, version)
|
|
|
|
else:
|
|
|
|
logging.warning('"%s" contains outdated %s (%s)', filename, name, version)
|
|
|
|
return True
|
|
|
|
break
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2016-06-16 00:29:17 +02:00
|
|
|
def insert_obbs(repodir, apps, apks):
|
|
|
|
"""Scans the .obb files in a given repo directory and adds them to the
|
2016-06-20 22:14:12 +02:00
|
|
|
relevant APK instances. OBB files have versionCodes like APK
|
|
|
|
files, and they are loosely associated. If there is an OBB file
|
|
|
|
present, then any APK with the same or higher versionCode will use
|
|
|
|
that OBB file. There are two OBB types: main and patch, each APK
|
|
|
|
can only have only have one of each.
|
|
|
|
|
|
|
|
https://developer.android.com/google/play/expansion-files.html
|
2016-06-16 00:29:17 +02:00
|
|
|
|
|
|
|
:param repodir: repo directory to scan
|
|
|
|
:param apps: list of current, valid apps
|
|
|
|
:param apks: current information on all APKs
|
2016-06-20 22:14:12 +02:00
|
|
|
|
2016-06-16 00:29:17 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
def obbWarnDelete(f, msg):
|
|
|
|
logging.warning(msg + f)
|
|
|
|
if options.delete_unknown:
|
|
|
|
logging.error("Deleting unknown file: " + f)
|
|
|
|
os.remove(f)
|
|
|
|
|
|
|
|
obbs = []
|
|
|
|
java_Integer_MIN_VALUE = -pow(2, 31)
|
2016-12-06 13:32:34 +01:00
|
|
|
currentPackageNames = apps.keys()
|
2016-06-16 00:29:17 +02:00
|
|
|
for f in glob.glob(os.path.join(repodir, '*.obb')):
|
|
|
|
obbfile = os.path.basename(f)
|
|
|
|
# obbfile looks like: [main|patch].<expansion-version>.<package-name>.obb
|
|
|
|
chunks = obbfile.split('.')
|
|
|
|
if chunks[0] != 'main' and chunks[0] != 'patch':
|
|
|
|
obbWarnDelete(f, 'OBB filename must start with "main." or "patch.": ')
|
|
|
|
continue
|
|
|
|
if not re.match(r'^-?[0-9]+$', chunks[1]):
|
|
|
|
obbWarnDelete('The OBB version code must come after "' + chunks[0] + '.": ')
|
|
|
|
continue
|
2016-11-29 13:40:21 +01:00
|
|
|
versionCode = int(chunks[1])
|
2016-06-16 00:29:17 +02:00
|
|
|
packagename = ".".join(chunks[2:-1])
|
|
|
|
|
|
|
|
highestVersionCode = java_Integer_MIN_VALUE
|
2016-12-06 13:32:34 +01:00
|
|
|
if packagename not in currentPackageNames:
|
2016-06-16 00:29:17 +02:00
|
|
|
obbWarnDelete(f, "OBB's packagename does not match a supported APK: ")
|
|
|
|
continue
|
|
|
|
for apk in apks:
|
2016-11-29 13:40:21 +01:00
|
|
|
if packagename == apk['packageName'] and apk['versionCode'] > highestVersionCode:
|
|
|
|
highestVersionCode = apk['versionCode']
|
|
|
|
if versionCode > highestVersionCode:
|
|
|
|
obbWarnDelete(f, 'OBB file has newer versionCode(' + str(versionCode)
|
2016-06-16 00:29:17 +02:00
|
|
|
+ ') than any APK: ')
|
|
|
|
continue
|
2016-06-20 22:14:12 +02:00
|
|
|
obbsha256 = sha256sum(f)
|
2016-11-29 13:40:21 +01:00
|
|
|
obbs.append((packagename, versionCode, obbfile, obbsha256))
|
2016-06-16 00:29:17 +02:00
|
|
|
|
|
|
|
for apk in apks:
|
2016-11-29 13:40:21 +01:00
|
|
|
for (packagename, versionCode, obbfile, obbsha256) in sorted(obbs, reverse=True):
|
|
|
|
if versionCode <= apk['versionCode'] and packagename == apk['packageName']:
|
2016-06-16 00:29:17 +02:00
|
|
|
if obbfile.startswith('main.') and 'obbMainFile' not in apk:
|
|
|
|
apk['obbMainFile'] = obbfile
|
2016-06-20 22:14:12 +02:00
|
|
|
apk['obbMainFileSha256'] = obbsha256
|
2016-06-16 00:29:17 +02:00
|
|
|
elif obbfile.startswith('patch.') and 'obbPatchFile' not in apk:
|
|
|
|
apk['obbPatchFile'] = obbfile
|
2016-06-20 22:14:12 +02:00
|
|
|
apk['obbPatchFileSha256'] = obbsha256
|
2016-06-16 00:29:17 +02:00
|
|
|
if 'obbMainFile' in apk and 'obbPatchFile' in apk:
|
|
|
|
break
|
|
|
|
|
|
|
|
|
2016-12-06 13:32:34 +01:00
|
|
|
def insert_graphics(repodir, apps):
|
|
|
|
"""Scans for screenshot PNG files in statically defined screenshots
|
|
|
|
directory and adds them to the app metadata. The screenshots and
|
|
|
|
graphic must be PNG or JPEG files ending with ".png", ".jpg", or ".jpeg"
|
|
|
|
and must be in the following layout:
|
|
|
|
|
|
|
|
repo/packageName/locale/featureGraphic.png
|
|
|
|
repo/packageName/locale/phoneScreenshots/1.png
|
|
|
|
repo/packageName/locale/phoneScreenshots/2.png
|
|
|
|
|
|
|
|
Where "packageName" is the app's packageName and "locale" is the locale
|
|
|
|
of the graphics, e.g. what language they are in, using the IETF RFC5646
|
|
|
|
format (en-US, fr-CA, es-MX, etc). This is following this pattern:
|
|
|
|
https://github.com/fastlane/fastlane/blob/1.109.0/supply/README.md#images-and-screenshots
|
|
|
|
|
2016-12-06 17:22:46 +01:00
|
|
|
This will also scan the metadata/ folder and the apps' source repos
|
|
|
|
for standard locations of graphic and screenshot files. If it finds
|
|
|
|
them, it will copy them into the repo.
|
|
|
|
|
2016-12-06 13:32:34 +01:00
|
|
|
:param repodir: repo directory to scan
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2016-12-06 17:22:46 +01:00
|
|
|
allowed_extensions = ('png', 'jpg', 'jpeg')
|
|
|
|
graphicnames = ('featureGraphic', 'icon', 'promoGraphic', 'tvBanner')
|
|
|
|
screenshotdirs = ('phoneScreenshots', 'sevenInchScreenshots',
|
|
|
|
'tenInchScreenshots', 'tvScreenshots', 'wearScreenshots')
|
|
|
|
|
|
|
|
sourcedirs = glob.glob(os.path.join('build', '[A-Za-z]*', 'fastlane', 'metadata', 'android', '[a-z][a-z][A-Z-.@]*'))
|
|
|
|
sourcedirs += glob.glob(os.path.join('metadata', '[A-Za-z]*', '[a-z][a-z][A-Z-.@]*'))
|
|
|
|
|
|
|
|
for d in sorted(sourcedirs):
|
|
|
|
if not os.path.isdir(d):
|
|
|
|
continue
|
|
|
|
for root, dirs, files in os.walk(d):
|
|
|
|
segments = root.split('/')
|
|
|
|
destdir = os.path.join('repo', segments[1], segments[-1]) # repo/packageName/locale
|
|
|
|
for f in files:
|
|
|
|
base, extension = common.get_extension(f)
|
|
|
|
if base in graphicnames and extension in allowed_extensions:
|
|
|
|
os.makedirs(destdir, mode=0o755, exist_ok=True)
|
|
|
|
logging.debug('copying ' + os.path.join(root, f) + ' ' + destdir)
|
|
|
|
shutil.copy(os.path.join(root, f), destdir)
|
|
|
|
for d in dirs:
|
|
|
|
if d in screenshotdirs:
|
|
|
|
for f in glob.glob(os.path.join(root, d, '*.*')):
|
|
|
|
_, extension = common.get_extension(f)
|
|
|
|
if extension in allowed_extensions:
|
|
|
|
screenshotdestdir = os.path.join(destdir, d)
|
|
|
|
os.makedirs(screenshotdestdir, mode=0o755, exist_ok=True)
|
|
|
|
logging.debug('copying ' + f + ' ' + screenshotdestdir)
|
|
|
|
shutil.copy(f, screenshotdestdir)
|
2016-12-06 13:32:34 +01:00
|
|
|
|
|
|
|
repofiles = sorted(glob.glob(os.path.join('repo', '[A-Za-z]*', '[a-z][a-z][A-Z-.@]*')))
|
|
|
|
for d in repofiles:
|
|
|
|
if not os.path.isdir(d):
|
|
|
|
continue
|
|
|
|
for f in sorted(glob.glob(os.path.join(d, '*.*')) + glob.glob(os.path.join(d, '*Screenshots', '*.*'))):
|
|
|
|
if not os.path.isfile(f):
|
|
|
|
continue
|
|
|
|
segments = f.split('/')
|
|
|
|
packageName = segments[1]
|
|
|
|
locale = segments[2]
|
|
|
|
screenshotdir = segments[3]
|
|
|
|
filename = os.path.basename(f)
|
|
|
|
base, extension = common.get_extension(filename)
|
|
|
|
|
|
|
|
if packageName not in apps:
|
2016-12-08 19:28:31 +01:00
|
|
|
logging.warning('Found "%s" graphic without metadata for app "%s"!'
|
|
|
|
% (filename, packageName))
|
|
|
|
continue
|
2016-12-06 13:32:34 +01:00
|
|
|
if 'localized' not in apps[packageName]:
|
|
|
|
apps[packageName]['localized'] = collections.OrderedDict()
|
|
|
|
if locale not in apps[packageName]['localized']:
|
|
|
|
apps[packageName]['localized'][locale] = collections.OrderedDict()
|
|
|
|
graphics = apps[packageName]['localized'][locale]
|
|
|
|
|
2016-12-06 17:22:46 +01:00
|
|
|
if extension not in allowed_extensions:
|
2016-12-06 13:32:34 +01:00
|
|
|
logging.warning('Only PNG and JPEG are supported for graphics, found: ' + f)
|
2016-12-06 17:22:46 +01:00
|
|
|
elif base in graphicnames:
|
2016-12-06 13:32:34 +01:00
|
|
|
# there can only be zero or one of these per locale
|
|
|
|
graphics[base] = filename
|
2016-12-06 17:22:46 +01:00
|
|
|
elif screenshotdir in screenshotdirs:
|
2016-12-06 13:32:34 +01:00
|
|
|
# there can any number of these per locale
|
|
|
|
logging.debug('adding ' + base + ':' + f)
|
|
|
|
if screenshotdir not in graphics:
|
|
|
|
graphics[screenshotdir] = []
|
|
|
|
graphics[screenshotdir].append(filename)
|
|
|
|
else:
|
|
|
|
logging.warning('Unsupported graphics file found: ' + f)
|
|
|
|
|
|
|
|
|
2016-10-13 18:24:58 +02:00
|
|
|
def scan_repo_files(apkcache, repodir, knownapks, use_date_from_file=False):
|
|
|
|
"""Scan a repo for all files with an extension except APK/OBB
|
|
|
|
|
|
|
|
:param apkcache: current cached info about all repo files
|
|
|
|
:param repodir: repo directory to scan
|
|
|
|
:param knownapks: list of all known files, as per metadata.read_metadata
|
|
|
|
:param use_date_from_file: use date from file (instead of current date)
|
|
|
|
for newly added files
|
|
|
|
"""
|
|
|
|
|
|
|
|
cachechanged = False
|
|
|
|
repo_files = []
|
|
|
|
for name in os.listdir(repodir):
|
2016-11-02 15:50:34 +01:00
|
|
|
file_extension = common.get_file_extension(name)
|
2016-10-13 18:24:58 +02:00
|
|
|
if file_extension == 'apk' or file_extension == 'obb':
|
|
|
|
continue
|
2016-11-02 15:50:34 +01:00
|
|
|
filename = os.path.join(repodir, name)
|
2017-03-10 17:40:19 +01:00
|
|
|
if filename.endswith('_src.tar.gz'):
|
2017-03-15 14:23:19 +01:00
|
|
|
logging.debug('skipping source tarball: ' + filename)
|
2017-03-10 17:40:19 +01:00
|
|
|
continue
|
2016-12-08 19:11:36 +01:00
|
|
|
if not common.is_repo_file(filename):
|
2016-10-13 18:24:58 +02:00
|
|
|
continue
|
2016-11-02 15:50:34 +01:00
|
|
|
stat = os.stat(filename)
|
|
|
|
if stat.st_size == 0:
|
2016-10-13 18:24:58 +02:00
|
|
|
logging.error(filename + ' is zero size!')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
shasum = sha256sum(filename)
|
|
|
|
usecache = False
|
|
|
|
if name in apkcache:
|
|
|
|
repo_file = apkcache[name]
|
2016-11-28 21:10:58 +01:00
|
|
|
# added time is cached as tuple but used here as datetime instance
|
|
|
|
if 'added' in repo_file:
|
|
|
|
a = repo_file['added']
|
|
|
|
if isinstance(a, datetime):
|
|
|
|
repo_file['added'] = a
|
|
|
|
else:
|
|
|
|
repo_file['added'] = datetime(*a[:6])
|
2016-11-29 13:40:21 +01:00
|
|
|
if repo_file['hash'] == shasum:
|
2016-10-13 18:24:58 +02:00
|
|
|
logging.debug("Reading " + name + " from cache")
|
|
|
|
usecache = True
|
|
|
|
else:
|
|
|
|
logging.debug("Ignoring stale cache data for " + name)
|
2016-11-28 21:18:17 +01:00
|
|
|
|
|
|
|
if not usecache:
|
2016-10-13 18:24:58 +02:00
|
|
|
logging.debug("Processing " + name)
|
|
|
|
repo_file = {}
|
|
|
|
# TODO rename apkname globally to something more generic
|
|
|
|
repo_file['name'] = name
|
2016-11-29 13:40:21 +01:00
|
|
|
repo_file['apkName'] = name
|
|
|
|
repo_file['hash'] = shasum
|
|
|
|
repo_file['hashType'] = 'sha256'
|
|
|
|
repo_file['versionCode'] = 0
|
|
|
|
repo_file['versionName'] = shasum
|
2016-10-13 18:24:58 +02:00
|
|
|
# the static ID is the SHA256 unless it is set in the metadata
|
2016-11-29 13:40:21 +01:00
|
|
|
repo_file['packageName'] = shasum
|
2017-03-10 18:28:22 +01:00
|
|
|
n = name.split('_')
|
|
|
|
if len(n) == 2:
|
|
|
|
packageName = n[0]
|
|
|
|
versionCode = n[1].split('.')[0]
|
|
|
|
if re.match(r'^-?[0-9]+$', versionCode) \
|
|
|
|
and common.is_valid_package_name(name.split('_')[0]):
|
2016-11-29 13:40:21 +01:00
|
|
|
repo_file['packageName'] = packageName
|
|
|
|
repo_file['versionCode'] = int(versionCode)
|
2017-03-10 19:05:01 +01:00
|
|
|
srcfilename = name + "_src.tar.gz"
|
2016-10-13 18:24:58 +02:00
|
|
|
if os.path.exists(os.path.join(repodir, srcfilename)):
|
|
|
|
repo_file['srcname'] = srcfilename
|
2016-11-02 15:50:34 +01:00
|
|
|
repo_file['size'] = stat.st_size
|
2016-10-13 18:24:58 +02:00
|
|
|
|
|
|
|
apkcache[name] = repo_file
|
|
|
|
cachechanged = True
|
|
|
|
|
|
|
|
if use_date_from_file:
|
2016-11-02 15:50:34 +01:00
|
|
|
timestamp = stat.st_ctime
|
2016-10-13 18:24:58 +02:00
|
|
|
default_date_param = datetime.fromtimestamp(timestamp).utctimetuple()
|
|
|
|
else:
|
|
|
|
default_date_param = None
|
|
|
|
|
|
|
|
# Record in knownapks, getting the added date at the same time..
|
2016-11-29 13:40:21 +01:00
|
|
|
added = knownapks.recordapk(repo_file['apkName'], repo_file['packageName'],
|
2016-10-13 18:24:58 +02:00
|
|
|
default_date=default_date_param)
|
|
|
|
if added:
|
|
|
|
repo_file['added'] = added
|
|
|
|
|
|
|
|
repo_files.append(repo_file)
|
|
|
|
|
|
|
|
return repo_files, cachechanged
|
|
|
|
|
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
def scan_apk(apkcache, apkfilename, repodir, knownapks, use_date_from_apk):
|
|
|
|
"""Scan the apk with the given filename in the given repo directory.
|
2012-02-26 15:18:58 +01:00
|
|
|
|
2013-05-09 21:09:17 +02:00
|
|
|
This also extracts the icons.
|
2012-02-26 15:18:58 +01:00
|
|
|
|
2013-05-09 21:09:17 +02:00
|
|
|
:param apkcache: current apk cache information
|
2017-03-15 18:43:22 +01:00
|
|
|
:param apkfilename: the filename of the apk to scan
|
2013-05-09 21:09:17 +02:00
|
|
|
:param repodir: repo directory to scan
|
|
|
|
:param knownapks: known apks info
|
2016-02-18 13:41:43 +01:00
|
|
|
:param use_date_from_apk: use date from APK (instead of current date)
|
|
|
|
for newly added APKs
|
2017-03-15 18:43:22 +01:00
|
|
|
:returns: (skip, apk, cachechanged) where skip is a boolean indicating whether to skip this apk,
|
|
|
|
apk is the scanned apk information, and cachechanged is True if the apkcache got changed.
|
2013-05-09 21:09:17 +02:00
|
|
|
"""
|
2012-02-26 15:18:58 +01:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
if ' ' in apkfilename:
|
|
|
|
logging.critical("Spaces in filenames are not allowed.")
|
|
|
|
sys.exit(1)
|
2015-01-11 19:22:00 +01:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
apkfile = os.path.join(repodir, apkfilename)
|
|
|
|
shasum = sha256sum(apkfile)
|
2012-09-03 12:48:18 +02:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
cachechanged = False
|
|
|
|
usecache = False
|
|
|
|
if apkfilename in apkcache:
|
|
|
|
apk = apkcache[apkfilename]
|
|
|
|
if apk['hash'] == shasum:
|
|
|
|
logging.debug("Reading " + apkfilename + " from cache")
|
|
|
|
usecache = True
|
|
|
|
else:
|
|
|
|
logging.debug("Ignoring stale cache data for " + apkfilename)
|
|
|
|
|
|
|
|
if not usecache:
|
|
|
|
logging.debug("Processing " + apkfilename)
|
|
|
|
apk = {}
|
|
|
|
apk['apkName'] = apkfilename
|
|
|
|
apk['hash'] = shasum
|
|
|
|
apk['hashType'] = 'sha256'
|
|
|
|
srcfilename = apkfilename[:-4] + "_src.tar.gz"
|
|
|
|
if os.path.exists(os.path.join(repodir, srcfilename)):
|
|
|
|
apk['srcname'] = srcfilename
|
|
|
|
apk['size'] = os.path.getsize(apkfile)
|
|
|
|
apk['uses-permission'] = set()
|
|
|
|
apk['uses-permission-sdk-23'] = set()
|
|
|
|
apk['features'] = set()
|
|
|
|
apk['icons_src'] = {}
|
|
|
|
apk['icons'] = {}
|
|
|
|
apk['antiFeatures'] = set()
|
|
|
|
if has_old_openssl(apkfile):
|
|
|
|
apk['antiFeatures'].add('KnownVuln')
|
|
|
|
p = SdkToolsPopen(['aapt', 'dump', 'badging', apkfile], output=False)
|
|
|
|
if p.returncode != 0:
|
|
|
|
if options.delete_unknown:
|
|
|
|
if os.path.exists(apkfile):
|
|
|
|
logging.error("Failed to get apk information, deleting " + apkfile)
|
|
|
|
os.remove(apkfile)
|
2014-06-02 22:18:12 +02:00
|
|
|
else:
|
2017-03-15 18:43:22 +01:00
|
|
|
logging.error("Could not find {0} to remove it".format(apkfile))
|
|
|
|
else:
|
|
|
|
logging.error("Failed to get apk information, skipping " + apkfile)
|
|
|
|
return True
|
|
|
|
for line in p.output.splitlines():
|
|
|
|
if line.startswith("package:"):
|
|
|
|
try:
|
|
|
|
apk['packageName'] = re.match(APK_NAME_PAT, line).group(1)
|
|
|
|
apk['versionCode'] = int(re.match(APK_VERCODE_PAT, line).group(1))
|
|
|
|
apk['versionName'] = re.match(APK_VERNAME_PAT, line).group(1)
|
|
|
|
except Exception as e:
|
|
|
|
logging.error("Package matching failed: " + str(e))
|
|
|
|
logging.info("Line was: " + line)
|
|
|
|
sys.exit(1)
|
|
|
|
elif line.startswith("application:"):
|
|
|
|
apk['name'] = re.match(APK_LABEL_PAT, line).group(1)
|
|
|
|
# Keep path to non-dpi icon in case we need it
|
|
|
|
match = re.match(APK_ICON_PAT_NODPI, line)
|
|
|
|
if match:
|
|
|
|
apk['icons_src']['-1'] = match.group(1)
|
|
|
|
elif line.startswith("launchable-activity:"):
|
|
|
|
# Only use launchable-activity as fallback to application
|
|
|
|
if not apk['name']:
|
|
|
|
apk['name'] = re.match(APK_LABEL_PAT, line).group(1)
|
|
|
|
if '-1' not in apk['icons_src']:
|
|
|
|
match = re.match(APK_ICON_PAT_NODPI, line)
|
2014-01-07 16:16:26 +01:00
|
|
|
if match:
|
2015-11-28 17:55:27 +01:00
|
|
|
apk['icons_src']['-1'] = match.group(1)
|
2017-03-15 18:43:22 +01:00
|
|
|
elif line.startswith("application-icon-"):
|
|
|
|
match = re.match(APK_ICON_PAT, line)
|
|
|
|
if match:
|
|
|
|
density = match.group(1)
|
|
|
|
path = match.group(2)
|
|
|
|
apk['icons_src'][density] = path
|
|
|
|
elif line.startswith("sdkVersion:"):
|
|
|
|
m = re.match(APK_SDK_VERSION_PAT, line)
|
|
|
|
if m is None:
|
|
|
|
logging.error(line.replace('sdkVersion:', '')
|
|
|
|
+ ' is not a valid minSdkVersion!')
|
|
|
|
else:
|
|
|
|
apk['minSdkVersion'] = m.group(1)
|
|
|
|
# if target not set, default to min
|
|
|
|
if 'targetSdkVersion' not in apk:
|
2016-06-14 11:43:07 +02:00
|
|
|
apk['targetSdkVersion'] = m.group(1)
|
2017-03-15 18:43:22 +01:00
|
|
|
elif line.startswith("targetSdkVersion:"):
|
|
|
|
m = re.match(APK_SDK_VERSION_PAT, line)
|
|
|
|
if m is None:
|
|
|
|
logging.error(line.replace('targetSdkVersion:', '')
|
|
|
|
+ ' is not a valid targetSdkVersion!')
|
|
|
|
else:
|
|
|
|
apk['targetSdkVersion'] = m.group(1)
|
|
|
|
elif line.startswith("maxSdkVersion:"):
|
|
|
|
apk['maxSdkVersion'] = re.match(APK_SDK_VERSION_PAT, line).group(1)
|
|
|
|
elif line.startswith("native-code:"):
|
|
|
|
apk['nativecode'] = []
|
|
|
|
for arch in line[13:].split(' '):
|
|
|
|
apk['nativecode'].append(arch[1:-1])
|
|
|
|
elif line.startswith('uses-permission:'):
|
|
|
|
perm_match = re.match(APK_PERMISSION_PAT, line).groupdict()
|
|
|
|
if perm_match['maxSdkVersion']:
|
|
|
|
perm_match['maxSdkVersion'] = int(perm_match['maxSdkVersion'])
|
|
|
|
permission = UsesPermission(
|
|
|
|
perm_match['name'],
|
|
|
|
perm_match['maxSdkVersion']
|
|
|
|
)
|
|
|
|
|
|
|
|
apk['uses-permission'].add(permission)
|
|
|
|
elif line.startswith('uses-permission-sdk-23:'):
|
|
|
|
perm_match = re.match(APK_PERMISSION_PAT, line).groupdict()
|
|
|
|
if perm_match['maxSdkVersion']:
|
|
|
|
perm_match['maxSdkVersion'] = int(perm_match['maxSdkVersion'])
|
|
|
|
permission_sdk_23 = UsesPermissionSdk23(
|
|
|
|
perm_match['name'],
|
|
|
|
perm_match['maxSdkVersion']
|
|
|
|
)
|
|
|
|
|
|
|
|
apk['uses-permission-sdk-23'].add(permission_sdk_23)
|
|
|
|
|
|
|
|
elif line.startswith('uses-feature:'):
|
|
|
|
feature = re.match(APK_FEATURE_PAT, line).group(1)
|
|
|
|
# Filter out this, it's only added with the latest SDK tools and
|
|
|
|
# causes problems for lots of apps.
|
|
|
|
if feature != "android.hardware.screen.portrait" \
|
|
|
|
and feature != "android.hardware.screen.landscape":
|
|
|
|
if feature.startswith("android.feature."):
|
|
|
|
feature = feature[16:]
|
|
|
|
apk['features'].add(feature)
|
|
|
|
|
|
|
|
if 'minSdkVersion' not in apk:
|
|
|
|
logging.warn("No SDK version information found in {0}".format(apkfile))
|
|
|
|
apk['minSdkVersion'] = 1
|
|
|
|
|
|
|
|
# Check for debuggable apks...
|
|
|
|
if common.isApkAndDebuggable(apkfile, config):
|
|
|
|
logging.warning('{0} is set to android:debuggable="true"'.format(apkfile))
|
|
|
|
|
|
|
|
# Get the signature (or md5 of, to be precise)...
|
|
|
|
logging.debug('Getting signature of {0}'.format(apkfile))
|
|
|
|
apk['sig'] = getsig(os.path.join(os.getcwd(), apkfile))
|
|
|
|
if not apk['sig']:
|
|
|
|
logging.critical("Failed to get apk signature")
|
|
|
|
sys.exit(1)
|
2015-07-21 01:42:40 +02:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
apkzip = zipfile.ZipFile(apkfile, 'r')
|
2014-01-07 12:06:39 +01:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
# if an APK has files newer than the system time, suggest updating
|
|
|
|
# the system clock. This is useful for offline systems, used for
|
|
|
|
# signing, which do not have another source of clock sync info. It
|
|
|
|
# has to be more than 24 hours newer because ZIP/APK files do not
|
|
|
|
# store timezone info
|
|
|
|
manifest = apkzip.getinfo('AndroidManifest.xml')
|
|
|
|
if manifest.date_time[1] == 0: # month can't be zero
|
|
|
|
logging.debug('AndroidManifest.xml has no date')
|
|
|
|
else:
|
|
|
|
dt_obj = datetime(*manifest.date_time)
|
|
|
|
checkdt = dt_obj - timedelta(1)
|
|
|
|
if datetime.today() < checkdt:
|
|
|
|
logging.warn('System clock is older than manifest in: '
|
|
|
|
+ apkfilename
|
|
|
|
+ '\nSet clock to that time using:\n'
|
|
|
|
+ 'sudo date -s "' + str(dt_obj) + '"')
|
|
|
|
|
|
|
|
iconfilename = "%s.%s.png" % (
|
|
|
|
apk['packageName'],
|
|
|
|
apk['versionCode'])
|
|
|
|
|
|
|
|
# Extract the icon file...
|
|
|
|
empty_densities = []
|
|
|
|
for density in screen_densities:
|
|
|
|
if density not in apk['icons_src']:
|
|
|
|
empty_densities.append(density)
|
|
|
|
continue
|
|
|
|
iconsrc = apk['icons_src'][density]
|
|
|
|
icon_dir = get_icon_dir(repodir, density)
|
|
|
|
icondest = os.path.join(icon_dir, iconfilename)
|
2014-01-07 12:06:39 +01:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
try:
|
|
|
|
with open(icondest, 'wb') as f:
|
2016-06-23 17:58:25 +02:00
|
|
|
f.write(get_icon_bytes(apkzip, iconsrc))
|
2017-03-15 18:43:22 +01:00
|
|
|
apk['icons'][density] = iconfilename
|
|
|
|
|
|
|
|
except:
|
|
|
|
logging.warn("Error retrieving icon file")
|
|
|
|
del apk['icons'][density]
|
|
|
|
del apk['icons_src'][density]
|
|
|
|
empty_densities.append(density)
|
|
|
|
|
|
|
|
if '-1' in apk['icons_src']:
|
|
|
|
iconsrc = apk['icons_src']['-1']
|
|
|
|
iconpath = os.path.join(
|
|
|
|
get_icon_dir(repodir, '0'), iconfilename)
|
|
|
|
with open(iconpath, 'wb') as f:
|
|
|
|
f.write(get_icon_bytes(apkzip, iconsrc))
|
|
|
|
try:
|
|
|
|
im = Image.open(iconpath)
|
|
|
|
dpi = px_to_dpi(im.size[0])
|
|
|
|
for density in screen_densities:
|
|
|
|
if density in apk['icons']:
|
|
|
|
break
|
|
|
|
if density == screen_densities[-1] or dpi >= int(density):
|
|
|
|
apk['icons'][density] = iconfilename
|
|
|
|
shutil.move(iconpath,
|
|
|
|
os.path.join(get_icon_dir(repodir, density), iconfilename))
|
|
|
|
empty_densities.remove(density)
|
|
|
|
break
|
|
|
|
except Exception as e:
|
|
|
|
logging.warn("Failed reading {0} - {1}".format(iconpath, e))
|
2014-01-24 12:55:43 +01:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
if apk['icons']:
|
|
|
|
apk['icon'] = iconfilename
|
2014-01-07 12:20:24 +01:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
apkzip.close()
|
2014-01-07 12:20:24 +01:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
# First try resizing down to not lose quality
|
|
|
|
last_density = None
|
|
|
|
for density in screen_densities:
|
|
|
|
if density not in empty_densities:
|
|
|
|
last_density = density
|
|
|
|
continue
|
|
|
|
if last_density is None:
|
|
|
|
continue
|
|
|
|
logging.debug("Density %s not available, resizing down from %s"
|
|
|
|
% (density, last_density))
|
|
|
|
|
|
|
|
last_iconpath = os.path.join(
|
|
|
|
get_icon_dir(repodir, last_density), iconfilename)
|
|
|
|
iconpath = os.path.join(
|
|
|
|
get_icon_dir(repodir, density), iconfilename)
|
|
|
|
fp = None
|
|
|
|
try:
|
|
|
|
fp = open(last_iconpath, 'rb')
|
|
|
|
im = Image.open(fp)
|
|
|
|
|
|
|
|
size = dpi_to_px(density)
|
|
|
|
|
|
|
|
im.thumbnail((size, size), Image.ANTIALIAS)
|
|
|
|
im.save(iconpath, "PNG")
|
2014-01-07 12:20:24 +01:00
|
|
|
empty_densities.remove(density)
|
2017-03-15 18:43:22 +01:00
|
|
|
except:
|
|
|
|
logging.warning("Invalid image file at %s" % last_iconpath)
|
|
|
|
finally:
|
|
|
|
if fp:
|
|
|
|
fp.close()
|
|
|
|
|
|
|
|
# Then just copy from the highest resolution available
|
|
|
|
last_density = None
|
|
|
|
for density in reversed(screen_densities):
|
|
|
|
if density not in empty_densities:
|
|
|
|
last_density = density
|
|
|
|
continue
|
|
|
|
if last_density is None:
|
|
|
|
continue
|
|
|
|
logging.debug("Density %s not available, copying from lower density %s"
|
|
|
|
% (density, last_density))
|
2014-01-07 12:06:39 +01:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
shutil.copyfile(
|
|
|
|
os.path.join(get_icon_dir(repodir, last_density), iconfilename),
|
|
|
|
os.path.join(get_icon_dir(repodir, density), iconfilename))
|
2014-01-07 17:01:51 +01:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
empty_densities.remove(density)
|
2013-08-19 11:20:50 +02:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
for density in screen_densities:
|
|
|
|
icon_dir = get_icon_dir(repodir, density)
|
|
|
|
icondest = os.path.join(icon_dir, iconfilename)
|
|
|
|
resize_icon(icondest, density)
|
|
|
|
|
|
|
|
# Copy from icons-mdpi to icons since mdpi is the baseline density
|
|
|
|
baseline = os.path.join(get_icon_dir(repodir, '160'), iconfilename)
|
|
|
|
if os.path.isfile(baseline):
|
|
|
|
apk['icons']['0'] = iconfilename
|
|
|
|
shutil.copyfile(baseline,
|
|
|
|
os.path.join(get_icon_dir(repodir, '0'), iconfilename))
|
|
|
|
|
|
|
|
if use_date_from_apk and manifest.date_time[1] != 0:
|
|
|
|
default_date_param = datetime(*manifest.date_time)
|
|
|
|
else:
|
|
|
|
default_date_param = None
|
|
|
|
|
|
|
|
# Record in known apks, getting the added date at the same time..
|
|
|
|
added = knownapks.recordapk(apk['apkName'], apk['packageName'],
|
|
|
|
default_date=default_date_param)
|
|
|
|
if added:
|
|
|
|
apk['added'] = added
|
2016-06-26 17:18:50 +02:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
apkcache[apkfilename] = apk
|
|
|
|
cachechanged = True
|
2012-09-03 12:48:18 +02:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
return False, apk, cachechanged
|
|
|
|
|
|
|
|
|
|
|
|
def scan_apks(apkcache, repodir, knownapks, use_date_from_apk=False):
|
|
|
|
"""Scan the apks in the given repo directory.
|
|
|
|
|
|
|
|
This also extracts the icons.
|
2012-07-12 22:48:59 +02:00
|
|
|
|
2017-03-15 18:43:22 +01:00
|
|
|
:param apkcache: current apk cache information
|
|
|
|
:param repodir: repo directory to scan
|
|
|
|
:param knownapks: known apks info
|
|
|
|
:param use_date_from_apk: use date from APK (instead of current date)
|
|
|
|
for newly added APKs
|
|
|
|
:returns: (apks, cachechanged) where apks is a list of apk information,
|
|
|
|
and cachechanged is True if the apkcache got changed.
|
|
|
|
"""
|
|
|
|
|
|
|
|
cachechanged = False
|
|
|
|
|
|
|
|
for icon_dir in get_all_icon_dirs(repodir):
|
|
|
|
if os.path.exists(icon_dir):
|
|
|
|
if options.clean:
|
|
|
|
shutil.rmtree(icon_dir)
|
|
|
|
os.makedirs(icon_dir)
|
|
|
|
else:
|
|
|
|
os.makedirs(icon_dir)
|
|
|
|
|
|
|
|
apks = []
|
|
|
|
for apkfile in glob.glob(os.path.join(repodir, '*.apk')):
|
|
|
|
apkfilename = apkfile[len(repodir) + 1:]
|
|
|
|
(skip, apk, cachechanged) = scan_apk(apkcache, apkfilename, repodir, knownapks, use_date_from_apk)
|
|
|
|
if skip:
|
|
|
|
continue
|
2015-11-28 17:55:27 +01:00
|
|
|
apks.append(apk)
|
2010-12-17 13:31:04 +01:00
|
|
|
|
2013-05-09 21:09:17 +02:00
|
|
|
return apks, cachechanged
|
2012-09-03 12:48:18 +02:00
|
|
|
|
2012-02-26 15:18:58 +01:00
|
|
|
|
2013-10-31 23:16:05 +01:00
|
|
|
repo_pubkey_fingerprint = None
|
|
|
|
|
2014-05-02 05:39:33 +02:00
|
|
|
|
2015-04-21 01:09:50 +02:00
|
|
|
# Generate a certificate fingerprint the same way keytool does it
|
|
|
|
# (but with slightly different formatting)
|
|
|
|
def cert_fingerprint(data):
|
|
|
|
digest = hashlib.sha256(data).digest()
|
|
|
|
ret = []
|
2016-01-04 17:29:40 +01:00
|
|
|
ret.append(' '.join("%02X" % b for b in bytearray(digest)))
|
2015-04-21 01:09:50 +02:00
|
|
|
return " ".join(ret)
|
|
|
|
|
|
|
|
|
|
|
|
def extract_pubkey():
|
|
|
|
global repo_pubkey_fingerprint
|
|
|
|
if 'repo_pubkey' in config:
|
|
|
|
pubkey = unhexlify(config['repo_pubkey'])
|
|
|
|
else:
|
2016-01-04 19:02:21 +01:00
|
|
|
p = FDroidPopenBytes([config['keytool'], '-exportcert',
|
|
|
|
'-alias', config['repo_keyalias'],
|
|
|
|
'-keystore', config['keystore'],
|
|
|
|
'-storepass:file', config['keystorepassfile']]
|
|
|
|
+ config['smartcardoptions'],
|
|
|
|
output=False, stderr_to_stdout=False)
|
2015-04-21 01:09:50 +02:00
|
|
|
if p.returncode != 0 or len(p.output) < 20:
|
|
|
|
msg = "Failed to get repo pubkey!"
|
|
|
|
if config['keystore'] == 'NONE':
|
|
|
|
msg += ' Is your crypto smartcard plugged in?'
|
|
|
|
logging.critical(msg)
|
|
|
|
sys.exit(1)
|
|
|
|
pubkey = p.output
|
|
|
|
repo_pubkey_fingerprint = cert_fingerprint(pubkey)
|
|
|
|
return hexlify(pubkey)
|
|
|
|
|
|
|
|
|
2017-02-10 18:38:25 +01:00
|
|
|
# Get raw URL from git service for mirroring
|
|
|
|
def get_raw_mirror(url):
|
|
|
|
# Divide urls in parts
|
|
|
|
url = url.split("/")
|
|
|
|
|
|
|
|
# Get the hostname
|
|
|
|
hostname = url[2]
|
|
|
|
|
|
|
|
# fdroidserver will use always 'master' branch for git-mirroring
|
|
|
|
branch = "master"
|
|
|
|
folder = "fdroid"
|
|
|
|
|
|
|
|
if hostname == "github.com":
|
|
|
|
# Github like RAW url "https://raw.githubusercontent.com/user/repo/master/fdroid"
|
|
|
|
url[2] = "raw.githubusercontent.com"
|
|
|
|
url.extend([branch, folder])
|
|
|
|
elif hostname == "gitlab.com":
|
|
|
|
# Gitlab like RAW url "https://gitlab.com/user/repo/raw/master/fdroid"
|
|
|
|
url.extend(["raw", branch, folder])
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
url = "/".join(url)
|
|
|
|
return url
|
|
|
|
|
|
|
|
|
2016-11-28 15:23:59 +01:00
|
|
|
def make_index(apps, sortedids, apks, repodir, archive):
|
|
|
|
"""Generate the repo index files.
|
2012-07-12 22:48:59 +02:00
|
|
|
|
2013-05-09 21:09:17 +02:00
|
|
|
:param apps: fully populated apps list
|
|
|
|
:param apks: full populated apks list
|
|
|
|
:param repodir: the repo directory
|
|
|
|
:param archive: True if this is the archive repo, False if it's the
|
|
|
|
main one.
|
|
|
|
:param categories: list of categories
|
|
|
|
"""
|
2010-10-22 21:38:54 +02:00
|
|
|
|
2016-11-28 21:09:07 +01:00
|
|
|
def _resolve_description_link(appid):
|
|
|
|
if appid in apps:
|
|
|
|
return ("fdroid.app:" + appid, apps[appid].Name)
|
|
|
|
raise MetaDataException("Cannot resolve app id " + appid)
|
|
|
|
|
|
|
|
nosigningkey = False
|
|
|
|
if not options.nosign:
|
|
|
|
if 'repo_keyalias' not in config:
|
|
|
|
nosigningkey = True
|
|
|
|
logging.critical("'repo_keyalias' not found in config.py!")
|
|
|
|
if 'keystore' not in config:
|
|
|
|
nosigningkey = True
|
|
|
|
logging.critical("'keystore' not found in config.py!")
|
|
|
|
if 'keystorepass' not in config and 'keystorepassfile' not in config:
|
|
|
|
nosigningkey = True
|
|
|
|
logging.critical("'keystorepass' not found in config.py!")
|
|
|
|
if 'keypass' not in config and 'keypassfile' not in config:
|
|
|
|
nosigningkey = True
|
|
|
|
logging.critical("'keypass' not found in config.py!")
|
|
|
|
if not os.path.exists(config['keystore']):
|
|
|
|
nosigningkey = True
|
|
|
|
logging.critical("'" + config['keystore'] + "' does not exist!")
|
|
|
|
if nosigningkey:
|
|
|
|
logging.warning("`fdroid update` requires a signing key, you can create one using:")
|
|
|
|
logging.warning("\tfdroid update --create-key")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
repodict = collections.OrderedDict()
|
|
|
|
repodict['timestamp'] = datetime.utcnow()
|
|
|
|
repodict['version'] = METADATA_VERSION
|
|
|
|
|
|
|
|
if config['repo_maxage'] != 0:
|
|
|
|
repodict['maxage'] = config['repo_maxage']
|
|
|
|
|
|
|
|
if archive:
|
|
|
|
repodict['name'] = config['archive_name']
|
|
|
|
repodict['icon'] = os.path.basename(config['archive_icon'])
|
|
|
|
repodict['address'] = config['archive_url']
|
|
|
|
repodict['description'] = config['archive_description']
|
|
|
|
urlbasepath = os.path.basename(urllib.parse.urlparse(config['archive_url']).path)
|
|
|
|
else:
|
|
|
|
repodict['name'] = config['repo_name']
|
|
|
|
repodict['icon'] = os.path.basename(config['repo_icon'])
|
|
|
|
repodict['address'] = config['repo_url']
|
|
|
|
repodict['description'] = config['repo_description']
|
|
|
|
urlbasepath = os.path.basename(urllib.parse.urlparse(config['repo_url']).path)
|
|
|
|
|
|
|
|
mirrorcheckfailed = False
|
|
|
|
mirrors = []
|
|
|
|
for mirror in sorted(config.get('mirrors', [])):
|
|
|
|
base = os.path.basename(urllib.parse.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
|
|
|
|
# must end with / or urljoin strips a whole path segment
|
|
|
|
if mirror.endswith('/'):
|
|
|
|
mirrors.append(urllib.parse.urljoin(mirror, urlbasepath))
|
|
|
|
else:
|
|
|
|
mirrors.append(urllib.parse.urljoin(mirror + '/', urlbasepath))
|
|
|
|
for mirror in config.get('servergitmirrors', []):
|
|
|
|
mirror = get_raw_mirror(mirror)
|
|
|
|
if mirror is not None:
|
|
|
|
mirrors.append(mirror + '/')
|
|
|
|
if mirrorcheckfailed:
|
|
|
|
sys.exit(1)
|
|
|
|
if mirrors:
|
|
|
|
repodict['mirrors'] = mirrors
|
|
|
|
|
|
|
|
appsWithPackages = collections.OrderedDict()
|
|
|
|
for packageName in sortedids:
|
|
|
|
app = apps[packageName]
|
|
|
|
if app['Disabled']:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# only include apps with packages
|
|
|
|
for apk in apks:
|
|
|
|
if apk['packageName'] == packageName:
|
|
|
|
newapp = copy.copy(app) # update wiki needs unmodified description
|
|
|
|
newapp['Description'] = metadata.description_html(app['Description'],
|
|
|
|
_resolve_description_link)
|
|
|
|
appsWithPackages[packageName] = newapp
|
|
|
|
break
|
|
|
|
|
2016-12-05 21:06:04 +01:00
|
|
|
requestsdict = dict()
|
|
|
|
for command in ('install', 'uninstall'):
|
|
|
|
packageNames = []
|
|
|
|
key = command + '_list'
|
|
|
|
if key in config:
|
|
|
|
if isinstance(config[key], str):
|
|
|
|
packageNames = [config[key]]
|
|
|
|
elif all(isinstance(item, str) for item in config[key]):
|
|
|
|
packageNames = config[key]
|
|
|
|
else:
|
|
|
|
raise TypeError('only accepts strings, lists, and tuples')
|
|
|
|
requestsdict[command] = packageNames
|
2016-11-28 21:09:07 +01:00
|
|
|
|
2016-12-05 21:06:04 +01:00
|
|
|
make_index_v0(appsWithPackages, apks, repodir, repodict, requestsdict)
|
|
|
|
make_index_v1(appsWithPackages, apks, repodir, repodict, requestsdict)
|
2016-11-28 21:09:07 +01:00
|
|
|
|
2016-12-05 21:06:04 +01:00
|
|
|
|
|
|
|
def make_index_v1(apps, packages, repodir, repodict, requestsdict):
|
2016-11-28 21:09:07 +01:00
|
|
|
|
|
|
|
def _index_encoder_default(obj):
|
|
|
|
if isinstance(obj, set):
|
|
|
|
return list(obj)
|
|
|
|
if isinstance(obj, datetime):
|
|
|
|
return int(obj.timestamp() * 1000) # Java expects milliseconds
|
|
|
|
raise TypeError(repr(obj) + " is not JSON serializable")
|
|
|
|
|
|
|
|
output = collections.OrderedDict()
|
|
|
|
output['repo'] = repodict
|
2016-12-05 21:06:04 +01:00
|
|
|
output['requests'] = requestsdict
|
2016-11-28 21:09:07 +01:00
|
|
|
|
|
|
|
appslist = []
|
|
|
|
output['apps'] = appslist
|
|
|
|
for appid, appdict in apps.items():
|
|
|
|
d = collections.OrderedDict()
|
|
|
|
appslist.append(d)
|
|
|
|
for k, v in sorted(appdict.items()):
|
|
|
|
if not v:
|
|
|
|
continue
|
|
|
|
if k in ('builds', 'comments', 'metadatapath',
|
|
|
|
'ArchivePolicy', 'AutoUpdateMode', 'MaintainerNotes',
|
|
|
|
'Provides', 'Repo', 'RepoType', 'RequiresRoot',
|
|
|
|
'UpdateCheckData', 'UpdateCheckIgnore', 'UpdateCheckMode',
|
|
|
|
'UpdateCheckName', 'NoSourceSince', 'VercodeOperation'):
|
|
|
|
continue
|
|
|
|
|
|
|
|
# name things after the App class fields in fdroidclient
|
|
|
|
if k == 'id':
|
|
|
|
k = 'packageName'
|
|
|
|
elif k == 'CurrentVersionCode': # TODO make SuggestedVersionCode the canonical name
|
|
|
|
k = 'suggestedVersionCode'
|
|
|
|
elif k == 'CurrentVersion': # TODO make SuggestedVersionName the canonical name
|
|
|
|
k = 'suggestedVersionName'
|
|
|
|
elif k == 'AutoName':
|
|
|
|
if 'Name' not in apps[appid]:
|
|
|
|
d['name'] = v
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
k = k[:1].lower() + k[1:]
|
|
|
|
d[k] = v
|
|
|
|
|
|
|
|
output_packages = dict()
|
|
|
|
output['packages'] = output_packages
|
|
|
|
for package in packages:
|
|
|
|
packageName = package['packageName']
|
|
|
|
if packageName in output_packages:
|
|
|
|
packagelist = output_packages[packageName]
|
|
|
|
else:
|
|
|
|
packagelist = []
|
|
|
|
output_packages[packageName] = packagelist
|
|
|
|
d = collections.OrderedDict()
|
|
|
|
packagelist.append(d)
|
|
|
|
for k, v in sorted(package.items()):
|
|
|
|
if not v:
|
|
|
|
continue
|
|
|
|
if k in ('icon', 'icons', 'icons_src', 'name', ):
|
|
|
|
continue
|
|
|
|
d[k] = v
|
|
|
|
|
|
|
|
json_name = 'index-v1.json'
|
|
|
|
index_file = os.path.join(repodir, json_name)
|
|
|
|
with open(index_file, 'w') as fp:
|
|
|
|
json.dump(output, fp, default=_index_encoder_default)
|
|
|
|
|
|
|
|
if options.nosign:
|
2017-03-16 18:51:43 +01:00
|
|
|
logging.debug('index-v1 must have a signature, use `fdroid signindex` to create it!')
|
|
|
|
else:
|
|
|
|
common.sign_index_v1(repodir, json_name)
|
2016-11-28 21:09:07 +01:00
|
|
|
|
|
|
|
|
2016-12-05 21:06:04 +01:00
|
|
|
def make_index_v0(apps, apks, repodir, repodict, requestsdict):
|
2016-11-28 21:09:07 +01:00
|
|
|
'''aka index.jar aka index.xml'''
|
|
|
|
|
2012-02-26 15:18:58 +01:00
|
|
|
doc = Document()
|
|
|
|
|
|
|
|
def addElement(name, value, doc, parent):
|
|
|
|
el = doc.createElement(name)
|
|
|
|
el.appendChild(doc.createTextNode(value))
|
|
|
|
parent.appendChild(el)
|
2014-05-02 05:41:44 +02:00
|
|
|
|
2015-06-28 20:45:06 +02:00
|
|
|
def addElementNonEmpty(name, value, doc, parent):
|
2015-06-26 17:41:19 +02:00
|
|
|
if not value:
|
|
|
|
return
|
2015-06-28 20:45:06 +02:00
|
|
|
addElement(name, value, doc, parent)
|
|
|
|
|
2016-10-13 18:02:44 +02:00
|
|
|
def addElementIfInApk(name, apk, key, doc, parent):
|
|
|
|
if key not in apk:
|
|
|
|
return
|
|
|
|
value = str(apk[key])
|
|
|
|
addElement(name, value, doc, parent)
|
|
|
|
|
2015-06-28 20:45:06 +02:00
|
|
|
def addElementCDATA(name, value, doc, parent):
|
2012-09-17 22:49:56 +02:00
|
|
|
el = doc.createElement(name)
|
|
|
|
el.appendChild(doc.createCDATASection(value))
|
|
|
|
parent.appendChild(el)
|
2012-02-26 15:18:58 +01:00
|
|
|
|
|
|
|
root = doc.createElement("fdroid")
|
|
|
|
doc.appendChild(root)
|
|
|
|
|
|
|
|
repoel = doc.createElement("repo")
|
2014-01-03 20:49:20 +01:00
|
|
|
|
2016-11-28 21:09:07 +01:00
|
|
|
repoel.setAttribute("name", repodict['name'])
|
|
|
|
if 'maxage' in repodict:
|
|
|
|
repoel.setAttribute("maxage", str(repodict['maxage']))
|
|
|
|
repoel.setAttribute("icon", os.path.basename(repodict['icon']))
|
|
|
|
repoel.setAttribute("url", repodict['address'])
|
|
|
|
addElement('description', repodict['description'], doc, repoel)
|
|
|
|
for mirror in repodict.get('mirrors', []):
|
|
|
|
addElement('mirror', mirror, doc, repoel)
|
2016-02-16 23:43:23 +01:00
|
|
|
|
2016-11-28 21:09:07 +01:00
|
|
|
repoel.setAttribute("version", str(repodict['version']))
|
|
|
|
repoel.setAttribute("timestamp", '%d' % repodict['timestamp'].timestamp())
|
2015-04-21 01:09:50 +02:00
|
|
|
|
2016-01-04 21:10:18 +01:00
|
|
|
repoel.setAttribute("pubkey", extract_pubkey().decode('utf-8'))
|
2012-02-26 15:18:58 +01:00
|
|
|
root.appendChild(repoel)
|
|
|
|
|
2016-08-23 20:30:27 +02:00
|
|
|
for command in ('install', 'uninstall'):
|
2016-12-05 21:06:04 +01:00
|
|
|
for packageName in requestsdict[command]:
|
2016-08-16 21:02:15 +02:00
|
|
|
element = doc.createElement(command)
|
|
|
|
root.appendChild(element)
|
|
|
|
element.setAttribute('packageName', packageName)
|
|
|
|
|
2016-11-28 21:09:07 +01:00
|
|
|
for appid, appdict in apps.items():
|
|
|
|
app = metadata.App(appdict)
|
2010-10-22 21:38:54 +02:00
|
|
|
|
2015-11-28 13:09:47 +01:00
|
|
|
if app.Disabled is not None:
|
2013-10-10 16:45:17 +02:00
|
|
|
continue
|
2012-02-26 15:18:58 +01:00
|
|
|
|
2013-10-10 16:45:17 +02:00
|
|
|
# Get a list of the apks for this app...
|
|
|
|
apklist = []
|
|
|
|
for apk in apks:
|
2016-11-29 13:40:21 +01:00
|
|
|
if apk['packageName'] == appid:
|
2013-10-10 16:45:17 +02:00
|
|
|
apklist.append(apk)
|
|
|
|
|
|
|
|
if len(apklist) == 0:
|
|
|
|
continue
|
|
|
|
|
|
|
|
apel = doc.createElement("application")
|
2015-11-28 13:09:47 +01:00
|
|
|
apel.setAttribute("id", app.id)
|
2013-10-10 16:45:17 +02:00
|
|
|
root.appendChild(apel)
|
|
|
|
|
2015-11-28 13:09:47 +01:00
|
|
|
addElement('id', app.id, doc, apel)
|
|
|
|
if app.added:
|
2016-11-28 21:10:58 +01:00
|
|
|
addElement('added', app.added.strftime('%Y-%m-%d'), doc, apel)
|
2016-11-28 21:17:22 +01:00
|
|
|
if app.lastUpdated:
|
2016-11-28 21:10:58 +01:00
|
|
|
addElement('lastupdated', app.lastUpdated.strftime('%Y-%m-%d'), doc, apel)
|
2015-11-28 13:09:47 +01:00
|
|
|
addElement('name', app.Name, doc, apel)
|
|
|
|
addElement('summary', app.Summary, doc, apel)
|
|
|
|
if app.icon:
|
|
|
|
addElement('icon', app.icon, doc, apel)
|
2014-05-02 05:41:44 +02:00
|
|
|
|
2016-11-25 15:29:37 +01:00
|
|
|
if app.get('Description'):
|
|
|
|
description = app.Description
|
|
|
|
else:
|
2016-11-28 21:09:07 +01:00
|
|
|
description = '<p>No description available</p>'
|
|
|
|
addElement('desc', description, doc, apel)
|
2015-11-28 13:09:47 +01:00
|
|
|
addElement('license', app.License, doc, apel)
|
|
|
|
if app.Categories:
|
|
|
|
addElement('categories', ','.join(app.Categories), doc, apel)
|
2013-10-10 16:45:17 +02:00
|
|
|
# We put the first (primary) category in LAST, which will have
|
|
|
|
# the desired effect of making clients that only understand one
|
|
|
|
# category see that one.
|
2015-11-28 13:09:47 +01:00
|
|
|
addElement('category', app.Categories[0], doc, apel)
|
|
|
|
addElement('web', app.WebSite, doc, apel)
|
|
|
|
addElement('source', app.SourceCode, doc, apel)
|
|
|
|
addElement('tracker', app.IssueTracker, doc, apel)
|
|
|
|
addElementNonEmpty('changelog', app.Changelog, doc, apel)
|
2016-01-03 20:49:36 +01:00
|
|
|
addElementNonEmpty('author', app.AuthorName, doc, apel)
|
|
|
|
addElementNonEmpty('email', app.AuthorEmail, doc, apel)
|
2015-11-28 13:09:47 +01:00
|
|
|
addElementNonEmpty('donate', app.Donate, doc, apel)
|
|
|
|
addElementNonEmpty('bitcoin', app.Bitcoin, doc, apel)
|
|
|
|
addElementNonEmpty('litecoin', app.Litecoin, doc, apel)
|
|
|
|
addElementNonEmpty('flattr', app.FlattrID, doc, apel)
|
2013-10-10 16:45:17 +02:00
|
|
|
|
|
|
|
# These elements actually refer to the current version (i.e. which
|
|
|
|
# one is recommended. They are historically mis-named, and need
|
|
|
|
# changing, but stay like this for now to support existing clients.
|
2015-11-28 13:09:47 +01:00
|
|
|
addElement('marketversion', app.CurrentVersion, doc, apel)
|
|
|
|
addElement('marketvercode', app.CurrentVersionCode, doc, apel)
|
2013-10-10 16:45:17 +02:00
|
|
|
|
2015-11-28 13:09:47 +01:00
|
|
|
if app.Provides:
|
|
|
|
pv = app.Provides.split(',')
|
2015-06-28 20:45:06 +02:00
|
|
|
addElementNonEmpty('provides', ','.join(pv), doc, apel)
|
2015-11-28 13:09:47 +01:00
|
|
|
if app.RequiresRoot:
|
2013-10-25 17:19:23 +02:00
|
|
|
addElement('requirements', 'root', doc, apel)
|
2013-10-10 16:45:17 +02:00
|
|
|
|
|
|
|
# Sort the apk list into version order, just so the web site
|
|
|
|
# doesn't have to do any work by default...
|
2016-11-29 13:40:21 +01:00
|
|
|
apklist = sorted(apklist, key=lambda apk: apk['versionCode'], reverse=True)
|
2013-10-10 16:45:17 +02:00
|
|
|
|
2016-11-03 14:14:08 +01:00
|
|
|
if 'antiFeatures' in apklist[0]:
|
|
|
|
app.AntiFeatures.extend(apklist[0]['antiFeatures'])
|
|
|
|
if app.AntiFeatures:
|
|
|
|
addElementNonEmpty('antifeatures', ','.join(app.AntiFeatures), doc, apel)
|
|
|
|
|
2013-10-10 16:45:17 +02:00
|
|
|
# Check for duplicates - they will make the client unhappy...
|
|
|
|
for i in range(len(apklist) - 1):
|
2016-11-29 13:40:21 +01:00
|
|
|
if apklist[i]['versionCode'] == apklist[i + 1]['versionCode']:
|
2014-01-27 16:56:55 +01:00
|
|
|
logging.critical("duplicate versions: '%s' - '%s'" % (
|
2016-11-29 13:40:21 +01:00
|
|
|
apklist[i]['apkName'], apklist[i + 1]['apkName']))
|
2013-10-10 16:45:17 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
static URLs to "Current Version" of each app
I wrote up the feature to automatically generate symlinks with a constant name
that points to the current release version. I have it on by default, with a
*config.py* option to turn it off. There is also an option to set where the
symlink name comes from which defaults to app['Name'] i.e. F-Droid.apk, but
can easily be set to app['id'], i.e. _org.fdroid.fdroid.apk_. I think the best
place for the symlinks is in the root of the repo, so like
https://f-droid.org/F-Droid.apk or https://guardianproject.info/fdroid/ChatSecure.apk
For the case of the current FDroid static link https://f-droid.org/FDroid.apk
it can just be a symlink to the generated one (https://f-droid.org/F-Droid.apk
or https://f-droid.org/org.fdroid.fdroid.apk). Right now, this feature is all
or nothing, meaning it generates symlinks for all apps in the repo, or none. I
can’t think of any problems that this might cause since its only symlinks, so
the amount of disk space is tiny. Also, I think it would be useful for having
an easy “Download this app” button on each app’s page on the “Browse” view. As
long as this button is less prominent than the “Download F-Droid” button, and
it is clear that it is better to use the FDroid app than doing direct
downloads. For the f-droid.org repo, the symlinks should probably be based on
app['id'] to prevent name conflicts.
more info here:
https://f-droid.org/forums/topic/static-urls-to-current-version-of-each-app/
2014-10-11 02:47:21 +02:00
|
|
|
current_version_code = 0
|
|
|
|
current_version_file = None
|
2013-10-10 16:45:17 +02:00
|
|
|
for apk in apklist:
|
2016-11-29 13:40:21 +01:00
|
|
|
file_extension = common.get_file_extension(apk['apkName'])
|
static URLs to "Current Version" of each app
I wrote up the feature to automatically generate symlinks with a constant name
that points to the current release version. I have it on by default, with a
*config.py* option to turn it off. There is also an option to set where the
symlink name comes from which defaults to app['Name'] i.e. F-Droid.apk, but
can easily be set to app['id'], i.e. _org.fdroid.fdroid.apk_. I think the best
place for the symlinks is in the root of the repo, so like
https://f-droid.org/F-Droid.apk or https://guardianproject.info/fdroid/ChatSecure.apk
For the case of the current FDroid static link https://f-droid.org/FDroid.apk
it can just be a symlink to the generated one (https://f-droid.org/F-Droid.apk
or https://f-droid.org/org.fdroid.fdroid.apk). Right now, this feature is all
or nothing, meaning it generates symlinks for all apps in the repo, or none. I
can’t think of any problems that this might cause since its only symlinks, so
the amount of disk space is tiny. Also, I think it would be useful for having
an easy “Download this app” button on each app’s page on the “Browse” view. As
long as this button is less prominent than the “Download F-Droid” button, and
it is clear that it is better to use the FDroid app than doing direct
downloads. For the f-droid.org repo, the symlinks should probably be based on
app['id'] to prevent name conflicts.
more info here:
https://f-droid.org/forums/topic/static-urls-to-current-version-of-each-app/
2014-10-11 02:47:21 +02:00
|
|
|
# find the APK for the "Current Version"
|
2016-11-29 13:40:21 +01:00
|
|
|
if current_version_code < apk['versionCode']:
|
|
|
|
current_version_code = apk['versionCode']
|
2015-11-28 13:09:47 +01:00
|
|
|
if current_version_code < int(app.CurrentVersionCode):
|
2016-11-29 13:40:21 +01:00
|
|
|
current_version_file = apk['apkName']
|
static URLs to "Current Version" of each app
I wrote up the feature to automatically generate symlinks with a constant name
that points to the current release version. I have it on by default, with a
*config.py* option to turn it off. There is also an option to set where the
symlink name comes from which defaults to app['Name'] i.e. F-Droid.apk, but
can easily be set to app['id'], i.e. _org.fdroid.fdroid.apk_. I think the best
place for the symlinks is in the root of the repo, so like
https://f-droid.org/F-Droid.apk or https://guardianproject.info/fdroid/ChatSecure.apk
For the case of the current FDroid static link https://f-droid.org/FDroid.apk
it can just be a symlink to the generated one (https://f-droid.org/F-Droid.apk
or https://f-droid.org/org.fdroid.fdroid.apk). Right now, this feature is all
or nothing, meaning it generates symlinks for all apps in the repo, or none. I
can’t think of any problems that this might cause since its only symlinks, so
the amount of disk space is tiny. Also, I think it would be useful for having
an easy “Download this app” button on each app’s page on the “Browse” view. As
long as this button is less prominent than the “Download F-Droid” button, and
it is clear that it is better to use the FDroid app than doing direct
downloads. For the f-droid.org repo, the symlinks should probably be based on
app['id'] to prevent name conflicts.
more info here:
https://f-droid.org/forums/topic/static-urls-to-current-version-of-each-app/
2014-10-11 02:47:21 +02:00
|
|
|
|
2013-10-10 16:45:17 +02:00
|
|
|
apkel = doc.createElement("package")
|
|
|
|
apel.appendChild(apkel)
|
2016-11-29 13:40:21 +01:00
|
|
|
addElement('version', apk['versionName'], doc, apkel)
|
|
|
|
addElement('versioncode', str(apk['versionCode']), doc, apkel)
|
|
|
|
addElement('apkname', apk['apkName'], doc, apkel)
|
2016-10-13 18:02:44 +02:00
|
|
|
addElementIfInApk('srcname', apk, 'srcname', doc, apkel)
|
2016-11-29 13:40:21 +01:00
|
|
|
|
|
|
|
hashel = doc.createElement("hash")
|
|
|
|
hashel.setAttribute('type', 'sha256')
|
|
|
|
hashel.appendChild(doc.createTextNode(apk['hash']))
|
|
|
|
apkel.appendChild(hashel)
|
|
|
|
|
2013-10-10 16:45:17 +02:00
|
|
|
addElement('size', str(apk['size']), doc, apkel)
|
2016-12-08 19:30:38 +01:00
|
|
|
addElementIfInApk('sdkver', apk,
|
|
|
|
'minSdkVersion', doc, apkel)
|
2016-10-13 18:02:44 +02:00
|
|
|
addElementIfInApk('targetSdkVersion', apk,
|
|
|
|
'targetSdkVersion', doc, apkel)
|
|
|
|
addElementIfInApk('maxsdkver', apk,
|
|
|
|
'maxSdkVersion', doc, apkel)
|
|
|
|
addElementIfInApk('obbMainFile', apk,
|
|
|
|
'obbMainFile', doc, apkel)
|
|
|
|
addElementIfInApk('obbMainFileSha256', apk,
|
|
|
|
'obbMainFileSha256', doc, apkel)
|
|
|
|
addElementIfInApk('obbPatchFile', apk,
|
|
|
|
'obbPatchFile', doc, apkel)
|
|
|
|
addElementIfInApk('obbPatchFileSha256', apk,
|
|
|
|
'obbPatchFileSha256', doc, apkel)
|
2013-10-10 16:45:17 +02:00
|
|
|
if 'added' in apk:
|
2016-11-28 21:10:58 +01:00
|
|
|
addElement('added', apk['added'].strftime('%Y-%m-%d'), doc, apkel)
|
2016-07-30 23:12:52 +02:00
|
|
|
|
2016-10-13 18:24:58 +02:00
|
|
|
if file_extension == 'apk': # sig is required for APKs, but only APKs
|
|
|
|
addElement('sig', apk['sig'], doc, apkel)
|
|
|
|
|
|
|
|
old_permissions = set()
|
2016-11-29 15:55:07 +01:00
|
|
|
sorted_permissions = sorted(apk['uses-permission'])
|
|
|
|
for perm in sorted_permissions:
|
2016-10-13 18:24:58 +02:00
|
|
|
perm_name = perm.name
|
|
|
|
if perm_name.startswith("android.permission."):
|
|
|
|
perm_name = perm_name[19:]
|
|
|
|
old_permissions.add(perm_name)
|
|
|
|
addElementNonEmpty('permissions', ','.join(old_permissions), doc, apkel)
|
|
|
|
|
2016-11-29 15:55:07 +01:00
|
|
|
for permission in sorted_permissions:
|
2016-10-13 18:24:58 +02:00
|
|
|
permel = doc.createElement('uses-permission')
|
|
|
|
permel.setAttribute('name', permission.name)
|
|
|
|
if permission.maxSdkVersion is not None:
|
2016-11-29 21:04:27 +01:00
|
|
|
permel.setAttribute('maxSdkVersion', '%d' % permission.maxSdkVersion)
|
2016-10-13 18:24:58 +02:00
|
|
|
apkel.appendChild(permel)
|
2016-11-29 15:55:07 +01:00
|
|
|
for permission_sdk_23 in sorted(apk['uses-permission-sdk-23']):
|
2016-10-13 18:24:58 +02:00
|
|
|
permel = doc.createElement('uses-permission-sdk-23')
|
|
|
|
permel.setAttribute('name', permission_sdk_23.name)
|
|
|
|
if permission_sdk_23.maxSdkVersion is not None:
|
2016-11-29 21:04:27 +01:00
|
|
|
permel.setAttribute('maxSdkVersion', '%d' % permission_sdk_23.maxSdkVersion)
|
2016-10-13 18:24:58 +02:00
|
|
|
apkel.appendChild(permel)
|
|
|
|
if 'nativecode' in apk:
|
2016-11-29 15:55:07 +01:00
|
|
|
addElement('nativecode', ','.join(sorted(apk['nativecode'])), doc, apkel)
|
|
|
|
addElementNonEmpty('features', ','.join(sorted(apk['features'])), doc, apkel)
|
2012-02-26 15:18:58 +01:00
|
|
|
|
static URLs to "Current Version" of each app
I wrote up the feature to automatically generate symlinks with a constant name
that points to the current release version. I have it on by default, with a
*config.py* option to turn it off. There is also an option to set where the
symlink name comes from which defaults to app['Name'] i.e. F-Droid.apk, but
can easily be set to app['id'], i.e. _org.fdroid.fdroid.apk_. I think the best
place for the symlinks is in the root of the repo, so like
https://f-droid.org/F-Droid.apk or https://guardianproject.info/fdroid/ChatSecure.apk
For the case of the current FDroid static link https://f-droid.org/FDroid.apk
it can just be a symlink to the generated one (https://f-droid.org/F-Droid.apk
or https://f-droid.org/org.fdroid.fdroid.apk). Right now, this feature is all
or nothing, meaning it generates symlinks for all apps in the repo, or none. I
can’t think of any problems that this might cause since its only symlinks, so
the amount of disk space is tiny. Also, I think it would be useful for having
an easy “Download this app” button on each app’s page on the “Browse” view. As
long as this button is less prominent than the “Download F-Droid” button, and
it is clear that it is better to use the FDroid app than doing direct
downloads. For the f-droid.org repo, the symlinks should probably be based on
app['id'] to prevent name conflicts.
more info here:
https://f-droid.org/forums/topic/static-urls-to-current-version-of-each-app/
2014-10-11 02:47:21 +02:00
|
|
|
if current_version_file is not None \
|
|
|
|
and config['make_current_version_link'] \
|
|
|
|
and repodir == 'repo': # only create these
|
2015-11-28 13:09:47 +01:00
|
|
|
namefield = config['current_version_name_source']
|
2016-11-23 17:25:59 +01:00
|
|
|
sanitized_name = re.sub('''[ '"&%?+=/]''', '', app.get(namefield))
|
2014-10-11 03:12:48 +02:00
|
|
|
apklinkname = sanitized_name + '.apk'
|
2014-10-11 02:54:32 +02:00
|
|
|
current_version_path = os.path.join(repodir, current_version_file)
|
2015-10-01 02:04:00 +02:00
|
|
|
if os.path.islink(apklinkname):
|
static URLs to "Current Version" of each app
I wrote up the feature to automatically generate symlinks with a constant name
that points to the current release version. I have it on by default, with a
*config.py* option to turn it off. There is also an option to set where the
symlink name comes from which defaults to app['Name'] i.e. F-Droid.apk, but
can easily be set to app['id'], i.e. _org.fdroid.fdroid.apk_. I think the best
place for the symlinks is in the root of the repo, so like
https://f-droid.org/F-Droid.apk or https://guardianproject.info/fdroid/ChatSecure.apk
For the case of the current FDroid static link https://f-droid.org/FDroid.apk
it can just be a symlink to the generated one (https://f-droid.org/F-Droid.apk
or https://f-droid.org/org.fdroid.fdroid.apk). Right now, this feature is all
or nothing, meaning it generates symlinks for all apps in the repo, or none. I
can’t think of any problems that this might cause since its only symlinks, so
the amount of disk space is tiny. Also, I think it would be useful for having
an easy “Download this app” button on each app’s page on the “Browse” view. As
long as this button is less prominent than the “Download F-Droid” button, and
it is clear that it is better to use the FDroid app than doing direct
downloads. For the f-droid.org repo, the symlinks should probably be based on
app['id'] to prevent name conflicts.
more info here:
https://f-droid.org/forums/topic/static-urls-to-current-version-of-each-app/
2014-10-11 02:47:21 +02:00
|
|
|
os.remove(apklinkname)
|
2014-10-11 02:54:32 +02:00
|
|
|
os.symlink(current_version_path, apklinkname)
|
|
|
|
# also symlink gpg signature, if it exists
|
|
|
|
for extension in ('.asc', '.sig'):
|
|
|
|
sigfile_path = current_version_path + extension
|
|
|
|
if os.path.exists(sigfile_path):
|
|
|
|
siglinkname = apklinkname + extension
|
2015-10-01 02:04:00 +02:00
|
|
|
if os.path.islink(siglinkname):
|
2014-10-11 02:54:32 +02:00
|
|
|
os.remove(siglinkname)
|
|
|
|
os.symlink(sigfile_path, siglinkname)
|
static URLs to "Current Version" of each app
I wrote up the feature to automatically generate symlinks with a constant name
that points to the current release version. I have it on by default, with a
*config.py* option to turn it off. There is also an option to set where the
symlink name comes from which defaults to app['Name'] i.e. F-Droid.apk, but
can easily be set to app['id'], i.e. _org.fdroid.fdroid.apk_. I think the best
place for the symlinks is in the root of the repo, so like
https://f-droid.org/F-Droid.apk or https://guardianproject.info/fdroid/ChatSecure.apk
For the case of the current FDroid static link https://f-droid.org/FDroid.apk
it can just be a symlink to the generated one (https://f-droid.org/F-Droid.apk
or https://f-droid.org/org.fdroid.fdroid.apk). Right now, this feature is all
or nothing, meaning it generates symlinks for all apps in the repo, or none. I
can’t think of any problems that this might cause since its only symlinks, so
the amount of disk space is tiny. Also, I think it would be useful for having
an easy “Download this app” button on each app’s page on the “Browse” view. As
long as this button is less prominent than the “Download F-Droid” button, and
it is clear that it is better to use the FDroid app than doing direct
downloads. For the f-droid.org repo, the symlinks should probably be based on
app['id'] to prevent name conflicts.
more info here:
https://f-droid.org/forums/topic/static-urls-to-current-version-of-each-app/
2014-10-11 02:47:21 +02:00
|
|
|
|
2012-02-26 15:18:58 +01:00
|
|
|
if options.pretty:
|
2016-01-04 21:10:18 +01:00
|
|
|
output = doc.toprettyxml(encoding='utf-8')
|
2010-10-22 21:38:54 +02:00
|
|
|
else:
|
2016-01-04 21:10:18 +01:00
|
|
|
output = doc.toxml(encoding='utf-8')
|
2015-08-29 03:37:23 +02:00
|
|
|
|
|
|
|
with open(os.path.join(repodir, 'index.xml'), 'wb') as f:
|
|
|
|
f.write(output)
|
2012-02-26 15:18:58 +01:00
|
|
|
|
2014-04-04 03:44:40 +02:00
|
|
|
if 'repo_keyalias' in config:
|
2012-02-26 15:18:58 +01:00
|
|
|
|
2015-01-10 17:35:12 +01:00
|
|
|
if options.nosign:
|
|
|
|
logging.info("Creating unsigned index in preparation for signing")
|
|
|
|
else:
|
|
|
|
logging.info("Creating signed index with this key (SHA256):")
|
|
|
|
logging.info("%s" % repo_pubkey_fingerprint)
|
2013-12-30 17:04:16 +01:00
|
|
|
|
2014-05-07 16:13:22 +02:00
|
|
|
# Create a jar of the index...
|
2015-01-10 17:35:12 +01:00
|
|
|
jar_output = 'index_unsigned.jar' if options.nosign else 'index.jar'
|
|
|
|
p = FDroidPopen(['jar', 'cf', jar_output, 'index.xml'], cwd=repodir)
|
2012-02-26 15:18:58 +01:00
|
|
|
if p.returncode != 0:
|
2015-01-10 17:35:12 +01:00
|
|
|
logging.critical("Failed to create {0}".format(jar_output))
|
2012-02-26 15:18:58 +01:00
|
|
|
sys.exit(1)
|
2011-01-29 10:32:21 +01:00
|
|
|
|
2012-02-26 15:18:58 +01:00
|
|
|
# Sign the index...
|
2015-01-10 17:35:12 +01:00
|
|
|
signed = os.path.join(repodir, 'index.jar')
|
|
|
|
if options.nosign:
|
|
|
|
# Remove old signed index if not signing
|
|
|
|
if os.path.exists(signed):
|
|
|
|
os.remove(signed)
|
|
|
|
else:
|
2017-03-15 21:23:44 +01:00
|
|
|
common.signjar(signed)
|
2012-02-26 15:18:58 +01:00
|
|
|
|
|
|
|
# Copy the repo icon into the repo directory...
|
2014-05-02 04:06:59 +02:00
|
|
|
icon_dir = os.path.join(repodir, 'icons')
|
2013-10-31 16:37:39 +01:00
|
|
|
iconfilename = os.path.join(icon_dir, os.path.basename(config['repo_icon']))
|
|
|
|
shutil.copyfile(config['repo_icon'], iconfilename)
|
2012-02-26 15:18:58 +01:00
|
|
|
|
2016-11-28 15:23:59 +01:00
|
|
|
|
|
|
|
def make_categories_txt(repodir, categories):
|
|
|
|
'''Write a category list in the repo to allow quick access'''
|
2012-02-26 15:18:58 +01:00
|
|
|
catdata = ''
|
2016-11-29 15:55:07 +01:00
|
|
|
for cat in sorted(categories):
|
2012-02-26 15:18:58 +01:00
|
|
|
catdata += cat + '\n'
|
2016-06-07 13:35:13 +02:00
|
|
|
with open(os.path.join(repodir, 'categories.txt'), 'w', encoding='utf8') as f:
|
2015-08-29 03:37:23 +02:00
|
|
|
f.write(catdata)
|
2012-02-26 15:18:58 +01:00
|
|
|
|
2013-05-09 21:09:17 +02:00
|
|
|
|
2014-01-09 13:33:48 +01:00
|
|
|
def archive_old_apks(apps, apks, archapks, repodir, archivedir, defaultkeepversions):
|
2013-05-09 21:09:17 +02:00
|
|
|
|
2016-01-04 17:02:28 +01:00
|
|
|
for appid, app in apps.items():
|
2013-05-09 21:09:17 +02:00
|
|
|
|
2015-11-28 13:09:47 +01:00
|
|
|
if app.ArchivePolicy:
|
|
|
|
keepversions = int(app.ArchivePolicy[:-9])
|
2013-10-14 17:16:34 +02:00
|
|
|
else:
|
|
|
|
keepversions = defaultkeepversions
|
|
|
|
|
2015-09-30 21:33:01 +02:00
|
|
|
def filter_apk_list_sorted(apk_list):
|
|
|
|
res = []
|
|
|
|
for apk in apk_list:
|
2016-11-29 13:40:21 +01:00
|
|
|
if apk['packageName'] == appid:
|
2015-09-30 21:33:01 +02:00
|
|
|
res.append(apk)
|
|
|
|
|
|
|
|
# Sort the apk list by version code. First is highest/newest.
|
2016-11-29 13:40:21 +01:00
|
|
|
return sorted(res, key=lambda apk: apk['versionCode'], reverse=True)
|
2015-09-30 21:33:01 +02:00
|
|
|
|
|
|
|
def move_file(from_dir, to_dir, filename, ignore_missing):
|
|
|
|
from_path = os.path.join(from_dir, filename)
|
|
|
|
if ignore_missing and not os.path.exists(from_path):
|
|
|
|
return
|
|
|
|
to_path = os.path.join(to_dir, filename)
|
|
|
|
shutil.move(from_path, to_path)
|
|
|
|
|
2016-05-29 16:36:58 +02:00
|
|
|
logging.debug("Checking archiving for {0} - apks:{1}, keepversions:{2}, archapks:{3}"
|
|
|
|
.format(appid, len(apks), keepversions, len(archapks)))
|
|
|
|
|
2015-09-30 21:33:01 +02:00
|
|
|
if len(apks) > keepversions:
|
|
|
|
apklist = filter_apk_list_sorted(apks)
|
|
|
|
# Move back the ones we don't want.
|
2013-05-09 21:09:17 +02:00
|
|
|
for apk in apklist[keepversions:]:
|
2016-11-29 13:40:21 +01:00
|
|
|
logging.info("Moving " + apk['apkName'] + " to archive")
|
|
|
|
move_file(repodir, archivedir, apk['apkName'], False)
|
|
|
|
move_file(repodir, archivedir, apk['apkName'] + '.asc', True)
|
2015-11-27 00:13:30 +01:00
|
|
|
for density in all_screen_densities:
|
|
|
|
repo_icon_dir = get_icon_dir(repodir, density)
|
|
|
|
archive_icon_dir = get_icon_dir(archivedir, density)
|
|
|
|
if density not in apk['icons']:
|
|
|
|
continue
|
|
|
|
move_file(repo_icon_dir, archive_icon_dir, apk['icons'][density], True)
|
2013-05-09 21:09:17 +02:00
|
|
|
if 'srcname' in apk:
|
2015-09-30 21:33:01 +02:00
|
|
|
move_file(repodir, archivedir, apk['srcname'], False)
|
2014-01-09 13:33:48 +01:00
|
|
|
archapks.append(apk)
|
2013-05-09 21:09:17 +02:00
|
|
|
apks.remove(apk)
|
2015-09-30 21:33:01 +02:00
|
|
|
elif len(apks) < keepversions and len(archapks) > 0:
|
|
|
|
required = keepversions - len(apks)
|
|
|
|
archapklist = filter_apk_list_sorted(archapks)
|
|
|
|
# Move forward the ones we want again.
|
|
|
|
for apk in archapklist[:required]:
|
2016-11-29 13:40:21 +01:00
|
|
|
logging.info("Moving " + apk['apkName'] + " from archive")
|
|
|
|
move_file(archivedir, repodir, apk['apkName'], False)
|
|
|
|
move_file(archivedir, repodir, apk['apkName'] + '.asc', True)
|
2015-11-27 00:13:30 +01:00
|
|
|
for density in all_screen_densities:
|
|
|
|
repo_icon_dir = get_icon_dir(repodir, density)
|
|
|
|
archive_icon_dir = get_icon_dir(archivedir, density)
|
|
|
|
if density not in apk['icons']:
|
|
|
|
continue
|
|
|
|
move_file(archive_icon_dir, repo_icon_dir, apk['icons'][density], True)
|
2015-09-30 21:33:01 +02:00
|
|
|
if 'srcname' in apk:
|
|
|
|
move_file(archivedir, repodir, apk['srcname'], False)
|
|
|
|
archapks.remove(apk)
|
|
|
|
apks.append(apk)
|
2013-05-09 21:09:17 +02:00
|
|
|
|
|
|
|
|
2015-08-20 17:40:18 +02:00
|
|
|
def add_apks_to_per_app_repos(repodir, apks):
|
|
|
|
apks_per_app = dict()
|
|
|
|
for apk in apks:
|
2016-11-29 13:40:21 +01:00
|
|
|
apk['per_app_dir'] = os.path.join(apk['packageName'], 'fdroid')
|
2015-08-20 17:40:18 +02:00
|
|
|
apk['per_app_repo'] = os.path.join(apk['per_app_dir'], 'repo')
|
|
|
|
apk['per_app_icons'] = os.path.join(apk['per_app_repo'], 'icons')
|
2016-11-29 13:40:21 +01:00
|
|
|
apks_per_app[apk['packageName']] = apk
|
2015-08-20 17:40:18 +02:00
|
|
|
|
|
|
|
if not os.path.exists(apk['per_app_icons']):
|
2016-11-29 13:40:21 +01:00
|
|
|
logging.info('Adding new repo for only ' + apk['packageName'])
|
2015-08-20 17:40:18 +02:00
|
|
|
os.makedirs(apk['per_app_icons'])
|
|
|
|
|
2016-11-29 13:40:21 +01:00
|
|
|
apkpath = os.path.join(repodir, apk['apkName'])
|
2015-08-20 17:40:18 +02:00
|
|
|
shutil.copy(apkpath, apk['per_app_repo'])
|
|
|
|
apksigpath = apkpath + '.sig'
|
|
|
|
if os.path.exists(apksigpath):
|
|
|
|
shutil.copy(apksigpath, apk['per_app_repo'])
|
|
|
|
apkascpath = apkpath + '.asc'
|
|
|
|
if os.path.exists(apkascpath):
|
|
|
|
shutil.copy(apkascpath, apk['per_app_repo'])
|
|
|
|
|
|
|
|
|
2016-12-16 12:19:07 +01:00
|
|
|
def make_binary_transparency_log(repodirs):
|
|
|
|
'''Log the indexes in a standalone git repo to serve as a "binary
|
|
|
|
transparency" log.
|
|
|
|
|
|
|
|
see: https://www.eff.org/deeplinks/2014/02/open-letter-to-tech-companies
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
import git
|
|
|
|
btrepo = 'binary_transparency'
|
|
|
|
if os.path.exists(os.path.join(btrepo, '.git')):
|
|
|
|
gitrepo = git.Repo(btrepo)
|
|
|
|
else:
|
|
|
|
if not os.path.exists(btrepo):
|
|
|
|
os.mkdir(btrepo)
|
|
|
|
gitrepo = git.Repo.init(btrepo)
|
2017-03-16 17:45:10 +01:00
|
|
|
|
|
|
|
gitconfig = gitrepo.config_writer()
|
|
|
|
gitconfig.set_value('user', 'name', 'fdroid update')
|
|
|
|
gitconfig.set_value('user', 'email', 'fdroid@' + platform.node())
|
|
|
|
|
2016-12-16 12:19:07 +01:00
|
|
|
url = config['repo_url'].rstrip('/')
|
|
|
|
with open(os.path.join(btrepo, 'README.md'), 'w') as fp:
|
|
|
|
fp.write("""
|
|
|
|
# Binary Transparency Log for %s
|
|
|
|
|
|
|
|
""" % url[:url.rindex('/')]) # strip '/repo'
|
|
|
|
gitrepo.index.add(['README.md', ])
|
|
|
|
gitrepo.index.commit('add README')
|
|
|
|
|
|
|
|
for repodir in repodirs:
|
|
|
|
cpdir = os.path.join(btrepo, repodir)
|
|
|
|
if not os.path.exists(cpdir):
|
|
|
|
os.mkdir(cpdir)
|
2016-11-28 21:09:07 +01:00
|
|
|
for f in ('index.xml', 'index-v1.json'):
|
2016-12-16 12:19:07 +01:00
|
|
|
dest = os.path.join(cpdir, f)
|
|
|
|
shutil.copyfile(os.path.join(repodir, f), dest)
|
|
|
|
gitrepo.index.add([os.path.join(repodir, f), ])
|
2016-11-28 21:09:07 +01:00
|
|
|
for f in ('index.jar', 'index-v1.jar'):
|
2016-12-16 12:19:07 +01:00
|
|
|
repof = os.path.join(repodir, f)
|
|
|
|
dest = os.path.join(cpdir, f)
|
|
|
|
jarin = zipfile.ZipFile(repof, 'r')
|
|
|
|
jarout = zipfile.ZipFile(dest, 'w')
|
|
|
|
for info in jarin.infolist():
|
|
|
|
if info.filename.startswith('META-INF/'):
|
|
|
|
jarout.writestr(info, jarin.read(info.filename))
|
|
|
|
jarout.close()
|
|
|
|
jarin.close()
|
|
|
|
gitrepo.index.add([repof, ])
|
|
|
|
|
|
|
|
files = []
|
|
|
|
for root, dirs, filenames in os.walk(repodir):
|
|
|
|
for f in filenames:
|
|
|
|
files.append(os.path.relpath(os.path.join(root, f), repodir))
|
|
|
|
output = collections.OrderedDict()
|
|
|
|
for f in sorted(files):
|
|
|
|
repofile = os.path.join(repodir, f)
|
|
|
|
stat = os.stat(repofile)
|
|
|
|
output[f] = (
|
|
|
|
stat.st_size,
|
|
|
|
stat.st_ctime_ns,
|
|
|
|
stat.st_mtime_ns,
|
|
|
|
stat.st_mode,
|
|
|
|
stat.st_uid,
|
|
|
|
stat.st_gid,
|
|
|
|
)
|
|
|
|
fslogfile = os.path.join(cpdir, 'filesystemlog.json')
|
|
|
|
with open(fslogfile, 'w') as fp:
|
|
|
|
json.dump(output, fp, indent=2)
|
|
|
|
gitrepo.index.add([os.path.join(repodir, 'filesystemlog.json'), ])
|
|
|
|
|
|
|
|
gitrepo.index.commit('fdroid update')
|
|
|
|
|
|
|
|
|
2013-11-01 12:10:57 +01:00
|
|
|
config = None
|
2013-10-31 16:37:39 +01:00
|
|
|
options = None
|
|
|
|
|
2014-05-02 05:39:33 +02:00
|
|
|
|
2013-05-09 21:09:17 +02:00
|
|
|
def main():
|
|
|
|
|
2013-11-01 12:10:57 +01:00
|
|
|
global config, options
|
2013-05-09 21:09:17 +02:00
|
|
|
|
|
|
|
# Parse command line...
|
2015-09-04 11:37:05 +02:00
|
|
|
parser = ArgumentParser()
|
2015-09-12 08:42:50 +02:00
|
|
|
common.setup_global_opts(parser)
|
2015-09-04 11:37:05 +02:00
|
|
|
parser.add_argument("--create-key", action="store_true", default=False,
|
|
|
|
help="Create a repo signing key in a keystore")
|
|
|
|
parser.add_argument("-c", "--create-metadata", action="store_true", default=False,
|
|
|
|
help="Create skeleton metadata files that are missing")
|
|
|
|
parser.add_argument("--delete-unknown", action="store_true", default=False,
|
2016-06-16 00:29:17 +02:00
|
|
|
help="Delete APKs and/or OBBs without metadata from the repo")
|
2015-09-04 11:37:05 +02:00
|
|
|
parser.add_argument("-b", "--buildreport", action="store_true", default=False,
|
|
|
|
help="Report on build data status")
|
|
|
|
parser.add_argument("-i", "--interactive", default=False, action="store_true",
|
|
|
|
help="Interactively ask about things that need updating.")
|
|
|
|
parser.add_argument("-I", "--icons", action="store_true", default=False,
|
|
|
|
help="Resize all the icons exceeding the max pixel size and exit")
|
|
|
|
parser.add_argument("-e", "--editor", default="/etc/alternatives/editor",
|
|
|
|
help="Specify editor to use in interactive mode. Default " +
|
|
|
|
"is /etc/alternatives/editor")
|
|
|
|
parser.add_argument("-w", "--wiki", default=False, action="store_true",
|
|
|
|
help="Update the wiki")
|
|
|
|
parser.add_argument("--pretty", action="store_true", default=False,
|
|
|
|
help="Produce human-readable index.xml")
|
|
|
|
parser.add_argument("--clean", action="store_true", default=False,
|
|
|
|
help="Clean update - don't uses caches, reprocess all apks")
|
|
|
|
parser.add_argument("--nosign", action="store_true", default=False,
|
|
|
|
help="When configured for signed indexes, create only unsigned indexes at this stage")
|
2016-02-18 13:41:43 +01:00
|
|
|
parser.add_argument("--use-date-from-apk", action="store_true", default=False,
|
|
|
|
help="Use date from apk instead of current time for newly added apks")
|
2016-09-12 12:55:48 +02:00
|
|
|
metadata.add_metadata_arguments(parser)
|
2015-09-04 11:37:05 +02:00
|
|
|
options = parser.parse_args()
|
2016-09-12 12:55:48 +02:00
|
|
|
metadata.warnings_action = options.W
|
2013-05-09 21:09:17 +02:00
|
|
|
|
2013-11-01 12:10:57 +01:00
|
|
|
config = common.read_config(options)
|
|
|
|
|
2016-02-11 20:43:55 +01:00
|
|
|
if not ('jarsigner' in config and 'keytool' in config):
|
|
|
|
logging.critical('Java JDK not found! Install in standard location or set java_paths!')
|
|
|
|
sys.exit(1)
|
|
|
|
|
2013-08-19 11:30:54 +02:00
|
|
|
repodirs = ['repo']
|
2013-10-31 16:37:39 +01:00
|
|
|
if config['archive_older'] != 0:
|
2013-08-19 11:30:54 +02:00
|
|
|
repodirs.append('archive')
|
|
|
|
if not os.path.exists('archive'):
|
|
|
|
os.mkdir('archive')
|
|
|
|
|
|
|
|
if options.icons:
|
|
|
|
resize_all_icons(repodirs)
|
|
|
|
sys.exit(0)
|
|
|
|
|
2014-06-30 18:19:47 +02:00
|
|
|
# check that icons exist now, rather than fail at the end of `fdroid update`
|
|
|
|
for k in ['repo_icon', 'archive_icon']:
|
|
|
|
if k in config:
|
|
|
|
if not os.path.exists(config[k]):
|
2014-07-01 20:32:49 +02:00
|
|
|
logging.critical(k + ' "' + config[k] + '" does not exist! Correct it in config.py.')
|
2014-06-30 18:19:47 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2015-04-21 03:38:52 +02:00
|
|
|
# if the user asks to create a keystore, do it now, reusing whatever it can
|
|
|
|
if options.create_key:
|
|
|
|
if os.path.exists(config['keystore']):
|
|
|
|
logging.critical("Cowardily refusing to overwrite existing signing key setup!")
|
|
|
|
logging.critical("\t'" + config['keystore'] + "'")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2015-05-22 09:29:51 +02:00
|
|
|
if 'repo_keyalias' not in config:
|
2015-04-21 03:38:52 +02:00
|
|
|
config['repo_keyalias'] = socket.getfqdn()
|
|
|
|
common.write_to_config(config, 'repo_keyalias', config['repo_keyalias'])
|
2015-05-22 09:29:51 +02:00
|
|
|
if 'keydname' not in config:
|
2015-04-21 03:38:52 +02:00
|
|
|
config['keydname'] = 'CN=' + config['repo_keyalias'] + ', OU=F-Droid'
|
|
|
|
common.write_to_config(config, 'keydname', config['keydname'])
|
2015-05-22 09:29:51 +02:00
|
|
|
if 'keystore' not in config:
|
2015-04-21 03:38:52 +02:00
|
|
|
config['keystore'] = common.default_config.keystore
|
|
|
|
common.write_to_config(config, 'keystore', config['keystore'])
|
|
|
|
|
|
|
|
password = common.genpassword()
|
2015-05-22 09:29:51 +02:00
|
|
|
if 'keystorepass' not in config:
|
2015-04-21 03:38:52 +02:00
|
|
|
config['keystorepass'] = password
|
|
|
|
common.write_to_config(config, 'keystorepass', config['keystorepass'])
|
2015-05-22 09:29:51 +02:00
|
|
|
if 'keypass' not in config:
|
2015-04-21 03:38:52 +02:00
|
|
|
config['keypass'] = password
|
|
|
|
common.write_to_config(config, 'keypass', config['keypass'])
|
|
|
|
common.genkeystore(config)
|
|
|
|
|
2013-05-09 21:09:17 +02:00
|
|
|
# Get all apps...
|
2013-11-19 15:35:16 +01:00
|
|
|
apps = metadata.read_metadata()
|
2013-05-09 21:09:17 +02:00
|
|
|
|
|
|
|
# Generate a list of categories...
|
2014-02-19 10:21:13 +01:00
|
|
|
categories = set()
|
2016-01-04 17:43:22 +01:00
|
|
|
for app in apps.values():
|
2015-11-28 13:09:47 +01:00
|
|
|
categories.update(app.Categories)
|
2013-05-09 21:09:17 +02:00
|
|
|
|
|
|
|
# Read known apks data (will be updated and written back when we've finished)
|
|
|
|
knownapks = common.KnownApks()
|
|
|
|
|
|
|
|
# Gather information about all the apk files in the repo directory, using
|
|
|
|
# cached data if possible.
|
|
|
|
apkcachefile = os.path.join('tmp', 'apkcache')
|
|
|
|
if not options.clean and os.path.exists(apkcachefile):
|
|
|
|
with open(apkcachefile, 'rb') as cf:
|
2016-04-08 20:09:49 +02:00
|
|
|
apkcache = pickle.load(cf, encoding='utf-8')
|
2016-06-15 16:34:10 +02:00
|
|
|
if apkcache.get("METADATA_VERSION") != METADATA_VERSION:
|
|
|
|
apkcache = {}
|
2013-05-09 21:09:17 +02:00
|
|
|
else:
|
|
|
|
apkcache = {}
|
|
|
|
|
|
|
|
delete_disabled_builds(apps, apkcache, repodirs)
|
|
|
|
|
2013-11-27 10:35:43 +01:00
|
|
|
# Scan all apks in the main repo
|
2016-10-13 17:28:54 +02:00
|
|
|
apks, cachechanged = scan_apks(apkcache, repodirs[0], knownapks, options.use_date_from_apk)
|
2013-05-09 21:09:17 +02:00
|
|
|
|
2016-10-13 18:24:58 +02:00
|
|
|
files, fcachechanged = scan_repo_files(apkcache, repodirs[0], knownapks,
|
|
|
|
options.use_date_from_apk)
|
|
|
|
cachechanged = cachechanged or fcachechanged
|
|
|
|
apks += files
|
2014-05-29 21:29:57 +02:00
|
|
|
# Generate warnings for apk's with no metadata (or create skeleton
|
|
|
|
# metadata files, if requested on the command line)
|
|
|
|
newmetadata = False
|
|
|
|
for apk in apks:
|
2016-11-29 13:40:21 +01:00
|
|
|
if apk['packageName'] not in apps:
|
2014-05-30 23:07:19 +02:00
|
|
|
if options.create_metadata:
|
2014-06-03 20:18:08 +02:00
|
|
|
if 'name' not in apk:
|
2016-11-29 13:40:21 +01:00
|
|
|
logging.error(apk['packageName'] + ' does not have a name! Skipping...')
|
2014-06-03 20:18:08 +02:00
|
|
|
continue
|
2016-11-29 13:40:21 +01:00
|
|
|
f = open(os.path.join('metadata', apk['packageName'] + '.txt'), 'w', encoding='utf8')
|
2014-05-29 21:29:57 +02:00
|
|
|
f.write("License:Unknown\n")
|
|
|
|
f.write("Web Site:\n")
|
|
|
|
f.write("Source Code:\n")
|
|
|
|
f.write("Issue Tracker:\n")
|
2015-01-11 02:26:41 +01:00
|
|
|
f.write("Changelog:\n")
|
2014-05-29 21:29:57 +02:00
|
|
|
f.write("Summary:" + apk['name'] + "\n")
|
|
|
|
f.write("Description:\n")
|
|
|
|
f.write(apk['name'] + "\n")
|
|
|
|
f.write(".\n")
|
2017-02-19 16:25:49 +01:00
|
|
|
f.write("Name:" + apk['name'] + "\n")
|
2014-05-29 21:29:57 +02:00
|
|
|
f.close()
|
2016-11-29 13:40:21 +01:00
|
|
|
logging.info("Generated skeleton metadata for " + apk['packageName'])
|
2014-05-29 21:29:57 +02:00
|
|
|
newmetadata = True
|
|
|
|
else:
|
2016-11-29 13:40:21 +01:00
|
|
|
msg = apk['apkName'] + " (" + apk['packageName'] + ") has no metadata!"
|
2014-05-29 21:29:57 +02:00
|
|
|
if options.delete_unknown:
|
2016-11-29 13:40:21 +01:00
|
|
|
logging.warn(msg + "\n\tdeleting: repo/" + apk['apkName'])
|
|
|
|
rmf = os.path.join(repodirs[0], apk['apkName'])
|
2014-05-29 21:29:57 +02:00
|
|
|
if not os.path.exists(rmf):
|
|
|
|
logging.error("Could not find {0} to remove it".format(rmf))
|
|
|
|
else:
|
|
|
|
os.remove(rmf)
|
|
|
|
else:
|
|
|
|
logging.warn(msg + "\n\tUse `fdroid update -c` to create it.")
|
|
|
|
|
|
|
|
# update the metadata with the newly created ones included
|
|
|
|
if newmetadata:
|
|
|
|
apps = metadata.read_metadata()
|
|
|
|
|
2016-06-16 00:29:17 +02:00
|
|
|
insert_obbs(repodirs[0], apps, apks)
|
2016-12-06 13:32:34 +01:00
|
|
|
insert_graphics(repodirs[0], apps)
|
2016-06-16 00:29:17 +02:00
|
|
|
|
2013-11-27 10:35:43 +01:00
|
|
|
# Scan the archive repo for apks as well
|
|
|
|
if len(repodirs) > 1:
|
2016-10-13 17:28:54 +02:00
|
|
|
archapks, cc = scan_apks(apkcache, repodirs[1], knownapks, options.use_date_from_apk)
|
2013-11-27 10:35:43 +01:00
|
|
|
if cc:
|
|
|
|
cachechanged = True
|
|
|
|
else:
|
|
|
|
archapks = []
|
|
|
|
|
2016-10-13 16:50:31 +02:00
|
|
|
# less than the valid range of versionCode, i.e. Java's Integer.MIN_VALUE
|
|
|
|
UNSET_VERSION_CODE = -0x100000000
|
|
|
|
|
2013-05-09 21:09:17 +02:00
|
|
|
# Some information from the apks needs to be applied up to the application
|
|
|
|
# level. When doing this, we use the info from the most recent version's apk.
|
|
|
|
# We deal with figuring out when the app was added and last updated at the
|
|
|
|
# same time.
|
2016-01-04 17:02:28 +01:00
|
|
|
for appid, app in apps.items():
|
2016-10-13 16:50:31 +02:00
|
|
|
bestver = UNSET_VERSION_CODE
|
2013-11-27 10:35:43 +01:00
|
|
|
for apk in apks + archapks:
|
2016-11-29 13:40:21 +01:00
|
|
|
if apk['packageName'] == appid:
|
|
|
|
if apk['versionCode'] > bestver:
|
|
|
|
bestver = apk['versionCode']
|
2013-05-09 21:09:17 +02:00
|
|
|
bestapk = apk
|
|
|
|
|
|
|
|
if 'added' in apk:
|
2015-11-28 13:09:47 +01:00
|
|
|
if not app.added or apk['added'] < app.added:
|
|
|
|
app.added = apk['added']
|
2016-11-28 21:17:22 +01:00
|
|
|
if not app.lastUpdated or apk['added'] > app.lastUpdated:
|
|
|
|
app.lastUpdated = apk['added']
|
2013-05-09 21:09:17 +02:00
|
|
|
|
2015-11-28 13:09:47 +01:00
|
|
|
if not app.added:
|
2015-11-26 23:47:22 +01:00
|
|
|
logging.debug("Don't know when " + appid + " was added")
|
2016-11-28 21:17:22 +01:00
|
|
|
if not app.lastUpdated:
|
2015-11-26 23:47:22 +01:00
|
|
|
logging.debug("Don't know when " + appid + " was last updated")
|
2013-05-09 21:09:17 +02:00
|
|
|
|
2016-10-13 16:50:31 +02:00
|
|
|
if bestver == UNSET_VERSION_CODE:
|
2016-11-23 17:25:59 +01:00
|
|
|
|
2015-11-28 13:09:47 +01:00
|
|
|
if app.Name is None:
|
|
|
|
app.Name = app.AutoName or appid
|
|
|
|
app.icon = None
|
2015-11-26 23:47:22 +01:00
|
|
|
logging.debug("Application " + appid + " has no packages")
|
2013-05-09 21:09:17 +02:00
|
|
|
else:
|
2015-11-28 13:09:47 +01:00
|
|
|
if app.Name is None:
|
|
|
|
app.Name = bestapk['name']
|
|
|
|
app.icon = bestapk['icon'] if 'icon' in bestapk else None
|
2016-02-17 00:11:22 +01:00
|
|
|
if app.CurrentVersionCode is None:
|
|
|
|
app.CurrentVersionCode = str(bestver)
|
2013-05-09 21:09:17 +02:00
|
|
|
|
|
|
|
# Sort the app list by name, then the web site doesn't have to by default.
|
|
|
|
# (we had to wait until we'd scanned the apks to do this, because mostly the
|
|
|
|
# name comes from there!)
|
2016-01-04 18:51:58 +01:00
|
|
|
sortedids = sorted(apps.keys(), key=lambda appid: apps[appid].Name.upper())
|
2013-05-09 21:09:17 +02:00
|
|
|
|
2015-08-20 17:40:18 +02:00
|
|
|
# APKs are placed into multiple repos based on the app package, providing
|
|
|
|
# per-app subscription feeds for nightly builds and things like it
|
|
|
|
if config['per_app_repos']:
|
|
|
|
add_apks_to_per_app_repos(repodirs[0], apks)
|
2016-01-04 17:02:28 +01:00
|
|
|
for appid, app in apps.items():
|
2015-08-20 17:40:18 +02:00
|
|
|
repodir = os.path.join(appid, 'fdroid', 'repo')
|
|
|
|
appdict = dict()
|
|
|
|
appdict[appid] = app
|
|
|
|
if os.path.isdir(repodir):
|
2016-11-28 15:23:59 +01:00
|
|
|
make_index(appdict, [appid], apks, repodir, False)
|
2015-08-20 17:40:18 +02:00
|
|
|
else:
|
|
|
|
logging.info('Skipping index generation for ' + appid)
|
|
|
|
return
|
|
|
|
|
2013-05-09 21:09:17 +02:00
|
|
|
if len(repodirs) > 1:
|
2014-01-09 13:33:48 +01:00
|
|
|
archive_old_apks(apps, apks, archapks, repodirs[0], repodirs[1], config['archive_older'])
|
2013-05-09 21:09:17 +02:00
|
|
|
|
2013-05-15 18:09:37 +02:00
|
|
|
# Make the index for the main repo...
|
2016-11-28 15:23:59 +01:00
|
|
|
make_index(apps, sortedids, apks, repodirs[0], False)
|
|
|
|
make_categories_txt(repodirs[0], categories)
|
2013-05-09 21:09:17 +02:00
|
|
|
|
2013-11-27 10:35:43 +01:00
|
|
|
# If there's an archive repo, make the index for it. We already scanned it
|
|
|
|
# earlier on.
|
2013-05-09 21:09:17 +02:00
|
|
|
if len(repodirs) > 1:
|
2016-11-28 15:23:59 +01:00
|
|
|
make_index(apps, sortedids, archapks, repodirs[1], True)
|
2013-05-09 21:09:17 +02:00
|
|
|
|
2016-12-16 12:19:07 +01:00
|
|
|
if config.get('binary_transparency_remote'):
|
|
|
|
make_binary_transparency_log(repodirs)
|
|
|
|
|
2013-10-31 16:37:39 +01:00
|
|
|
if config['update_stats']:
|
2012-08-31 19:17:38 +02:00
|
|
|
|
|
|
|
# Update known apks info...
|
|
|
|
knownapks.writeifchanged()
|
|
|
|
|
|
|
|
# Generate latest apps data for widget
|
|
|
|
if os.path.exists(os.path.join('stats', 'latestapps.txt')):
|
|
|
|
data = ''
|
2016-06-07 13:35:13 +02:00
|
|
|
with open(os.path.join('stats', 'latestapps.txt'), 'r', encoding='utf8') as f:
|
2016-01-04 17:28:55 +01:00
|
|
|
for line in f:
|
|
|
|
appid = line.rstrip()
|
|
|
|
data += appid + "\t"
|
|
|
|
app = apps[appid]
|
|
|
|
data += app.Name + "\t"
|
|
|
|
if app.icon is not None:
|
|
|
|
data += app.icon + "\t"
|
|
|
|
data += app.License + "\n"
|
2016-06-07 13:35:13 +02:00
|
|
|
with open(os.path.join(repodirs[0], 'latestapps.dat'), 'w', encoding='utf8') as f:
|
2015-08-29 03:37:23 +02:00
|
|
|
f.write(data)
|
2012-02-26 15:18:58 +01:00
|
|
|
|
2013-05-09 21:09:17 +02:00
|
|
|
if cachechanged:
|
2016-06-15 16:34:10 +02:00
|
|
|
apkcache["METADATA_VERSION"] = METADATA_VERSION
|
2013-05-09 21:09:17 +02:00
|
|
|
with open(apkcachefile, 'wb') as cf:
|
|
|
|
pickle.dump(apkcache, cf)
|
|
|
|
|
2012-08-22 18:24:33 +02:00
|
|
|
# Update the wiki...
|
|
|
|
if options.wiki:
|
2014-08-16 12:46:02 +02:00
|
|
|
update_wiki(apps, sortedids, apks + archapks)
|
2012-02-26 15:18:58 +01:00
|
|
|
|
2014-01-27 16:56:55 +01:00
|
|
|
logging.info("Finished.")
|
2012-02-26 15:18:58 +01:00
|
|
|
|
2016-11-15 21:55:06 +01:00
|
|
|
|
2012-02-26 15:18:58 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|