1
1
sovereign-stack/uninstall.sh

90 lines
2.2 KiB
Bash
Raw Normal View History

2023-02-01 19:44:05 +00:00
#!/bin/bash
2023-09-22 23:46:07 +00:00
set -exu
2023-09-22 23:46:07 +00:00
PURGE_INCUS=false
# grab any modifications from the command line.
for i in "$@"; do
case $i in
--purge)
2023-09-22 23:46:07 +00:00
PURGE_INCUS=true
shift
;;
*)
echo "Unexpected option: $1"
exit 1
;;
esac
done
2023-02-01 19:44:05 +00:00
# this script undoes install.sh
2023-09-22 23:46:07 +00:00
if ! command -v incus >/dev/null 2>&1; then
echo "This script requires incus to be installed. Please run 'install.sh'."
2023-03-02 14:46:17 +00:00
exit 1
fi
2023-02-01 19:44:05 +00:00
2023-09-22 23:46:07 +00:00
if ! incus remote get-default | grep -q "local"; then
echo "ERROR: You MUST be on the local remote when uninstalling the SSME."
2023-09-22 23:46:07 +00:00
echo "INFO: You can use 'incus remote switch local' to do this."
exit 1
fi
2023-09-22 23:46:07 +00:00
if ! incus project list | grep -q "default (current)"; then
echo "ERROR: You MUST be on the default project when uninstalling the SSME."
2023-09-22 23:46:07 +00:00
echo "INFO: You can use 'incus project switch default' to do this."
exit 1
fi
2023-09-22 23:46:07 +00:00
if incus list --format csv | grep -q "ss-mgmt"; then
2023-02-01 19:44:05 +00:00
2023-09-22 23:46:07 +00:00
if incus list --format csv -q | grep -q "ss-mgmt,RUNNING"; then
incus stop ss-mgmt
2023-02-01 19:44:05 +00:00
fi
2023-09-22 23:46:07 +00:00
if incus config device list ss-mgmt -q | grep -q "ss-code"; then
incus config device remove ss-mgmt ss-code
2023-03-19 17:49:00 +00:00
fi
2023-03-02 14:46:17 +00:00
2023-09-22 23:46:07 +00:00
if incus config device list ss-mgmt -q | grep -q "ss-root"; then
incus config device remove ss-mgmt ss-root
fi
2023-03-02 14:46:17 +00:00
2023-09-22 23:46:07 +00:00
if incus config device list ss-mgmt -q | grep -q "ss-ssh"; then
incus config device remove ss-mgmt ss-ssh
fi
2023-09-22 23:46:07 +00:00
incus delete ss-mgmt
2023-03-02 14:46:17 +00:00
fi
2023-09-22 23:46:07 +00:00
if [ "$PURGE_INCUS" = true ]; then
2023-02-01 19:44:05 +00:00
2023-09-22 23:46:07 +00:00
if incus profile device list default | grep -q root; then
incus profile device remove default root
fi
2023-02-01 19:44:05 +00:00
2023-09-22 23:46:07 +00:00
if incus profile device list default | grep -q enp5s0; then
incus profile device remove default enp5s0
fi
2023-02-01 19:44:05 +00:00
2023-09-23 16:26:51 +00:00
if incus network list --project default | grep -q incusbr0; then
incus network delete incusbr0
fi
2023-02-01 19:44:05 +00:00
2023-04-07 14:23:04 +00:00
# this file contains the BASE_IMAGE_NAME
. ./deployment/base.sh
2023-09-22 23:46:07 +00:00
if incus image list | grep -q "$UBUNTU_BASE_IMAGE_NAME"; then
incus image delete "$UBUNTU_BASE_IMAGE_NAME"
fi
2023-02-01 19:44:05 +00:00
2023-09-22 23:46:07 +00:00
if incus storage list --format csv | grep -q sovereign-stack; then
incus storage delete sovereign-stack
fi
2023-11-29 19:04:24 +00:00
if dpkg -l | grep -q incus; then
sudo apt purge incus -y
fi
fi