From 1d62574fa19f7d62e63a02c564f5602f5a15963d Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sat, 16 Feb 2019 18:49:13 +0100 Subject: [PATCH] build-package.sh: handle Release.gpg and get deb path from Package This makes it possible to download .debs from dl.bintray.com/xeffyr --- build-package.sh | 35 ++++++++++++++++++++++------------- scripts/get_hash_from_file.py | 19 +++++++++++-------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/build-package.sh b/build-package.sh index 0bf42aa3f..46b84b4e3 100755 --- a/build-package.sh +++ b/build-package.sh @@ -454,12 +454,12 @@ termux_download_deb() { local version=$3 local deb_file=${package}_${version}_${package_arch}.deb for idx in $(seq ${#TERMUX_REPO_URL[@]}); do - local TERMUX_REPO_NAME=$(echo ${TERMUX_REPO_URL[$idx-1]} | sed -e 's%https://%%g' -e 's%http://%%g' -e 's%/dists%%g' -e 's%/%-%g') + local TERMUX_REPO_NAME=$(echo ${TERMUX_REPO_URL[$idx-1]} | sed -e 's%https://%%g' -e 's%http://%%g' -e 's%/%-%g') local PACKAGE_FILE_PATH="${TERMUX_REPO_NAME}-${TERMUX_REPO_DISTRIBUTION[$idx-1]}-${TERMUX_REPO_COMPONENT[$idx-1]}-Packages" - PKG_HASH=$(./scripts/get_hash_from_file.py "${TERMUX_COMMON_CACHEDIR}-$arch/$PACKAGE_FILE_PATH" $package $version) + read -d "\n" PKG_PATH PKG_HASH <<<$(./scripts/get_hash_from_file.py "${TERMUX_COMMON_CACHEDIR}-$arch/$PACKAGE_FILE_PATH" $package $version) if ! [ "$PKG_HASH" = "" ]; then if [ ! "$TERMUX_QUIET_BUILD" = true ]; then - echo "Found $package in ${TERMUX_REPO_URL[$idx-1]}" + echo "Found $package in ${TERMUX_REPO_URL[$idx-1]}/dists/${TERMUX_REPO_DISTRIBUTION[$idx-1]}" fi break fi @@ -467,7 +467,7 @@ termux_download_deb() { if [ "$PKG_HASH" = "" ]; then return 1 else - termux_download ${TERMUX_REPO_URL[$idx-1]}/${TERMUX_REPO_DISTRIBUTION[$idx-1]}/${TERMUX_REPO_COMPONENT[$idx-1]}/binary-${package_arch}/${deb_file} \ + termux_download ${TERMUX_REPO_URL[$idx-1]}/${PKG_PATH} \ $TERMUX_COMMON_CACHEDIR-$package_arch/${deb_file} \ $PKG_HASH return 0 @@ -518,21 +518,30 @@ termux_step_get_repo_files() { gpg --import ${TERMUX_REPO_SIGNING_KEYS} for idx in $(seq ${#TERMUX_REPO_URL[@]}); do - local TERMUX_REPO_NAME=$(echo ${TERMUX_REPO_URL[$idx-1]} | sed -e 's%https://%%g' -e 's%http://%%g' -e 's%/dists%%g' -e 's%/%-%g') - curl --fail -L "${TERMUX_REPO_URL[$idx-1]}/${TERMUX_REPO_DISTRIBUTION[$idx-1]}/InRelease" \ + local TERMUX_REPO_NAME=$(echo ${TERMUX_REPO_URL[$idx-1]} | sed -e 's%https://%%g' -e 's%http://%%g' -e 's%/%-%g') + curl --fail -L "${TERMUX_REPO_URL[$idx-1]}/dists/${TERMUX_REPO_DISTRIBUTION[$idx-1]}/InRelease" \ -o ${TERMUX_COMMON_CACHEDIR}/${TERMUX_REPO_NAME}-${TERMUX_REPO_DISTRIBUTION[$idx-1]}-InRelease \ - || termux_error_exit "Download of ${TERMUX_REPO_URL[$idx-1]}/${TERMUX_REPO_DISTRIBUTION[$idx-1]}/InRelease failed" + || curl --fail -L "${TERMUX_REPO_URL[$idx-1]}/dists/${TERMUX_REPO_DISTRIBUTION[$idx-1]}/Release.gpg" \ + -o ${TERMUX_COMMON_CACHEDIR}/${TERMUX_REPO_NAME}-${TERMUX_REPO_DISTRIBUTION[$idx-1]}-Release.gpg \ + && curl --fail -L "${TERMUX_REPO_URL[$idx-1]}/dists/${TERMUX_REPO_DISTRIBUTION[$idx-1]}/Release" \ + -o ${TERMUX_COMMON_CACHEDIR}/${TERMUX_REPO_NAME}-${TERMUX_REPO_DISTRIBUTION[$idx-1]}-Release \ + || termux_error_exit "Download of InRelease and Release.gpg from ${TERMUX_REPO_URL[$idx-1]}/dists/${TERMUX_REPO_DISTRIBUTION[$idx-1]} failed" + + if [ -f ${TERMUX_COMMON_CACHEDIR}/${TERMUX_REPO_NAME}-${TERMUX_REPO_DISTRIBUTION[$idx-1]}-InRelease ]; then + local RELEASE_FILE=${TERMUX_COMMON_CACHEDIR}/${TERMUX_REPO_NAME}-${TERMUX_REPO_DISTRIBUTION[$idx-1]}-InRelease + gpg --verify $RELEASE_FILE + else + local RELEASE_FILE=${TERMUX_COMMON_CACHEDIR}/${TERMUX_REPO_NAME}-${TERMUX_REPO_DISTRIBUTION[$idx-1]}-Release + gpg --verify ${RELEASE_FILE}.gpg $RELEASE_FILE + fi - gpg --verify ${TERMUX_COMMON_CACHEDIR}/${TERMUX_REPO_NAME}-${TERMUX_REPO_DISTRIBUTION[$idx-1]}-InRelease for arch in all $TERMUX_ARCH; do - local packages_hash=$(./scripts/get_hash_from_file.py ${TERMUX_COMMON_CACHEDIR}/${TERMUX_REPO_NAME}-${TERMUX_REPO_DISTRIBUTION[$idx-1]}-InRelease \ - $arch ${TERMUX_REPO_COMPONENT[$idx-1]}) + local packages_hash=$(./scripts/get_hash_from_file.py ${RELEASE_FILE} $arch ${TERMUX_REPO_COMPONENT[$idx-1]}) # If packages_hash = "" then the repo probably doesn't contain debs for $arch if ! [ "$packages_hash" = "" ]; then - termux_download "${TERMUX_REPO_URL[$idx-1]}/${TERMUX_REPO_DISTRIBUTION[$idx-1]}/${TERMUX_REPO_COMPONENT[$idx-1]}/binary-$arch/Packages.xz" \ - "${TERMUX_COMMON_CACHEDIR}-$arch/${TERMUX_REPO_NAME}-${TERMUX_REPO_DISTRIBUTION[$idx-1]}-${TERMUX_REPO_COMPONENT[$idx-1]}-Packages.xz" \ + termux_download "${TERMUX_REPO_URL[$idx-1]}/dists/${TERMUX_REPO_DISTRIBUTION[$idx-1]}/${TERMUX_REPO_COMPONENT[$idx-1]}/binary-$arch/Packages" \ + "${TERMUX_COMMON_CACHEDIR}-$arch/${TERMUX_REPO_NAME}-${TERMUX_REPO_DISTRIBUTION[$idx-1]}-${TERMUX_REPO_COMPONENT[$idx-1]}-Packages" \ $packages_hash - xz --keep -df "${TERMUX_COMMON_CACHEDIR}-$arch/${TERMUX_REPO_NAME}-${TERMUX_REPO_DISTRIBUTION[$idx-1]}-${TERMUX_REPO_COMPONENT[$idx-1]}-Packages.xz" fi done done diff --git a/scripts/get_hash_from_file.py b/scripts/get_hash_from_file.py index bf7dfd009..ce95889be 100755 --- a/scripts/get_hash_from_file.py +++ b/scripts/get_hash_from_file.py @@ -8,7 +8,10 @@ def get_pkg_hash_from_Packages(Packages_file, package, version, hash="SHA256"): for pkg in package_list: if pkg.split('\n')[0] == "Package: "+package: for line in pkg.split('\n'): - if line.startswith('Version:'): + # Assuming Filename: comes before Version: + if line.startswith('Filename:'): + print(line.split(" ")[1] + " ") + elif line.startswith('Version:'): if line != 'Version: '+version: # Seems the repo contains the wrong version, or several versions # We can't use this one so continue looking @@ -17,10 +20,10 @@ def get_pkg_hash_from_Packages(Packages_file, package, version, hash="SHA256"): print(line.split(" ")[1]) break -def get_Packages_hash_from_InRelease(InRelease_file, arch, component, hash="SHA256"): - string_to_find = component+'/binary-'+arch+'/Packages.xz' - with open(InRelease_file, 'r') as InRelease: - hash_list = InRelease.readlines() +def get_Packages_hash_from_Release(Release_file, arch, component, hash="SHA256"): + string_to_find = component+'/binary-'+arch+'/Packages' + with open(Release_file, 'r') as Release: + hash_list = Release.readlines() for i in range(len(hash_list)): if hash_list[i].startswith(hash+':'): break @@ -35,7 +38,7 @@ if __name__ == '__main__': if sys.argv[1].endswith('Packages'): get_pkg_hash_from_Packages(sys.argv[1], sys.argv[2], sys.argv[3]) - elif sys.argv[1].endswith('InRelease'): - get_Packages_hash_from_InRelease(sys.argv[1], sys.argv[2], sys.argv[3]) + elif sys.argv[1].endswith(('InRelease', 'Release')): + get_Packages_hash_from_Release(sys.argv[1], sys.argv[2], sys.argv[3]) else: - sys.exit(sys.argv[1]+' does not seem to be a path to a Packages or InRelease file') + sys.exit(sys.argv[1]+' does not seem to be a path to a Packages or InRelease/Release file')