]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
testing: Run commands in chroot in a login shell
authorTobias Brunner <tobias@strongswan.org>
Fri, 15 Aug 2025 12:36:45 +0000 (14:36 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 18 Sep 2025 09:13:32 +0000 (11:13 +0200)
Similar to the previous commit, this ensures we have the same environment
we do later on the system.

testing/scripts/function.sh

index c162044e511872cf51e362e79ec45cc118e7ff93..faf968f9b6c71fd9f7719dab71251d41f10cdb8b 100755 (executable)
@@ -48,9 +48,23 @@ execute()
 
 # execute command in chroot
 # $1 - command to execute
+# $2 - whether or not to log command exit status
+#      (0 -> disable exit status logging)
 execute_chroot()
 {
-       execute "chroot $LOOPDIR env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin $@"
+       cmd=${1}
+       echo chroot $LOOPDIR $cmd >>$LOGFILE 2>&1
+       chroot $LOOPDIR /bin/bash -l <<-EOF >>$LOGFILE 2>&1
+               $cmd
+       EOF
+       status=$?
+       [ "$2" != 0 ] && log_status $status
+       if [ $status != 0 ]; then
+               echo
+               echo "! Command chroot $LOOPDIR $cmd failed, exiting (status $status)"
+               echo "! Check why here $LOGFILE"
+               exit 1
+       fi
 }
 
 # write green status message to console