Remove All Looker Related Artifacts From Linux VM

Using a bash script, how to remove all artifacts related to Looker?

Note:

  • This script must be run as root.
  • This script will not delete or modify any files/folders within the Insights directory.

The script will remove the following:

  • looker-container, it it exists
  • looker image, if it exists
  • volumes looker_lookerfiles and looker_workdir, if they exist
  • insights/cert-password, if it exists
  • insights/looker-password, if it exists

#!/bin/bash

# ansi escape code for green color

GREEN='\033[0;32m'

# ansi escape code for yellow color

YELLOW='\033[1;33m'

# ansi escape code to reset color

RESET='\033[0m'

# check if container exists

if docker container ls -a --format '{{.Names}}' | grep -q '^looker-container$'; then

echo -e "${GREEN}removing looker-container...${RESET}"

docker stop looker-container

docker rm looker-container

else

echo -e "${YELLOW}container looker-container does not exist...nothing to delete${RESET}"

fi

# check if image exists

if [[ -z "$(docker images -q)" ]]; then

echo -e "${YELLOW}no images exist...nothing to delete${RESET}"

else

# run docker images command and extract the image ids

image_ids=$(docker images --format "{{.ID}}")

# iterate over the image ids and display them

for image_id in $image_ids; do

echo "image id: $image_id"

done

# prompt for image id to delete

read -p "enter the image id to delete: " image_id_to_delete

# delete the image

docker image rm -f "$image_id_to_delete"

echo -e "${GREEN}image with id $image_id_to_delete has been deleted...${RESET}"

fi

# check if the volume looker_lookerfiles exists

if docker volume ls --format '{{.Name}}' | grep -q '^looker_lookerfiles$'; then

echo -e "${GREEN}removing volume looker_lookerfiles...${RESET}"

docker volume rm looker_lookerfiles

else

echo -e "${YELLOW}volume looker_lookerfiles does not exist...nothing to delete${RESET}"

fi

# check if the volume looker_workdir exists

if docker volume ls --format '{{.Name}}' | grep -q '^looker_workdir$'; then

echo -e "${GREEN}removing volume looker_workdir...${RESET}"

docker volume rm looker_workdir

else

echo -e "${YELLOW}volume looker_workdir does not exist...nothing to delete${RESET}"

fi

# check if the password entry for insights/cert-password exists

if pass show Insights/cert-password >/dev/null 2>&1; then

echo -e "${GREEN}removing password entry for Insights/cert-password...${RESET}"

pass rm -f Insights/cert-password

else

echo -e "${YELLOW}password entry for Insights/cert-password does not exist...nothing to delete${RESET}"

fi

# check if the password entry for insights/looker-password exists

if pass show Insights/looker-password >/dev/null 2>&1; then

echo -e "${GREEN}removing password entry for Insights/looker-password...${RESET}"

pass rm -f Insights/looker-password

else

echo -e "${YELLOW}password entry for Insights/looker-password does not exist...nothing to delete${RESET}"

fi