tools/deployment/libvirt/cleanup_network.sh
Michel Thebeau 0a924bc76a deployment: libvirt: make use of rm command safer
Add sanity around the use of 'rm' in script.  Make sure the file to be
deleted is the correct type, and that its content also meets
expectation.

An example of dangerous outcome in this code from using "sudo rm -rf" is
that if the CONTROLLER or COMPUTE variables are preceded by a space
character then the directory /var/lib/libvirt/images/ will be deleted.

Refrain from using recursive and force options, and in this case because
they are not needed.

Related-Bug: #1790716

Change-Id: I76797133589d993dca2b2aac3c97184bac0457ca
Signed-off-by: Michel Thebeau <michel.thebeau@windriver.com>
2018-09-11 11:49:50 -04:00

22 lines
684 B
Bash
Executable File

#!/usr/bin/env bash
#
# cleanup_network.sh - Cleans up network interfaces - not safe to run blindly!
MY_WORKING_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}" )" )"
source ${MY_WORKING_DIR}/functions.sh
NETWORK_DEFAULT=${NETWORK_DEFAULT:-default}
BRIDGE_INTERFACE=${BRIDGE_INTERFACE=stxbr0}
if virsh net-list --name | grep ${NETWORK_DEFAULT} ; then
sudo virsh net-destroy ${NETWORK_DEFAULT}
sudo virsh net-undefine ${NETWORK_DEFAULT}
delete_xml /etc/libvirt/qemu/networks/autostart/${NETWORK_DEFAULT}.xml
fi
if [ -d "/sys/class/net/${BRIDGE_INTERFACE}" ]; then
sudo ifconfig ${BRIDGE_INTERFACE} down || true
sudo brctl delbr ${BRIDGE_INTERFACE} || true
fi