From 6d5cf3aa0b8a7cabc50e091c444b8ed4c73dc1ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Thu, 28 Nov 2019 09:37:33 +0100 Subject: implement --shell-cmd "CMD" option also justify code to have only one place to run the shell or command --- build | 23 +++++++++++++++++++---- build-vm | 8 +++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/build b/build index 93dca5a..ed5e0c9 100755 --- a/build +++ b/build @@ -104,6 +104,7 @@ RSYNCDONE= SIGNDUMMY= DO_STATISTICS= RUN_SHELL= +RUN_SHELL_CMD= CCACHE= DLNOSIGNATURE= BUILD_FLAVOR= @@ -163,6 +164,10 @@ Known Parameters: --shell Instead of starting a build start a root shell in the build root. + --shell-cmd CMD + Run the command CMD instead of giving a root shell + --shell option is implicit set. + --sysrq $ Sends a single specifed char as sysrq to the running kernel of the build. @@ -1019,6 +1024,12 @@ while test -n "$1"; do RUN_SHELL=1 shift ;; + -shell-cmd) + needarg + RUN_SHELL=1 + RUN_SHELL_CMD="$ARG" + shift + ;; -signdummy) SIGNDUMMY=1 ;; @@ -1383,10 +1394,14 @@ for RECIPEFILE in "${RECIPEFILES[@]}" ; do setupccache if test -n "$RUN_SHELL" ; then - echo "You may want to initialize environment via:" - echo " su - $BUILD_USER" - chroot $BUILD_ROOT - cleanup_and_exit 0 + if test -z "$RUN_SHELL_CMD" ; then + echo "" + echo "You may want to initialize environment via:" + echo " su - $BUILD_USER" + echo "" + fi + chroot $BUILD_ROOT "${RUN_SHELL_CMD:=/bin/bash}" + cleanup_and_exit $? fi # fill build directories with sources. Also sets TOPDIR diff --git a/build-vm b/build-vm index 0f53c66..0681797 100644 --- a/build-vm +++ b/build-vm @@ -863,6 +863,7 @@ vm_first_stage() { echo ")" >> $BUILD_ROOT/.build/build.data echo "VM_TYPE='$VM_TYPE'" >> $BUILD_ROOT/.build/build.data echo "RUN_SHELL='$RUN_SHELL'" >> $BUILD_ROOT/.build/build.data + echo "RUN_SHELL_CMD='$RUN_SHELL_CMD'" >> $BUILD_ROOT/.build/build.data echo "DO_STATISTICS='$DO_STATISTICS'" >> $BUILD_ROOT/.build/build.data echo "TIME_PREINSTALL='$TIME_PREINSTALL'" >> $BUILD_ROOT/.build/build.data echo "VM_WATCHDOG='$VM_WATCHDOG'" >> $BUILD_ROOT/.build/build.data @@ -881,11 +882,8 @@ vm_first_stage() { umount -n $BUILD_ROOT/mnt 2> /dev/null || true vm_init_script="/.build/build" - if test -n "$RUN_SHELL"; then - vm_init_script="/bin/bash" - fi if check_use_emulator ; then - vm_init_script="/.build/$INITVM_NAME" + vm_init_script="/.build/$INITVM_NAME" fi if test -n "$VM_ROOT" ; then # copy out kernel & initrd (if they exist) during unmounting VM image @@ -936,7 +934,7 @@ vm_first_stage() { fi vm_attach_root - if test -n "$VM_SWAP" ; then + if test -n "$VM_SWAP" -a -z "$RUN_SHELL" ; then vm_attach_swap BUILDSTATUS=$(dd if="$VM_SWAP" bs=12 count=1 2>/dev/null | tr '\0' a) case $BUILDSTATUS in -- cgit v1.2.3