From patchwork Thu Jul 20 03:18:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABl_PORTAY?= X-Patchwork-Id: 791357 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xCfJ129nkz9t2r for ; Thu, 20 Jul 2017 13:18:56 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id CA0F68A21D; Thu, 20 Jul 2017 03:18:49 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2cSivEn-8WZ6; Thu, 20 Jul 2017 03:18:48 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id E0FD58A21B; Thu, 20 Jul 2017 03:18:47 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id 561D21C255F for ; Thu, 20 Jul 2017 03:18:46 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 4F7308819E for ; Thu, 20 Jul 2017 03:18:46 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WESwBOBO0HBn for ; Thu, 20 Jul 2017 03:18:44 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.savoirfairelinux.com (mail.savoirfairelinux.com [208.88.110.44]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 06C508217E for ; Thu, 20 Jul 2017 03:18:42 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 70A969C255C; Wed, 19 Jul 2017 23:18:41 -0400 (EDT) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 5yPUU0ro9hK7; Wed, 19 Jul 2017 23:18:40 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id A1BB59C2566; Wed, 19 Jul 2017 23:18:40 -0400 (EDT) X-Virus-Scanned: amavisd-new at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id UOa11MrdifVA; Wed, 19 Jul 2017 23:18:40 -0400 (EDT) Received: from localhost.localdomain (modemcable013.17-177-173.mc.videotron.ca [173.177.17.13]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id 6F8BE9C255C; Wed, 19 Jul 2017 23:18:40 -0400 (EDT) From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= To: buildroot@buildroot.org Date: Wed, 19 Jul 2017 23:18:36 -0400 Message-Id: <20170720031836.977-1-gael.portay@savoirfairelinux.com> X-Mailer: git-send-email 2.13.2 MIME-Version: 1.0 Cc: =?utf-8?q?Ga=C3=ABl=20PORTAY?= , "Yann E . MORIN" Subject: [Buildroot] [PATCH] support/download: print dl hash if not provided X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" When a hash file exists but the hash is not provided, the script exits without any information about the hash of the downloaded file. ERROR: No hash found for rpi-userland-771a9aa7155442615bbe4cd6cf87b29b90cd228a.tar.gz Now, the script hashes the downloaded file and suggests its sha256 to the user. $ make ... >>> rpi-userland 771a9aa7155442615bbe4cd6cf87b29b90cd228a Downloading --2017-07-19 21:38:39-- https://github.com/raspberrypi/userland/archive/771a9aa7155442615bbe4cd6cf87b29b90cd228a/rpi-userland-771a9aa7155442615bbe4cd6cf87b29b90cd228a.tar.gz ... ERROR: No hash found for rpi-userland-771a9aa7155442615bbe4cd6cf87b29b90cd228a.tar.gz ERROR: If the source is trusted, consider adding these lines to package/rpi-userland//rpi-userland.hash # Locally calculated from download sha256 771fb1be53414b00a9213f24bd9c88059cf76b72c5e21ac613b267d3e58d3715 rpi-userland-771a9aa7155442615bbe4cd6cf87b29b90cd228a.tar.gz ... It also fixes check_one_hash description. check_one_hash() takes three arguments: - algo hash - known hash - file to hash Signed-off-by: Gaƫl PORTAY --- support/download/check-hash | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/support/download/check-hash b/support/download/check-hash index c1ff53c02..b18447f86 100755 --- a/support/download/check-hash +++ b/support/download/check-hash @@ -41,13 +41,12 @@ if [ ! -f "${h_file}" ]; then exit 0 fi -# Check one hash for a file -# $1: known hash +# Compute hash for a file +# $1: algo hash # $2: file (full path) -check_one_hash() { +compute_hash() { _h="${1}" - _known="${2}" - _file="${3}" + _file="${2}" # Note: md5 is supported, but undocumented on purpose. # Note: sha3 is not supported, since there is currently no implementation @@ -66,8 +65,20 @@ check_one_hash() { ;; esac + ${_h}sum "${_file}" |cut -d ' ' -f 1 +} + +# Check one hash for a file +# $1: algo hash +# $2: known hash +# $3: file (full path) +check_one_hash() { + _h="${1}" + _known="${2}" + _file="${3}" + # Do the hashes match? - _hash=$( ${_h}sum "${_file}" |cut -d ' ' -f 1 ) + _hash=$( compute_hash "${_h}" "${_file}" ) if [ "${_hash}" = "${_known}" ]; then printf "%s: OK (%s: %s)\n" "${base}" "${_h}" "${_hash}" return 0 @@ -105,6 +116,12 @@ if [ ${nb_checks} -eq 0 ]; then exit 0 ;; esac + + h="sha256" + hash=$( compute_hash "${h}" "${file}" ) printf "ERROR: No hash found for %s\n" "${base}" >&2 + printf "ERROR: If the source is trusted, consider adding these lines to ${h_file}\n" >&2 + printf "# Locally calculated from download\n" >&2 + printf "${h} ${hash} ${base}\n" >&2 exit 3 fi