From patchwork Mon Oct 23 16:11:35 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: 829367 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yLLxy4mGPz9t5s for ; Tue, 24 Oct 2017 03:11:50 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 2BCE187439; Mon, 23 Oct 2017 16:11:48 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id P4b3BtMrMLkh; Mon, 23 Oct 2017 16:11:46 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id C292C873E2; Mon, 23 Oct 2017 16:11:46 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 6FE3B1BFB70 for ; Mon, 23 Oct 2017 16:11:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 681A6878DA for ; Mon, 23 Oct 2017 16:11:45 +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 syOnEusRJu0H for ; Mon, 23 Oct 2017 16:11: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 hemlock.osuosl.org (Postfix) with ESMTPS id 07CFC878C4 for ; Mon, 23 Oct 2017 16:11:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 5F04C9C19F9; Mon, 23 Oct 2017 12:11:42 -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 mHxVL8-AgC52; Mon, 23 Oct 2017 12:11:41 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 410DE9C2728; Mon, 23 Oct 2017 12:11:41 -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 QroxPo7HEr6u; Mon, 23 Oct 2017 12:11:41 -0400 (EDT) Received: from archlinux.mtl.sfl (unknown [192.168.49.77]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id 155179C19F9; Mon, 23 Oct 2017 12:11:41 -0400 (EDT) From: =?utf-8?q?Ga=C3=ABl_PORTAY?= To: buildroot@buildroot.org, "Arnout Vandecappelle" Date: Mon, 23 Oct 2017 12:11:35 -0400 Message-Id: <20171023161135.8799-1-gael.portay@savoirfairelinux.com> X-Mailer: git-send-email 2.14.2 MIME-Version: 1.0 Cc: =?utf-8?q?Ga=C3=ABl_PORTAY?= , "Yann E. MORIN" Subject: [Buildroot] [PATCHv2] 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-a7976021a89451de0d008aa48f16c4e88872899b.tar.gz Now, the script hashes the downloaded file and suggests its sha256 to the user. $ make ... >>> rpi-userland a7976021a89451de0d008aa48f16c4e88872899b Downloading --2017-10-23 15:29:46-- https://github.com/raspberrypi/userland/archive/a7976021a89451de0d008aa48f16c4e88872899b/rpi-userland-a7976021a89451de0d008aa48f16c4e88872899b.tar.gz ... ERROR: No hash found for rpi-userland-a7976021a89451de0d008aa48f16c4e88872899b.tar.gz ERROR: Please find a hash in the upstream announcement or website and add it to package/rpi-userland//rpi-userland.hash ERROR: If upstream doesn't provide a hash and the source is trusted, consider adding these lines: # Locally calculated from download sha256 8ed745ea28ef9d5e6d2e5534acabe1ea1a6c6be9bab7f683527ce5da5a3f77cb rpi-userland-a7976021a89451de0d0 ... Signed-off-by: Gaƫl PORTAY --- Hi all, I tested it without hash file, the build succeed $ rm -Rf output/build/rpi-userland-* $ rm -f package/rpi-userland/rpi-userland.hash $ make && echo succeed ... succeed I tested it with an empty hash file, the build failed $ rm -Rf output/build/rpi-userland-* $ rm -f package/rpi-userland/rpi-userland.hash $ touch package/rpi-userland/rpi-userland.hash $ make || echo oops ... ERROR: No hash found for rpi-userland-a7976021a89451de0d008aa48f16c4e88872899b.tar.gz ERROR: Please find a hash in the upstream announcement or website and add it to package/rpi-userland//rpi-userland.hash ERROR: If upstream doesn't provide a hash and the source is trusted, consider adding these lines: # Locally calculated from download sha256 8ed745ea28ef9d5e6d2e5534acabe1ea1a6c6be9bab7f683527ce5da5a3f77cb rpi-userland-a7976021a89451de0d008aa48f16c4e88872899b.tar.gz ... oops I tested it with the new locally computed hash, the build succeed $ rm -Rf output/build/rpi-userland-* $ cat <package/rpi-userland/rpi-userland.hash # Locally calculated from download sha256 8ed745ea28ef9d5e6d2e5534acabe1ea1a6c6be9bab7f683527ce5da5a3f77cb rpi-userland-a7976021a89451de0d008aa48f16c4e88872899b.tar.gz EOF $ make && echo succeed .. succeed Regards, Gael Changes since v1: reword error message as suggested by Arnout. support/download/check-hash | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/support/download/check-hash b/support/download/check-hash index fe9c10570e..663efa014f 100755 --- a/support/download/check-hash +++ b/support/download/check-hash @@ -41,14 +41,12 @@ if [ ! -f "${h_file}" ]; then exit 0 fi -# Check one hash for a file +# Compute hash for a file # $1: algo hash -# $2: known hash -# $3: file (full path) -check_one_hash() { +# $2: file (full path) +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 @@ -67,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 @@ -106,6 +116,13 @@ 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: Please find a hash in the upstream announcement or website and add it to ${h_file}\n" >&2 + printf "ERROR: If upstream doesn't provide a hash and the source is trusted, consider adding these lines:\n" >&2 + printf "# Locally calculated from download\n" >&2 + printf "${h} ${hash} ${base}\n" >&2 exit 3 fi