From 968c96fce980e5aaa22ca89b5fade3c49e873cb5 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Tue, 1 Jan 2019 20:22:32 +0100 Subject: [PATCH] Rename get_pkg_hash.py->get_hash_from_file.py --- build-package.sh | 22 ++++++++++----------- scripts/get_hash_from_file.py | 37 +++++++++++++++++++++++++++++++++++ scripts/get_pkg_hash.py | 20 ------------------- 3 files changed, 47 insertions(+), 32 deletions(-) create mode 100755 scripts/get_hash_from_file.py delete mode 100755 scripts/get_pkg_hash.py diff --git a/build-package.sh b/build-package.sh index b77744684..16845439b 100755 --- a/build-package.sh +++ b/build-package.sh @@ -326,6 +326,7 @@ termux_step_setup_variables() { : "${TERMUX_DEBDIR:="${TERMUX_SCRIPTDIR}/debs"}" : "${TERMUX_SKIP_DEPCHECK:="false"}" : "${TERMUX_INSTALL_DEPS:="false"}" + : "${TERMUX_REPO_SIGNING_KEY:="2218893D3F679BEFC421FD976700B77E6D8D0AE7"}" : "${TERMUX_REPO_URL:="https://termux.net/dists"}" : "${TERMUX_REPO_DISTRIBUTION:="stable"}" : "${TERMUX_REPO_COMPONENT:="main"}" @@ -457,7 +458,7 @@ termux_download_deb() { local package_arch=$2 local version=$3 local deb_file=${package}_${version}_${package_arch}.deb - local pkg_hash=$(./scripts/get_pkg_hash.py ${TERMUX_COMMON_CACHEDIR}-${package_arch}/Packages $package) + local pkg_hash=$(./scripts/get_hash_from_file.py ${TERMUX_COMMON_CACHEDIR}-${package_arch}/Packages $package) if [ "$pkg_hash" = "" ]; then # No hash found for $package @@ -518,19 +519,16 @@ termux_step_start_build() { curl --fail -LO "$TERMUX_REPO_URL/$TERMUX_REPO_DISTRIBUTION/InRelease" \ || termux_error_exit "Download of $TERMUX_REPO_URL/$TERMUX_REPO_DISTRIBUTION/InRelease failed" # Import Fornwalls key: - gpg --recv 2218893D3F679BEFC421FD976700B77E6D8D0AE7 + gpg --recv $TERMUX_REPO_SIGNING_KEY gpg --verify InRelease - for arch in all $TERMUX_ARCH; do - # A sha256 hashsum has length 64 so grep for hashes that are that long - local packages_hash=$(grep binary-$arch/Packages.xz $TERMUX_COMMON_CACHEDIR/InRelease | awk 'length($1) == 64 {print $1}') - termux_download "$TERMUX_REPO_URL/$TERMUX_REPO_DISTRIBUTION/$TERMUX_REPO_COMPONENT/binary-$arch/Packages.xz" \ - "${TERMUX_COMMON_CACHEDIR}-$arch/Packages.xz" \ - $packages_hash - xz -df "${TERMUX_COMMON_CACHEDIR}-$arch/Packages.xz" - done - # cd ${TERMUX_COMMON_CACHEDIR}-$TERMUX_ARCH - # curl --fail -L "$TERMUX_REPO_URL/$TERMUX_REPO_DISTRIBUTION/$TERMUX_REPO_COMPONENT/binary-${TERMUX_ARCH}/Packages.xz" | xz -d > Packages || termux_error_exit "Download of $TERMUX_REPO_URL/$TERMUX_REPO_DISTRIBUTION/$TERMUX_REPO_COMPONENT/Packages.xz failed" ) + for arch in all $TERMUX_ARCH; do + local packages_hash=$(./scripts/get_hash_from_file.py ${TERMUX_COMMON_CACHEDIR}/InRelease $arch) + termux_download "$TERMUX_REPO_URL/$TERMUX_REPO_DISTRIBUTION/$TERMUX_REPO_COMPONENT/binary-$arch/Packages.xz" \ + "${TERMUX_COMMON_CACHEDIR}-$arch/Packages.xz" \ + $packages_hash + xz -df "${TERMUX_COMMON_CACHEDIR}-$arch/Packages.xz" + done # Download dependencies local pkg dep_arch dep_version deb_file diff --git a/scripts/get_hash_from_file.py b/scripts/get_hash_from_file.py new file mode 100755 index 000000000..4d355832c --- /dev/null +++ b/scripts/get_hash_from_file.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +import os, sys + +def get_pkg_hash_from_Packages(Packages_file, package, hash="SHA256"): + with open(Packages_file, 'r') as Packages: + package_list = Packages.read().split('\n\n') + for pkg in package_list: + if pkg.split('\n')[0] == "Package: "+package: + for line in pkg.split('\n'): + if line.startswith(hash): + print(line.split(" ")[1]) + break + break + +def get_Packages_hash_from_InRelease(InRelease_file, arch, hash="SHA256"): + string_to_found = 'binary-'+arch+'/Packages.xz' + with open(InRelease_file, 'r') as InRelease: + hash_list = InRelease.readlines() + for i in range(len(hash_list)): + if hash_list[i].startswith(hash+':'): + break + for j in range(i, len(hash_list)): + if string_to_found in hash_list[j].strip(' '): + print(hash_list[j].strip(' ').split(' ')[0]) + break + +if __name__ == '__main__': + if len(sys.argv) < 2: + sys.exit('Too few arguments, I need the path to a Packages file and a package name. Exiting') + + if sys.argv[1].endswith('Packages'): + get_pkg_hash_from_Packages(sys.argv[1], sys.argv[2]) + elif sys.argv[1].endswith('InRelease'): + get_Packages_hash_from_InRelease(sys.argv[1], sys.argv[2]) + else: + sys.exit(sys.argv[1]+' does not seem to be a path to a Packages or InRelease file') diff --git a/scripts/get_pkg_hash.py b/scripts/get_pkg_hash.py deleted file mode 100755 index 668392601..000000000 --- a/scripts/get_pkg_hash.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python - -import os, sys - -def get_hash_from_Packages(Packages_file, package, hash="SHA256"): - with open(Packages_file, 'r') as Packages: - package_list = Packages.read().split('\n\n') - for pkg in package_list: - if pkg.split('\n')[0] == "Package: "+package: - for line in pkg.split('\n'): - if line.startswith(hash): - print(line.split(" ")[1]) - break - break - -if __name__ == '__main__': - if len(sys.argv) < 2: - print('Too few arguments, I need the path to a Packages file and a package name. Exiting') - sys.exit(1) - get_hash_from_Packages(sys.argv[1], sys.argv[2])