public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Anton Mikanovich <amikan@ilbers.de>
To: isar-users@googlegroups.com
Cc: Anton Mikanovich <amikan@ilbers.de>
Subject: [PATCH v2 1/4] sbuild: Allow setting custom config paths
Date: Fri, 30 Dec 2022 22:08:21 +0300	[thread overview]
Message-ID: <20221230190824.12256-2-amikan@ilbers.de> (raw)
In-Reply-To: <20221230190824.12256-1-amikan@ilbers.de>

Extend internal schroot APIs to be able to set custom chroot config
name. This will allow to configure/unconfigure schroots from any task.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 meta/classes/sbuild.bbclass | 51 +++++++++++++++++++++++++++----------
 1 file changed, 38 insertions(+), 13 deletions(-)

diff --git a/meta/classes/sbuild.bbclass b/meta/classes/sbuild.bbclass
index 6e3c790c..06c01d67 100644
--- a/meta/classes/sbuild.bbclass
+++ b/meta/classes/sbuild.bbclass
@@ -31,10 +31,18 @@ SBUILD_CONFIG="${WORKDIR}/sbuild.conf"
 
 schroot_create_configs() {
     mkdir -p "${TMPDIR}/schroot-overlay"
-    sudo -s <<'EOSUDO'
+
+    conf_dir="${SBUILD_CONF_DIR}"
+    conf_file="${SCHROOT_CONF_FILE}"
+    if [ -n "$1" ]; then
+        conf_dir="${SCHROOT_CONF}/${1}"
+        conf_file="${SCHROOT_CONF}/chroot.d/${1}"
+    fi
+    export conf_dir conf_file
+    sudo -E -s <<'EOSUDO'
         set -e
 
-        cat << EOF > "${SCHROOT_CONF_FILE}"
+        cat << EOF > "${conf_file}"
 [${SBUILD_CHROOT}]
 type=directory
 directory=${SCHROOT_DIR}
@@ -51,8 +59,8 @@ preserve-environment=true
 EOF
 
         # Prepare mount points
-        cp -rf "${SCHROOT_CONF}/sbuild" "${SBUILD_CONF_DIR}"
-        sbuild_fstab="${SBUILD_CONF_DIR}/fstab"
+        cp -rf "${SCHROOT_CONF}/sbuild" "${conf_dir}"
+        sbuild_fstab="${conf_dir}/fstab"
 
         fstab_baseapt="${REPO_BASE_DIR} /base-apt none rw,bind 0 0"
         grep -qxF "${fstab_baseapt}" ${sbuild_fstab} || echo "${fstab_baseapt}" >> ${sbuild_fstab}
@@ -68,12 +76,19 @@ EOSUDO
 }
 
 schroot_delete_configs() {
-    sudo -s <<'EOSUDO'
+    conf_dir="${SBUILD_CONF_DIR}"
+    conf_file="${SCHROOT_CONF_FILE}"
+    if [ -n "$1" ]; then
+        conf_dir="${SCHROOT_CONF}/${1}"
+        conf_file="${SCHROOT_CONF}/chroot.d/${1}"
+    fi
+    export conf_dir conf_file
+    sudo -E -s <<'EOSUDO'
         set -e
-        if [ -d "${SBUILD_CONF_DIR}" ]; then
-            rm -rf "${SBUILD_CONF_DIR}"
+        if [ -d "${conf_dir}" ]; then
+            rm -rf "${conf_dir}"
         fi
-        rm -f "${SCHROOT_CONF_FILE}"
+        rm -f "${conf_file}"
 EOSUDO
 }
 
@@ -107,22 +122,32 @@ sbuild_export() {
 }
 
 insert_mounts() {
-    sudo -s <<'EOSUDO'
+    conf_dir="${SBUILD_CONF_DIR}"
+    if [ -n "$1" ]; then
+        conf_dir="${SCHROOT_CONF}/${1}"
+    fi
+    export conf_dir
+    sudo -E -s <<'EOSUDO'
         set -e
         for mp in ${SCHROOT_MOUNTS}; do
             FSTAB_LINE="${mp%%:*} ${mp#*:} none rw,bind 0 0"
-            grep -qxF "${FSTAB_LINE}" ${SBUILD_CONF_DIR}/fstab || \
-                echo "${FSTAB_LINE}" >> ${SBUILD_CONF_DIR}/fstab
+            grep -qxF "${FSTAB_LINE}" ${conf_dir}/fstab || \
+                echo "${FSTAB_LINE}" >> ${conf_dir}/fstab
         done
 EOSUDO
 }
 
 remove_mounts() {
-    sudo -s <<'EOSUDO'
+    conf_dir="${SBUILD_CONF_DIR}"
+    if [ -n "$1" ]; then
+        conf_dir="${SCHROOT_CONF}/${1}"
+    fi
+    export conf_dir
+    sudo -E -s <<'EOSUDO'
         set -e
         for mp in ${SCHROOT_MOUNTS}; do
             FSTAB_LINE="${mp%%:*} ${mp#*:} none rw,bind 0 0"
-            sed -i "\|${FSTAB_LINE}|d" ${SBUILD_CONF_DIR}/fstab
+            sed -i "\|${FSTAB_LINE}|d" ${conf_dir}/fstab
         done
 EOSUDO
 }
-- 
2.17.1


  reply	other threads:[~2022-12-30 19:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-30 19:08 [PATCH v2 0/4] Imager schroot migration Anton Mikanovich
2022-12-30 19:08 ` Anton Mikanovich [this message]
2022-12-30 19:08 ` [PATCH v2 2/4] imager: Migrate from buildchroot to schroot Anton Mikanovich
2022-12-30 19:08 ` [PATCH v2 3/4] imager: Move image types " Anton Mikanovich
2022-12-30 19:08 ` [PATCH v2 4/4] events: Cleanup lost schroot sessions if any Anton Mikanovich
2023-01-03  9:55   ` Roberto A. Foglietta
2023-01-04 11:19     ` Roberto A. Foglietta
2022-12-30 19:13 ` [PATCH v2 0/4] Imager schroot migration Anton Mikanovich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221230190824.12256-2-amikan@ilbers.de \
    --to=amikan@ilbers.de \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox