Do not create duplicate sections in schroot.conf
authorMikolaj Wielgus <wielgusmikolaj@gmail.com>
Fri, 20 Aug 2021 21:31:30 +0000 (23:31 +0200)
committerMikolaj Wielgus <wielgusmikolaj@gmail.com>
Fri, 20 Aug 2021 23:50:07 +0000 (01:50 +0200)
mk-deb-chroot

index 948bd3f95e86d439282ebb9d98de03e8ad1c874f..969930fd8b906f784902f9ea938b688386e492f3 100755 (executable)
@@ -48,8 +48,11 @@ cat <<EOF >/etc/schroot/$chrootdir/fstab
 /tmp            /tmp            none    rw,bind         0       0
 EOF
 
-# Add chroot config to schroot.conf
-cat <<EOF >>/etc/schroot/schroot.conf
+if grep -x "\[$chrootdir\]" /etc/schroot/schroot.conf; then
+    echo "Found [$chrootdir] section in /etc/schroot/schroot.conf"
+else
+    # Add chroot config to schroot.conf
+    cat <<EOF >>/etc/schroot/schroot.conf
 [$chrootdir]
 description=Debian Buster for $chrootdir
 directory=/opt/chroot/$chrootdir
@@ -58,7 +61,7 @@ type=directory
 profile=$chrootdir
 EOF
 
-echo "Adding the following $chrootdir section to /etc/schroot/schroot.conf:
+    echo "Adding the following $chrootdir section to /etc/schroot/schroot.conf:
 
 [$chrootdir]
 description=Debian Buster for $chrootdir
@@ -69,6 +72,7 @@ type=directory
 This enables you to chroot into $chrootdir as an unprivileged user by running
 'schroot -c $chrootdir /bin/bash'
 "
+fi
 
 # Install apt dependencies in the chroot
 cd /tmp