#!/bin/sh -eu
#
# Copyright (C) 2020 Axis Communications AB
#
# SPDX-License-Identifier: Apache-2.0

do_unmount() {
	[ $# -eq 2 ] || return
	local mounts=
	while read ignore mount ignore; do
		case $mount in
			$1/*|$2/*)
				mounts="$mount $mounts"
				;;
		esac
	done </proc/self/mounts
	[ -z "$mounts" ] || umount $mounts
}

do_unmount /run/k3s /var/lib/rancher/k3s

# The lines below come from install.sh's create_killall() function:
ip link show 2>/dev/null | grep 'master cni0' | while read ignore iface ignore; do
    iface=${iface%%@*}
    [ -z "$iface" ] || ip link delete $iface
done

ip link delete cni0
ip link delete flannel.1
rm -rf /var/lib/cni/
