From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6788114222392803328 X-Received: by 2002:ac2:5282:: with SMTP id q2mr5624464lfm.17.1580481003684; Fri, 31 Jan 2020 06:30:03 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a2e:6809:: with SMTP id c9ls114138lja.1.gmail; Fri, 31 Jan 2020 06:30:03 -0800 (PST) X-Google-Smtp-Source: APXvYqy+UqOh0yuUJGtOQWcsHncdQTfkOVSDUYEvxyoqGk8F+JP9kGlW+Nmbn1jEHWGa8gM1Mk6u X-Received: by 2002:a05:651c:d4:: with SMTP id 20mr5939360ljr.269.1580481003023; Fri, 31 Jan 2020 06:30:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580481003; cv=none; d=google.com; s=arc-20160816; b=DKXvkbfgFd+vx/TMZb+i9shAev/rZFEcMhH3yFkHsGjqFJqtITGx/YvRI/ubAk7NKL GxLVFNslIrP7kW/A+i9AoqIzQOK6LAxnnkHh5dr3/+X9M08/bBpHKT7Wie/M4TXFZs2q EkC4c9g3PfJCQ3c9tvAl+HNA0tbTCPFwYWICNZG9NEJngPvZ74hG1y0hwyRNAqZf/Zty 3cL4wbCeEe7y52LIPvd8hfqtJZHvDhG9jezchJT6SSnzqtip3Q1l34UK5KPzJQhm1PCC BgmxzSWt88UHwRyUEft0sUgf47k4v2Hh0RiXuGD3P11eGftYQOaXeHK5JNsdAoanzFQP xXSw== 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=la2GzjtT9BQttNpp3X70T+hQ605RvXE+bTOgKC3sHUw=; b=ueMRkxWCq0phQT6A6rXdb4L5zIpHCd/2i5UTPZt0JCDw/KmVpCKKcmm/BnmdOEeFfE kxc3FfczZ09zrb78FaAB9X3tCh1jC8Kqti1OmHG8Al/gFuwA3bksNZYKRGVjXVXq3Xgb q6ETt+Aol1gZ16qFdeU6IBlWqjpI04v2sd0RF1jMxivsQQqWkRF6snlJszFR9DFbVzQb uQEKqHgHxyxwUtaOYSKJbMKH2EKa4oy6OC7iOC7RTufHtgOR9XZNciPyqDyvJPmPmwUB vYWzeNSGNfl3b0eiXFTi6UBD553ZBNZd8eLyJwxmL6G9+momkaUqtwcGf0xb4j2gBF0y XJXQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.14 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 david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id p12si519205lji.1.2020.01.31.06.30.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jan 2020 06:30:02 -0800 (PST) Received-SPF: pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.14 as permitted sender) client-ip=192.35.17.14; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=henning.schild@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from mail1.sbs.de (mail1.sbs.de [192.129.41.35]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id 00VEU1n7027016 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 31 Jan 2020 15:30:01 +0100 Received: from md1za8fc.ad001.siemens.net ([139.25.68.229]) by mail1.sbs.de (8.15.2/8.15.2) with ESMTP id 00VEU1RF030231; Fri, 31 Jan 2020 15:30:01 +0100 From: Henning Schild To: isar-users@googlegroups.com Cc: Vijai Kumar K , Henning Schild Subject: [PATCHv4 01/26] repository: new class to deal with repos Date: Fri, 31 Jan 2020 15:29:35 +0100 Message-Id: <20200131143000.14873-2-henning.schild@siemens.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200131143000.14873-1-henning.schild@siemens.com> References: <20200131143000.14873-1-henning.schild@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUID: gL9pr68xdA/b 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..1f08c703 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) 2019 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 af9c9840..f38168c7 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 ?= "" @@ -140,31 +141,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..880ddefc --- /dev/null +++ b/meta/classes/repository.bbclass @@ -0,0 +1,69 @@ +# This software is a part of ISAR. +# Copyright (C) 2017-2019 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 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..c9a7dad1 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) 2019 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 fd7de0b7..00000000 --- a/meta/recipes-devtools/base-apt/files/distributions.in +++ /dev/null @@ -1,3 +0,0 @@ -Codename: {CODENAME} -Architectures: i386 armhf arm64 amd64 mipsel 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 a24a7000..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 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..0227c1b0 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) 2019 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