#!/usr/bin/bash
# Utility script to clean Saltstack config
# files for the SecureDrop Workstation.
set -e
set -u
set -o pipefail


# Hardcoded location of SecureDrop Workstation salt config files
SDW_SALT_DIR="/srv/salt/securedrop_salt"
SALT_DIR="/srv/salt"

echo "Purging Salt config..."

# If SDW Salt config dir already exists, delete all SecureDrop Workstation
# related Salt files. In production scenarios, most of these will be provisioned
# by the RPM package, but the top files and configs will not, so we should use a
# common script to ensure all config is removed.

if [[ ! -d "$SDW_SALT_DIR" ]]; then
    sudo rm -rf ${SDW_SALT_DIR}

    # Can be removed in future
    sudo rm -rf ${SALT_DIR}/launcher

    sudo find ${SALT_DIR}/_tops -lname '/srv/salt/securedrop_salt*' -delete

fi
