config/scripts/.cleanup.sh
2023-06-26 15:20:23 +02:00

44 lines
997 B
Bash
Executable File

#!/bin/bash
stopdls() {
if docker ps | grep -q " $DLS_CTR_NAME$"; then
pinfo "Stopping Direktil Local Server..."
docker stop $DLS_CTR_NAME
fi
}
cleanuppaths() {
PATHS="data secrets kubeconfig cache dist"
cd $ctxdir
for path in $PATHS; do
if test -e $path; then
pinfo "Removing path $path ..."
rm -rf $path
fi
done
}
cleanupnetwork() {
if iptables -L -n |grep -q $QEMU_BR_NAME; then
pinfo "Cleaning iptables rules..."
iptables -t nat -D POSTROUTING -j MASQUERADE -s $QEMU_BR_IP/$QEMU_BR_MASK \! -o $QEMU_BR_NAME
iptables -D FORWARD -o $QEMU_BR_NAME -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -D FORWARD -j ACCEPT -i $QEMU_BR_NAME
fi
if ip li show $QEMU_BR_NAME &>/dev/null; then
pinfo "Cleaning existing interfaces..."
ip li set $QEMU_BR_NAME down
ip li del $QEMU_BR_NAME
fi
}
source $(dirname $0)/.common
check_root
prereqs
stopdls
declare -A hosts
get_hosts
destroyvms
cleanuppaths
cleanupnetwork