From patchwork Tue Feb 1 13:52:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 5033 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4Jp5x25rVpz3wp0 for ; Tue, 1 Feb 2022 13:53:10 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4Jp5wn4jlxz5HT; Tue, 1 Feb 2022 13:52:57 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4Jp5wn4Tqbz30GR; Tue, 1 Feb 2022 13:52:57 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4Jp5wl0LKtz2xVY for ; Tue, 1 Feb 2022 13:52:55 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4Jp5wk2dBBz4R9; Tue, 1 Feb 2022 13:52:54 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1643723574; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k2QzLTEbTsgNFtvHGgE7jRM6/m6WaaaJQXqOqu37S1A=; b=6B4GFQpf/n/zhrvYA5aEFlxe/Iqgn7nogvPVPLMVO4BAl4KD/2rX/hWZG/22Ao2Jt9DtAe L4FeA1wJXWRsL9CA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1643723574; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k2QzLTEbTsgNFtvHGgE7jRM6/m6WaaaJQXqOqu37S1A=; b=ogINBRnam+u49i/FlW5tQXCWIrR/RL4wM2j56PAam+hBN/veD+5AhO4cBAM0/5KM93sRLP N0wzifQzWsTFnSVzMClelMP954w+N72TO8b/4mWKPYpnX3tHjCftj2ItE1I/PuBCdb0Xdg a606DdmCzDyXViR+WXOLknBrPh9VrD/t/veqGdqe6GcZmsRuZmi0E/V28FGHGT2mMeibn7 penqqAfmaWIb73cRKvkLL1vE5BJABObMZqwXgn+9B6vG3ELKe8PBzBLLwIKGO3F6FmN1hv p8nCdIU25e04GwIs+hXcn5dT0J+fH0U3rLX2CnMhJLFqbZ8tXDZjGZ2vNHWDWA== From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH 08/10] rust: Add script to automatically generate packages Date: Tue, 1 Feb 2022 13:52:44 +0000 Message-Id: <20220201135246.4096955-8-michael.tremer@ipfire.org> In-Reply-To: <20220201135246.4096955-1-michael.tremer@ipfire.org> References: <20220201135246.4096955-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" This is a very tiring and repetitive process which is now automated in this script which will find the latest version and create a LFS file for it. Signed-off-by: Michael Tremer --- tools/download-rust-crate | 82 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 tools/download-rust-crate diff --git a/tools/download-rust-crate b/tools/download-rust-crate new file mode 100755 index 000000000..bae6b60be --- /dev/null +++ b/tools/download-rust-crate @@ -0,0 +1,82 @@ +#!/bin/bash + +set -o pipefail + +RUST_TEMPLATE="lfs/rust-rand" + +fetch_latest_version() { + local name="${1}" + + if ! curl --silent "https://crates.io/api/v1/crates/${name}" | \ + jq --raw-output .crate.max_stable_version; then + echo "${0}: Could not find the latest stable version of ${name}" >&2 + return 1 + fi +} + +main() { + local name="${1}" + local version="${2}" + + if [ -z "${name}" ]; then + echo "${0}: You need to pass a name of a crate" >&2 + return 2 + fi + + if [ -z "${version}" ]; then + version="$(fetch_latest_version "${name}")" + if [ -z "${version}" ]; then + # error message has already been printed + return 1 + fi + fi + + # Compose download URL + local url="https://crates.io/api/v1/crates/${name}/${version}/download" + local download="$(mktemp)" + + # Perform download + if ! curl -L "${url}" -o "${download}"; then + echo "${0}: Could not download ${name}-${version}" >&2 + unlink "${download}" + return 1 + fi + + # Check if download is an orderly tar file + if ! tar tvf "${download}" &>/dev/null; then + echo "${0}: Download is not a tar file" >&2 + unlink "${download}" + return 1 + fi + + # Hash the downloaded file + local md5sum="$(md5sum "${download}" | awk '{ print $1 }')" + if [ -z "${md5sum}" ]; then + echo "${0}: Could not hash download" >&2 + unlink "${download}" + return 1 + fi + + local filename="cache/${name}-${version}.tar.gz" + + # Move to final destination + if ! install -m 644 "${download}" "${filename}"; then + echo "${0}: Could not move downloaded file to ${filename}" >&2 + unlink "${download}" + return 1 + fi + + # Remove download + unlink "${download}" + + # Create a new LFS file + sed < "${RUST_TEMPLATE}" > "lfs/rust-${name}" \ + -e "s/^VER.*/VER = ${version}/" \ + -e "s/^THISAPP.*/THISAPP = ${name}-\$(VER)/" \ + -e "s/^\$(DL_FILE)_MD5.*/\$(DL_FILE)_MD5 = ${md5sum}/" + + echo "Done" + return 0 +} + +main "$@" || exit $?