-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathquickclean.sh
More file actions
executable file
·45 lines (38 loc) · 1.29 KB
/
quickclean.sh
File metadata and controls
executable file
·45 lines (38 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
set -euo pipefail
LVM_DISK="/var/lib/microshift-okd/lvmdisk.image"
LVM_CONFIG="/etc/systemd/system/microshift.service.d/99-lvm-config.conf"
VG_NAME="myvg1"
# Check if the script is running as root
if [ "$(id -u)" -ne 0 ]; then
echo "ERROR: This script must be run as root (use sudo)"
exit 1
fi
# Clean up the MicroShift container and image
image_ref="$(podman inspect --format '{{.Image}}' microshift-okd 2>/dev/null || true)"
if [ -n "${image_ref:-}" ]; then
podman rm -f --time 0 microshift-okd || true
podman rmi -f "${image_ref}" || true
fi
# Clean up the MicroShift data and uninstall RPMs
if rpm -q microshift &>/dev/null ; then
echo y | microshift-cleanup-data --all
# Remove the LVM configuration
if [ -f "${LVM_CONFIG}" ] ; then
rm -f "${LVM_CONFIG}"
systemctl daemon-reload
fi
dnf remove -y 'microshift*'
# Undo post-installation configuration
rm -f /etc/sysctl.d/99-microshift.conf
rm -f /root/.kube/config
fi
# Remove the LVM disk
if [ -f "${LVM_DISK}" ]; then
lvremove -y "${VG_NAME}" || true
vgremove -y "${VG_NAME}" || true
DEVICE_NAME="$(losetup -j "${LVM_DISK}" | cut -d: -f1)"
# shellcheck disable=SC2086
[ -n "${DEVICE_NAME}" ] && losetup -d ${DEVICE_NAME}
rm -rf "$(dirname "${LVM_DISK}")"
fi