From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6788114222392803328 X-Received: by 2002:a7b:c454:: with SMTP id l20mr4317085wmi.189.1583877400568; Tue, 10 Mar 2020 14:56:40 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:adf:cd01:: with SMTP id w1ls8739001wrm.0.gmail; Tue, 10 Mar 2020 14:56:40 -0700 (PDT) X-Google-Smtp-Source: ADFU+vun2hLQjie5bTXKoGh8wDXIxPriBj6WowH1O3S/y9/1pO5xhuXho6/OW5FXvbFxAHqnuIEz X-Received: by 2002:a5d:42c8:: with SMTP id t8mr2475856wrr.415.1583877399959; Tue, 10 Mar 2020 14:56:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583877399; cv=none; d=google.com; s=arc-20160816; b=MJUk0lwPNwj64ao5IVoTkUlVWRGNwq6Ik1wNEsAdjYzokJ7k9tcQvITvewVCwFibZm 60Idex+kOMNPZW1B/4dJ2aHj7TG91+jRsohQ6HsjkQWX/IzEaVUFDZEN/AoSXqWdAaku wK4Xm7dpIEZKnCdYC64DWjgrayH1w256I4gtErqlg/Ja9GOiAA1B73Sg4/8poq33lff/ ikWcpCRwQnMRQAx/uE7eLfP1bxL+HjrMlFzfhGdaSUMqaHbNuGuO44woo/tcufOF7S1D WhvqTVr2Fg35BhUxSghO3Qp/YNHe6F86X4Ih2bKkkhCv8VjMAGNQXa69BqwtC73XOekz R5SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=oC37dbAz+x1ImcuH1WBeJHpfdDe+1qnh7yDi+jf2T94=; b=VAVZ6szXRFzzerr3o5iDHhQHaVNisSaqRBOxMXYepnvIsMit3TcUnmJ7o9ikFuyUa0 MAHVvBi+10+p6PRj26zFhUJEdpjJrxbyfi09/hn1J/+jXKF5iHPaC9YCUnrvx8Ak92EQ 5dcwpsQr0RHju1pMEd0zwVrIPvzGMDnHdMd76VUecmtTEUriUwSihKvXT7oyj9ET39pe gXP/oUcfMYdjdu8GmAJ4Hh08JjTbX1m1VVK0Li0fxFoto8wig1JfNt2m4apzzDiCHz3J 0keL2L8u7bGAjWOfbUttnP9fWiL00nlZa92qYQgEr/LtOwQ8qQq2vr9SULQF/xuJpTTw SbYA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 194.138.37.39 as permitted sender) smtp.mailfrom=henning.schild@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Return-Path: Received: from lizzard.sbs.de (lizzard.sbs.de. [194.138.37.39]) by gmr-mx.google.com with ESMTPS id h15si244576wml.4.2020.03.10.14.56.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Mar 2020 14:56:39 -0700 (PDT) Received-SPF: pass (google.com: domain of henning.schild@siemens.com designates 194.138.37.39 as permitted sender) client-ip=194.138.37.39; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 194.138.37.39 as permitted sender) smtp.mailfrom=henning.schild@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from mail2.sbs.de (mail2.sbs.de [192.129.41.66]) by lizzard.sbs.de (8.15.2/8.15.2) with ESMTPS id 02ALuc05030845 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Mar 2020 22:56:38 +0100 Received: from localhost.localdomain ([139.22.36.172]) by mail2.sbs.de (8.15.2/8.15.2) with ESMTP id 02ALub5j026985; Tue, 10 Mar 2020 22:56:38 +0100 From: Henning Schild To: isar-users@googlegroups.com Cc: Vijai Kumar K , Baurzhan Ismagulov , Jan Kiszka , Henning Schild Subject: [PATCHv5 01/29] repository: new class to deal with repos Date: Tue, 10 Mar 2020 22:56:03 +0100 Message-Id: <20200310215631.24859-2-henning.schild@siemens.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200310215631.24859-1-henning.schild@siemens.com> References: <20200310215631.24859-1-henning.schild@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUID: xfYiLirw3ln0 From: Henning Schild Factor out all the "reprepro" code into a common class. There are slight functional changes since the two copies of the code got out of sync. Signed-off-by: Henning Schild --- meta/classes/base-apt-helper.bbclass | 28 ++++---- meta/classes/dpkg-base.bbclass | 24 ++----- meta/classes/repository.bbclass | 69 +++++++++++++++++++ meta/recipes-devtools/base-apt/base-apt.bb | 37 +++------- .../base-apt/files/distributions.in | 3 - .../isar-apt/files/distributions.in | 3 - meta/recipes-devtools/isar-apt/isar-apt.bb | 26 ++----- 7 files changed, 102 insertions(+), 88 deletions(-) create mode 100644 meta/classes/repository.bbclass delete mode 100644 meta/recipes-devtools/base-apt/files/distributions.in delete mode 100644 meta/recipes-devtools/isar-apt/files/distributions.in diff --git a/meta/classes/base-apt-helper.bbclass b/meta/classes/base-apt-helper.bbclass index 90b2cfcb..6fc57303 100644 --- a/meta/classes/base-apt-helper.bbclass +++ b/meta/classes/base-apt-helper.bbclass @@ -1,5 +1,10 @@ # This software is a part of ISAR. # Copyright (C) 2018 ilbers GmbH +# Copyright (C) 2020 Siemens AG +# +# SPDX-License-Identifier: MIT + +inherit repository compare_pkg_md5sums() { pkg1=$1 @@ -14,10 +19,6 @@ compare_pkg_md5sums() { populate_base_apt() { search_dir=$1 - if [ -n "${GNUPGHOME}" ]; then - export GNUPGHOME="${GNUPGHOME}" - fi - find $search_dir -name '*.deb' | while read package; do # NOTE: due to packages stored by reprepro are not modified, we can # use search by filename to check if package is already in repo. In @@ -40,18 +41,15 @@ populate_base_apt() { compare_pkg_md5sums "$package" "$base_apt_p" && continue # md5sum differs, so remove the package from base-apt - name=$(echo $base_name | cut -d '_' -f 1) - reprepro -b ${REPO_BASE_DIR}/${BASE_DISTRO} \ - --dbdir ${REPO_BASE_DB_DIR}/${BASE_DISTRO} \ - -C main -A ${DISTRO_ARCH} \ - remove ${BASE_DISTRO_CODENAME} \ - $name + repo_del_package "${REPO_BASE_DIR}"/"${BASE_DISTRO}" \ + "${REPO_BASE_DB_DIR}"/"${BASE_DISTRO}" \ + "${BASE_DISTRO_CODENAME}" \ + "${base_apt_p}" fi - reprepro -b ${REPO_BASE_DIR}/${BASE_DISTRO} \ - --dbdir ${REPO_BASE_DB_DIR}/${BASE_DISTRO} \ - -C main \ - includedeb ${BASE_DISTRO_CODENAME} \ - $package + repo_add_packages "${REPO_BASE_DIR}"/"${BASE_DISTRO}" \ + "${REPO_BASE_DB_DIR}"/"${BASE_DISTRO}" \ + "${BASE_DISTRO_CODENAME}" \ + "${package}" done } diff --git a/meta/classes/dpkg-base.bbclass b/meta/classes/dpkg-base.bbclass index 5d2c161c..4702e52b 100644 --- a/meta/classes/dpkg-base.bbclass +++ b/meta/classes/dpkg-base.bbclass @@ -7,6 +7,7 @@ inherit buildchroot inherit debianize inherit terminal +inherit repository DEPENDS ?= "" @@ -142,31 +143,16 @@ repo_clean() { DEBS=$( find ${S}/.. -maxdepth 1 -name "*.deb" || [ ! -d ${S} ] ) if [ -n "${DEBS}" ]; then for d in ${DEBS}; do - p=$( dpkg-deb --show --showformat '${Package}' ${d} ) - a=$( dpkg-deb --show --showformat '${Architecture}' ${d} ) - # removing "all" means no arch - aarg="-A ${a}" - [ "${a}" = "all" ] && aarg="" - reprepro -b ${REPO_ISAR_DIR}/${DISTRO} \ - --dbdir ${REPO_ISAR_DB_DIR}/${DISTRO} \ - -C main ${aarg} \ - remove ${DEBDISTRONAME} \ - ${p} + repo_del_package "${REPO_ISAR_DIR}"/"${DISTRO}" \ + "${REPO_ISAR_DB_DIR}"/"${DISTRO}" "${DEBDISTRONAME}" "${d}" done fi } -# Install package to Isar-apt do_deploy_deb() { - if [ -n "${GNUPGHOME}" ]; then - export GNUPGHOME="${GNUPGHOME}" - fi repo_clean - reprepro -b ${REPO_ISAR_DIR}/${DISTRO} \ - --dbdir ${REPO_ISAR_DB_DIR}/${DISTRO} \ - -C main \ - includedeb ${DEBDISTRONAME} \ - ${S}/../*.deb + repo_add_packages "${REPO_ISAR_DIR}"/"${DISTRO}" \ + "${REPO_ISAR_DB_DIR}"/"${DISTRO}" "${DEBDISTRONAME}" ${S}/../*.deb } addtask deploy_deb after do_dpkg_build before do_build diff --git a/meta/classes/repository.bbclass b/meta/classes/repository.bbclass new file mode 100644 index 00000000..cf0fb5a2 --- /dev/null +++ b/meta/classes/repository.bbclass @@ -0,0 +1,69 @@ +# This software is a part of ISAR. +# Copyright (C) 2017-2020 Siemens AG +# Copyright (C) 2019 ilbers GmbH +# +# SPDX-License-Identifier: MIT + +repo_create() { + local dir="$1" + local dbdir="$2" + local codename="$3" + local keyfiles="$4" + + if [ -n "${GNUPGHOME}" ]; then + export GNUPGHOME="${GNUPGHOME}" + fi + + if [ ! -f "${dir}"/conf/distributions ]; then + mkdir -p "${dir}"/conf/ + cat < "${dir}"/conf/distributions +Codename: ${codename} +Architectures: i386 armhf arm64 amd64 mipsel riscv64 source +Components: main +EOF + if [ -n "${keyfiles}" ] ; then + local option="" + for key in ${keyfiles}; do + keyid=$(gpg --keyid-format 0xlong --with-colons ${key} 2>/dev/null | grep "^pub:" | awk -F':' '{print $5;}') + option="${option}${keyid} " + done + echo "SignWith: ${option}" >> "${dir}"/conf/distributions + fi + fi + if [ ! -d "${dbdir}" ]; then + reprepro -b "${dir}" --dbdir "${dbdir}" export "${codename}" + fi +} + +repo_add_packages() { + local dir="$1" + local dbdir="$2" + local codename="$3" + shift; shift; shift + + if [ -n "${GNUPGHOME}" ]; then + export GNUPGHOME="${GNUPGHOME}" + fi + reprepro -b "${dir}" --dbdir "${dbdir}" -C main \ + includedeb "${codename}" \ + "$@" +} + +repo_del_package() { + local dir="$1" + local dbdir="$2" + local codename="$3" + local file="$4" + + if [ -n "${GNUPGHOME}" ]; then + export GNUPGHOME="${GNUPGHOME}" + fi + local p=$( dpkg-deb --show --showformat '${Package}' "${file}" ) + local a=$( dpkg-deb --show --showformat '${Architecture}' "${file}" ) + # removing "all" means no arch + local aarg="-A ${a}" + [ "${a}" = "all" ] && aarg="" + reprepro -b "${dir}" --dbdir "${dbdir}" -C main ${aarg} \ + remove "${codename}" \ + "${p}" +} diff --git a/meta/recipes-devtools/base-apt/base-apt.bb b/meta/recipes-devtools/base-apt/base-apt.bb index 9a0f7c8b..7c891fa0 100644 --- a/meta/recipes-devtools/base-apt/base-apt.bb +++ b/meta/recipes-devtools/base-apt/base-apt.bb @@ -1,45 +1,24 @@ # This software is a part of ISAR. # Copyright (C) 2018 ilbers GmbH +# Copyright (C) 2020 Siemens AG +# +# SPDX-License-Identifier: MIT -SRC_URI = "file://distributions.in" +inherit repository BASE_REPO_KEY ?= "" KEYFILES ?= "" -CACHE_CONF_DIR = "${REPO_BASE_DIR}/${BASE_DISTRO}/conf" -do_cache_config[dirs] = "${CACHE_CONF_DIR}" do_cache_config[stamp-extra-info] = "${DISTRO}" do_cache_config[lockfiles] = "${REPO_BASE_DIR}/isar.lock" # Generate reprepro config for current distro if it doesn't exist. Once it's # generated, this task should do nothing. repo_config() { - if [ -n "${GNUPGHOME}" ]; then - export GNUPGHOME="${GNUPGHOME}" - fi - - if [ ! -e "${CACHE_CONF_DIR}/distributions" ]; then - sed -e "s#{CODENAME}#"${BASE_DISTRO_CODENAME}"#g" \ - ${WORKDIR}/distributions.in > ${CACHE_CONF_DIR}/distributions - if [ -n "${KEYFILES}" ]; then - option="" - for key in ${KEYFILES}; do - keyid=$(gpg --keyid-format 0xlong --with-colons ${key} 2>/dev/null | grep "^pub:" | awk -F':' '{print $5;}') - option="${option}${keyid} " - done - # To generate Release.gpg - echo "SignWith: ${option}" >> ${CACHE_CONF_DIR}/distributions - fi - fi - - path_cache="${REPO_BASE_DIR}/${BASE_DISTRO}" - path_databases="${REPO_BASE_DB_DIR}/${BASE_DISTRO}" - - if [ ! -d "${path_databases}" ]; then - reprepro -b ${path_cache} \ - --dbdir ${path_databases} \ - export ${BASE_DISTRO_CODENAME} - fi + repo_create "${REPO_BASE_DIR}"/"${BASE_DISTRO}" \ + "${REPO_BASE_DB_DIR}"/"${BASE_DISTRO}" \ + "${BASE_DISTRO_CODENAME}" \ + "${KEYFILES}" } python do_cache_config() { diff --git a/meta/recipes-devtools/base-apt/files/distributions.in b/meta/recipes-devtools/base-apt/files/distributions.in deleted file mode 100644 index 3cf7ea55..00000000 --- a/meta/recipes-devtools/base-apt/files/distributions.in +++ /dev/null @@ -1,3 +0,0 @@ -Codename: {CODENAME} -Architectures: i386 armhf arm64 amd64 mipsel riscv64 source -Components: main diff --git a/meta/recipes-devtools/isar-apt/files/distributions.in b/meta/recipes-devtools/isar-apt/files/distributions.in deleted file mode 100644 index 64717364..00000000 --- a/meta/recipes-devtools/isar-apt/files/distributions.in +++ /dev/null @@ -1,3 +0,0 @@ -Codename: {DISTRO_NAME} -Architectures: i386 armhf arm64 amd64 mipsel riscv64 source -Components: main diff --git a/meta/recipes-devtools/isar-apt/isar-apt.bb b/meta/recipes-devtools/isar-apt/isar-apt.bb index e6f1753d..c53b01f7 100644 --- a/meta/recipes-devtools/isar-apt/isar-apt.bb +++ b/meta/recipes-devtools/isar-apt/isar-apt.bb @@ -1,32 +1,20 @@ # This software is a part of ISAR. # Copyright (C) 2015-2017 ilbers GmbH +# Copyright (C) 2020 Siemens AG +# +# SPDX-License-Identifier: MIT -SRC_URI = "file://distributions.in" +inherit repository -CACHE_CONF_DIR = "${REPO_ISAR_DIR}/${DISTRO}/conf" -do_cache_config[dirs] = "${CACHE_CONF_DIR}" do_cache_config[stamp-extra-info] = "${DISTRO}" do_cache_config[lockfiles] = "${REPO_ISAR_DIR}/isar.lock" # Generate reprepro config for current distro if it doesn't exist. Once it's # generated, this task should do nothing. do_cache_config() { - if [ ! -e "${CACHE_CONF_DIR}/distributions" ]; then - sed -e "s#{DISTRO_NAME}#"${DEBDISTRONAME}"#g" \ - ${WORKDIR}/distributions.in > ${CACHE_CONF_DIR}/distributions - fi - - path_cache="${REPO_ISAR_DIR}/${DISTRO}" - path_databases="${REPO_ISAR_DB_DIR}/${DISTRO}" - - if [ ! -d "${path_databases}" ]; then - if [ -n "${GNUPGHOME}" ]; then - export GNUPGHOME="${GNUPGHOME}" - fi - reprepro -b ${path_cache} \ - --dbdir ${path_databases} \ - export ${DEBDISTRONAME} - fi + repo_create "${REPO_ISAR_DIR}"/"${DISTRO}" \ + "${REPO_ISAR_DB_DIR}"/"${DISTRO}" \ + "${DEBDISTRONAME}" } addtask cache_config after do_unpack before do_build -- 2.24.1