From ed55eaab73519af8fe451528e04d6986b615f321 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Charaoui?= <jerome@riseup.net>
Date: Sun, 12 Feb 2023 12:14:42 -0500
Subject: [PATCH] install packages with explicit TMPDIR

For package installation, the runner $TMPDIR may not be big enough, eg
when rebuilding an initramfs it runs out of space, so use a new function
that sets it explicitly.
---
 test/borg.bats   | 2 +-
 test/common.bash | 4 ++++
 test/dup.bats    | 2 +-
 test/mysql.bats  | 2 +-
 test/pgsql.bats  | 2 +-
 test/rdiff.bats  | 2 +-
 test/rsync.bats  | 2 +-
 test/sys.bats    | 2 +-
 test/tar.bats    | 2 +-
 9 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/test/borg.bats b/test/borg.bats
index 0a454ac..10fc7e2 100644
--- a/test/borg.bats
+++ b/test/borg.bats
@@ -1,7 +1,7 @@
 load common
 
 begin_borg() {
-    apt-get -qq install debootstrap borgbackup
+    install_pkgs debootstrap borgbackup
     if [ ! -d "$BN_SRCDIR" ]; then
         debootstrap --variant=minbase testing "$BN_SRCDIR"
     fi
diff --git a/test/common.bash b/test/common.bash
index 45c193f..7280180 100644
--- a/test/common.bash
+++ b/test/common.bash
@@ -241,3 +241,7 @@ makegpgkeys() {
     BN_SIGNKEY=$(gpg --keyid-format long -k sign@bntest0 | sed -n '2p' | grep -o '\S\+')
     export BN_SIGNKEY
 }
+
+install_pkgs() {
+    TMPDIR=/tmp DEBIAN_FRONTEND=noninteractive apt-get -qq install $@
+}
diff --git a/test/dup.bats b/test/dup.bats
index 71ce4f5..8136709 100644
--- a/test/dup.bats
+++ b/test/dup.bats
@@ -1,7 +1,7 @@
 load common
 
 begin_dup() {
-    apt-get -qq install debootstrap duplicity trickle
+    install_pkgs debootstrap duplicity trickle
     if [ ! -d /var/cache/bntest ]; then
         debootstrap --variant=minbase testing "$BN_SRCDIR"
     fi
diff --git a/test/mysql.bats b/test/mysql.bats
index 205a94f..ca73656 100644
--- a/test/mysql.bats
+++ b/test/mysql.bats
@@ -1,7 +1,7 @@
 load common
 
 begin_mysql() {
-    apt-get -qq install default-mysql-server
+    install_pkgs install default-mysql-server
     systemctl is-active mysql || systemctl start mysql
     zcat "${BATS_TEST_DIRNAME}/samples/bntest_p8Cz8k.sql.gz" | mysql --defaults-file=/etc/mysql/debian.cnf
     zcat "${BATS_TEST_DIRNAME}/samples/bntest_v11vJj.sql.gz" | mysql --defaults-file=/etc/mysql/debian.cnf
diff --git a/test/pgsql.bats b/test/pgsql.bats
index 163fe8c..3f995d3 100644
--- a/test/pgsql.bats
+++ b/test/pgsql.bats
@@ -1,7 +1,7 @@
 load common
 
 begin_pgsql() {
-    apt-get -qq install postgresql
+    install_pkgs postgresql
     systemctl is-active postgresql || systemctl start postgresql
     sudo -u postgres createuser --superuser root
     createdb bntest_p8Cz8k
diff --git a/test/rdiff.bats b/test/rdiff.bats
index 8a70b77..8f5a450 100644
--- a/test/rdiff.bats
+++ b/test/rdiff.bats
@@ -1,7 +1,7 @@
 load common
 
 begin_rdiff() {
-    apt-get -qq install debootstrap rdiff-backup cstream
+    install_pkgs install debootstrap rdiff-backup cstream
     if [ ! -d /var/cache/bntest ]; then
         debootstrap --variant=minbase testing /var/cache/bntest
     fi
diff --git a/test/rsync.bats b/test/rsync.bats
index 903518d..b33cf5b 100644
--- a/test/rsync.bats
+++ b/test/rsync.bats
@@ -1,7 +1,7 @@
 load common
 
 begin_rsync() {
-    apt-get -qq install debootstrap rsync
+    install_pkgs debootstrap rsync
     if [ ! -d "$BN_SRCDIR" ]; then
         debootstrap --variant=minbase testing "$BN_SRCDIR"
     fi
diff --git a/test/sys.bats b/test/sys.bats
index 439fa35..7e1b67f 100644
--- a/test/sys.bats
+++ b/test/sys.bats
@@ -1,7 +1,7 @@
 load common
 
 begin_sys() {
-    apt-get -qq install debconf-utils hwinfo lvm2 cryptsetup-bin parted
+    install_pkgs debconf-utils hwinfo lvm2 cryptsetup-bin parted
 
     cat << EOF > "${BATS_TMPDIR}/backup.d/test.sys"
 when = manual
diff --git a/test/tar.bats b/test/tar.bats
index a593c84..0846941 100644
--- a/test/tar.bats
+++ b/test/tar.bats
@@ -1,7 +1,7 @@
 load common
 
 begin_tar() {
-    apt-get -qq install debootstrap ncompress zstd
+    install_pkgs debootstrap ncompress zstd
     if [ ! -d "$BN_SRCDIR" ]; then
         debootstrap --variant=minbase testing "$BN_SRCDIR"
     fi
-- 
GitLab