From 2866a0e47e3b2c80d7f3c2c94d415f69fab589ec Mon Sep 17 00:00:00 2001 From: mathieulaunay <54592312+mathieulaunay@users.noreply.github.com> Date: Tue, 21 Feb 2023 17:40:25 +0100 Subject: [PATCH] build: add an env var to run make reset unattended (#13821) previously "make reset" was expecting user input from the terminal to do its job setting UNATTENDED to any non-zero string will allow "make reset" to run without interactive confirmation - Why I did it This is the backport to 202211 from master (see PR #12207) When doing automated builds of SONiC images, we need to reset the working repositories between each build. - How I did it Adding an environment variable that is read by Makefile.work - How to verify it running UNATTENDED=1 make reset should make an automatic reset of all working directories --- Makefile.work | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/Makefile.work b/Makefile.work index 8db05e43c575..04ffc7c5ab2c 100644 --- a/Makefile.work +++ b/Makefile.work @@ -53,6 +53,10 @@ # * ENABLE_BOOTCHART: Enable SONiC bootchart # * Default: n # * Values: y,n +# * UNATTENDED: Don't wait for interactive input from terminal, setting this +# * value to anything will enable it +# * Default: unset +# * Value: y # ############################################################################### @@ -585,23 +589,28 @@ init : .ONESHELL : reset reset : - $(Q)echo && echo -n "Warning! All local changes will be lost. Proceed? [y/N]: " - $(Q)read ans && ( - if [ $$ans == y ]; then - echo "Resetting local repository. Please wait..."; - sudo rm -rf fsroot*; - if [ "$(MULTIARCH_QEMU_ENVIRON)" == y ] && [[ "$(CONFIGURED_ARCH)" == "armhf" || "$(CONFIGURED_ARCH)" == "arm64" ]]; then - echo "Stopping march $(CONFIGURED_ARCH) docker" - sudo kill -9 `sudo cat /var/run/march/docker.pid` || true - sudo rm -f /var/run/march/docker.pid || true - fi - git clean -xfdf; - git reset --hard; - git submodule foreach --recursive 'git clean -xfdf || true'; - git submodule foreach --recursive 'git reset --hard || true'; - git submodule foreach --recursive 'git remote update || true'; - git submodule update --init --recursive; - echo "Reset complete!"; - else - echo "Reset aborted"; - fi ) + $(Q)echo && ( + if [ -z "$(UNATTENDED)" ]; then + echo -n "Warning! All local changes will be lost. Proceed? [y/N]: " + @read ans + else + ans=y + fi + if [ $$ans == y ]; then + echo "Resetting local repository. Please wait..."; + sudo rm -rf fsroot*; + if [ "$(MULTIARCH_QEMU_ENVIRON)" == y ] && [[ "$(CONFIGURED_ARCH)" == "armhf" || "$(CONFIGURED_ARCH)" == "arm64" ]]; then + echo "Stopping march $(CONFIGURED_ARCH) docker" + sudo kill -9 `sudo cat /var/run/march/docker.pid` || true + sudo rm -f /var/run/march/docker.pid || true + fi + git clean -xfdf; + git reset --hard; + git submodule foreach --recursive 'git clean -xfdf || true'; + git submodule foreach --recursive 'git reset --hard || true'; + git submodule foreach --recursive 'git remote update || true'; + git submodule update --init --recursive; + echo "Reset complete!"; + else + echo "Reset aborted"; + fi )