1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2025-01-09 03:31:46 +00:00

postbuild script - Improve cross-platform compatibility (#208)

This commit is contained in:
Catfriend1 2019-01-06 21:12:23 +01:00 committed by GitHub
parent 2e034c0239
commit 3a6b5e5478
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,8 @@ import os.path
import sys import sys
import subprocess import subprocess
import platform import platform
import codecs
import re
# #
# Script Compatibility: # Script Compatibility:
# - Python 2.7.15 # - Python 2.7.15
@ -39,21 +41,38 @@ def calcAndPrintCertHash(apk_fullfn, apk_build_type):
if not apk_fullfn or not os.path.isfile(apk_fullfn): if not apk_fullfn or not os.path.isfile(apk_fullfn):
return None return None
if (platform.system() == 'Linux'): keytool_bin = which("keytool")
try: if not keytool_bin:
keytool_bin = which("keytool") keytool_bin = os.environ.get('ProgramFiles') + os.path.sep + 'Android' + os.path.sep + 'Android Studio' + os.path.sep + 'jre' + os.path.sep + 'bin' + os.path.sep + 'keytool.exe'
result_hash = subprocess.check_output(keytool_bin + ' -list -printcert -jarfile "' + apk_fullfn + '" | grep "SHA1: " | cut -d " " -f 3 | xxd -r -p | openssl base64', shell=True) try:
result_hash = result_hash.strip('\n') if (platform.system() == "Windows"):
except: shell_result = subprocess.check_output(keytool_bin + ' -list -printcert -jarfile "' + apk_fullfn + '"')
print('[WARN] Failed to exec \'keytool\'.'); else:
return None shell_result = subprocess.check_output(keytool_bin + ' -list -printcert -jarfile "' + apk_fullfn + '"', shell=True)
except Exception as e:
print('[WARN] Failed to exec keytool: ' + str(e));
return None
release_types = { try:
"2ScaPj41giu4vFh+Y7Q0GJTqwbA=": "GitHub", result_array = codecs.decode(shell_result, 'cp1252').splitlines()
"nyupq9aU0x6yK8RHaPra5GbTqQY=": "F-Droid", for result_line in result_array:
"dQAnHXvlh80yJgrQUCo6LAg4294=": "Google Play" if result_line:
} result_line = result_line.strip()
print('[INFO] Built ' + apk_build_type + ' APK for ' + release_types.get(result_hash, "INVALID_CHANNEL") + ' (signing certificate hash: ' + result_hash + ')') if 'SHA1: ' in result_line:
result_hex = result_line.replace('SHA1: ', '')
result_hex_cleaned = re.sub('[^A-Fa-f0-9]+', '', result_hex)
result_hash = codecs.encode(codecs.decode(result_hex_cleaned, 'hex'), 'base64').decode('utf-8')
result_hash = result_hash.strip('\n')
except Exception as e:
print('[WARN] Failed to parse keytool result: ' + str(e));
return None
release_types = {
"2ScaPj41giu4vFh+Y7Q0GJTqwbA=": "GitHub",
"nyupq9aU0x6yK8RHaPra5GbTqQY=": "F-Droid",
"dQAnHXvlh80yJgrQUCo6LAg4294=": "Google Play"
}
print('[INFO] Built ' + apk_build_type + ' APK for ' + release_types.get(result_hash, "INVALID_CHANNEL") + ' (signing certificate hash: ' + result_hash + ')')
return None return None
@ -106,7 +125,7 @@ if platform.system() not in SUPPORTED_PYTHON_PLATFORMS:
', '.join(SUPPORTED_PYTHON_PLATFORMS)) ', '.join(SUPPORTED_PYTHON_PLATFORMS))
print ('') print ('')
# Build FullFN of "app-debug.apk". # Build FullFNs.
current_dir = os.path.dirname(os.path.realpath(__file__)) current_dir = os.path.dirname(os.path.realpath(__file__))
enable_push_to_device = os.path.realpath(os.path.join(current_dir, "..", "#enable_push_to_device")) enable_push_to_device = os.path.realpath(os.path.join(current_dir, "..", "#enable_push_to_device"))
debug_apk = os.path.realpath(os.path.join(current_dir, 'build', 'outputs', 'apk', 'debug', 'app-debug.apk')) debug_apk = os.path.realpath(os.path.join(current_dir, 'build', 'outputs', 'apk', 'debug', 'app-debug.apk'))