mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-01-07 10:42:07 +00:00
postbuild script - Improve cross-platform compatibility (#208)
This commit is contained in:
parent
2e034c0239
commit
3a6b5e5478
1 changed files with 34 additions and 15 deletions
|
@ -4,6 +4,8 @@ import os.path
|
|||
import sys
|
||||
import subprocess
|
||||
import platform
|
||||
import codecs
|
||||
import re
|
||||
#
|
||||
# Script Compatibility:
|
||||
# - 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):
|
||||
return None
|
||||
|
||||
if (platform.system() == 'Linux'):
|
||||
try:
|
||||
keytool_bin = which("keytool")
|
||||
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)
|
||||
result_hash = result_hash.strip('\n')
|
||||
except:
|
||||
print('[WARN] Failed to exec \'keytool\'.');
|
||||
return None
|
||||
keytool_bin = which("keytool")
|
||||
if not keytool_bin:
|
||||
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'
|
||||
try:
|
||||
if (platform.system() == "Windows"):
|
||||
shell_result = subprocess.check_output(keytool_bin + ' -list -printcert -jarfile "' + apk_fullfn + '"')
|
||||
else:
|
||||
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 = {
|
||||
"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 + ')')
|
||||
try:
|
||||
result_array = codecs.decode(shell_result, 'cp1252').splitlines()
|
||||
for result_line in result_array:
|
||||
if result_line:
|
||||
result_line = result_line.strip()
|
||||
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
|
||||
|
||||
|
@ -106,7 +125,7 @@ if platform.system() not in SUPPORTED_PYTHON_PLATFORMS:
|
|||
', '.join(SUPPORTED_PYTHON_PLATFORMS))
|
||||
print ('')
|
||||
|
||||
# Build FullFN of "app-debug.apk".
|
||||
# Build FullFNs.
|
||||
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"))
|
||||
debug_apk = os.path.realpath(os.path.join(current_dir, 'build', 'outputs', 'apk', 'debug', 'app-debug.apk'))
|
||||
|
|
Loading…
Reference in a new issue