# Ubuntu: sudo apt-get -y install python3 python3-venv qemu-utils kpartx
 # CentOS: sudo yum install -y python3 qemu-img kpartx
 
+# Stop on error (see https://wizardzines.com/comics/bash-errors/)
+set -euo pipefail
+
 usage() {
     echo "Usage: $0 [-l] [-g] [-v]"
     echo "   -l    build NFVbench loop VM image"
 
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 grubby --update-kernel=ALL --args="isolcpus=1-7 rcu_nocbs=1 nohz=on nohz_full=1 nmi_watchdog=0"
 grubby --update-kernel=ALL --args="default_hugepagesz=1G hugepagesz=1G hugepages=4"
 grubby --update-kernel=ALL --args="intel_iommu=on iommu=pt"
 
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 grubby --update-kernel=ALL --args="vga=792"
 
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 grubby --set-default-index=0
 
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 if [ $DIB_USE_ELREPO_KERNEL != "True" ]; then
     exit 0
 fi
 
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 python3 -m pip install --upgrade pip
 python3 -m pip install setuptools wheel pbr
 python3 -m pip install pyyaml
 
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 # set accurate rc.local file corresponding to current image built
 if [ $DIB_DEV_IMAGE = "loopvm" ]; then
     mv /etc/rc.d/rc.local.loopvm /etc/rc.d/rc.local
 else
     mv /etc/rc.d/rc.local.generator /etc/rc.d/rc.local
-fi
\ No newline at end of file
+fi
 
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 chmod +x /etc/rc.d/rc.local
 chmod +x /etc/sysconfig/network-scripts/ifcfg-eth0
 chmod +x /etc/profile.d/nfvbench.sh
 
 #!/bin/bash
 
+# Make sure the disk image build fails if nfvbench installation fails
+set -euo pipefail
+
 if [ $DIB_DEV_IMAGE != "generator" ]; then
     exit 0
 fi
 
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 # Set UseDNS no value in sshd_config to reduce time to connect
-echo "UseDNS no" >> /etc/ssh/sshd_config
\ No newline at end of file
+echo "UseDNS no" >> /etc/ssh/sshd_config
 
 #!/bin/bash
 
+# Stop on error
+set -euo pipefail
+
 yum erase -y python-devel libyaml-devel numactl-devel kernel-devel kernel-headers kernel-lt-headers kernel-lt-devel gcc git python3-dev libpython3.6-dev