Browse Source

Rename get_pkg_hash.py->get_hash_from_file.py

android-5
Henrik Grimler 6 years ago
parent
commit
2103c04b0b
  1. 22
      build-package.sh
  2. 37
      scripts/get_hash_from_file.py
  3. 20
      scripts/get_pkg_hash.py

22
build-package.sh

@ -327,6 +327,7 @@ termux_step_setup_variables() {
: "${TERMUX_PKG_MAINTAINER:="Fredrik Fornwall @fornwall"}"
: "${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

37
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')

20
scripts/get_pkg_hash.py

@ -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])
Loading…
Cancel
Save