From 84bd74057f0d2543ddbc7de2351b0a310df329c6 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sun, 25 Dec 2016 16:40:05 +0100 Subject: build: use mkhash to replace various quirky md5sum/openssl calls Signed-off-by: Felix Fietkau --- scripts/combined-ext-image.sh | 2 +- scripts/combined-image.sh | 2 +- scripts/download.pl | 8 ++------ scripts/ipkg-make-index.sh | 2 +- scripts/om-fwupgradecfg-gen.sh | 10 +++++----- 5 files changed, 10 insertions(+), 14 deletions(-) (limited to 'scripts') diff --git a/scripts/combined-ext-image.sh b/scripts/combined-ext-image.sh index 374fe6e344..0c7b1d993d 100755 --- a/scripts/combined-ext-image.sh +++ b/scripts/combined-ext-image.sh @@ -47,7 +47,7 @@ while [ "$#" -gt 1 ] [ ! -f "$file" ] && echo "$ME: Not a valid file: $file" && usage FILES="$FILES $file" - md5=$(cat "$file" | md5sum -) + md5=$(mkhash md5 "$file") printf "%-32s%08x%32s" "$filename" $(stat -c "%s" "$file") "${md5%% *}" >> $IMG_OUT shift 2 done diff --git a/scripts/combined-image.sh b/scripts/combined-image.sh index 5472b2cfd2..4e00cb89a2 100644 --- a/scripts/combined-image.sh +++ b/scripts/combined-image.sh @@ -16,7 +16,7 @@ dd if="$1" of="$kern" bs=$BLKSZ conv=sync 2>/dev/null dd if="$2" of="$root" bs=$BLKSZ conv=sync 2>/dev/null # Calculate md5sum over combined kernel and rootfs image. -md5=$(cat "$kern" "$root" | md5sum -) +md5=$(cat "$kern" "$root" | mkhash md5) # Write image header followed by kernel and rootfs image. # The header is padded to 64k, format is: diff --git a/scripts/download.pl b/scripts/download.pl index ad8b837288..0398c564ef 100755 --- a/scripts/download.pl +++ b/scripts/download.pl @@ -65,12 +65,8 @@ sub hash_cmd() { my $len = length($file_hash); my $cmd; - $len == 64 and return "openssl dgst -sha256 | sed -e 's,.*= ,,'"; - $len == 32 and do { - my $cmd = which("md5sum") || which("md5") || die 'no md5 checksum program found, please install md5 or md5sum'; - chomp $cmd; - return $cmd; - }; + $len == 64 and return "mkhash sha256"; + $len == 32 and return "mkhash md5"; return undef; } diff --git a/scripts/ipkg-make-index.sh b/scripts/ipkg-make-index.sh index c99c5fe8a3..dcd11ca191 100755 --- a/scripts/ipkg-make-index.sh +++ b/scripts/ipkg-make-index.sh @@ -18,7 +18,7 @@ for pkg in `find $pkg_dir -name '*.ipk' | sort`; do [[ "$name" = "libc" ]] && continue echo "Generating index for package $pkg" >&2 file_size=$(ls -l $pkg | awk '{print $5}') - sha256sum=$(openssl dgst -sha256 $pkg | awk '{print $2}') + sha256sum=$(mkhash sha256 $pkg) # Take pains to make variable value sed-safe sed_safe_pkg=`echo $pkg | sed -e 's/^\.\///g' -e 's/\\//\\\\\\//g'` tar -xzOf $pkg ./control.tar.gz | tar xzOf - ./control | sed -e "s/^Description:/Filename: $sed_safe_pkg\\ diff --git a/scripts/om-fwupgradecfg-gen.sh b/scripts/om-fwupgradecfg-gen.sh index 6c3b74cc1c..bb30252aa0 100644 --- a/scripts/om-fwupgradecfg-gen.sh +++ b/scripts/om-fwupgradecfg-gen.sh @@ -41,16 +41,16 @@ esac CHECK_BS=65536 KERNEL_SIZE=$(stat -c%s "$KERNEL_PATH") -KERNEL_MD5=$(md5=$(md5sum $KERNEL_PATH); echo ${md5%% *}) -KERNEL_SHA256=$(openssl dgst -sha256 $KERNEL_PATH | awk '{print $2}') +KERNEL_MD5=$(mkhash md5 $KERNEL_PATH) +KERNEL_SHA256=$(mkhash sha256 $KERNEL_PATH) KERNEL_PART_SIZE=$(size=$(($KERNEL_SIZE / $FLASH_BS)); [ $(($size * $FLASH_BS)) -lt $KERNEL_SIZE ] && size=$(($size + 1)); echo $(($size * $FLASH_BS / 1024))) ROOTFS_FLASH_ADDR=$(addr=$(($KERNEL_FLASH_ADDR + ($KERNEL_PART_SIZE * 1024))); printf "0x%x" $addr) ROOTFS_SIZE=$(stat -c%s "$ROOTFS_PATH") ROOTFS_CHECK_BLOCKS=$((($ROOTFS_SIZE / $CHECK_BS) - $MD5_SKIP_BLOCKS)) -ROOTFS_MD5=$(md5=$(dd if=$ROOTFS_PATH bs=$CHECK_BS count=$ROOTFS_CHECK_BLOCKS 2>&- | md5sum); echo ${md5%% *}) -ROOTFS_MD5_FULL=$(md5=$(md5sum $ROOTFS_PATH); echo ${md5%% *}) -ROOTFS_SHA256_FULL=$(openssl dgst -sha256 $ROOTFS_PATH | awk '{print $2}') +ROOTFS_MD5=$(dd if=$ROOTFS_PATH bs=$CHECK_BS count=$ROOTFS_CHECK_BLOCKS 2>&- | mkhash md5) +ROOTFS_MD5_FULL=$(mkhash md5 $ROOTFS_PATH) +ROOTFS_SHA256_FULL=$(mkhash sha256 $ROOTFS_PATH) ROOTFS_CHECK_SIZE=$(printf '0x%x' $(($ROOTFS_CHECK_BLOCKS * $CHECK_BS))) ROOTFS_PART_SIZE=$(($MAX_PART_SIZE - $KERNEL_PART_SIZE)) -- cgit v1.2.3