HIRS/package/linux/aca/aca_remove_setup.sh

86 lines
2.2 KiB
Bash
Raw Normal View History

2023-08-23 20:30:06 +00:00
#!/bin/bash
#####################################################################################
#
# Script to remove ACA setup files and database items.
#
#
#####################################################################################
SCRIPT_DIR=$( dirname -- "$( readlink -f -- "$0"; )"; )
OPTION_IN=$1; # per Fedora packing guidelines: $1 = 1 for an upgrade, 0 for a remove
if [ -z $1 ]; then OPTION_IN="2"; fi # Set if called by command line
case $OPTION_IN in
"0")
echo "Package removal requested"
OPTION="ACA_PKG_REMOVE"
;;
"1")
echo "Package upgrade requested"
OPTION="ACA_UPGRADE"
;;
"2")
echo "ACA Setup removal requested"
OPTION="ACA_SET_REMOVE"
;;
*)
echo "$1 is an unknown parameter for aca_remove_setup"
exit 1
break
;;
esac
2023-08-23 20:30:06 +00:00
LOG_FILE=/dev/null
2024-02-23 20:19:02 +00:00
LOG_DIR="/var/log/hirs/"
2023-08-23 20:30:06 +00:00
# Check for Admin privileges
if [ "$EUID" -ne 0 ]; then
echo "This script requires root. ACA setup not removed. Please run as root."
exit 1
fi
2023-09-18 20:48:29 +00:00
2024-02-23 20:19:02 +00:00
if [ ! -d "/etc/hirs" ]; then
echo "/etc/hirs does not exist, aborting removal."
exit 1
fi
if [ ! -d "/opt/hirs" ]; then
echo "/opt/hirs does not exist, aborting removal."
exit 1
fi
2024-02-23 20:19:02 +00:00
2023-09-18 20:48:29 +00:00
source $SCRIPT_DIR/../db/mysql_util.sh
2024-02-23 20:19:02 +00:00
# Make sure mysql root password is available before continuing...
check_mariadb_install
2023-09-18 20:48:29 +00:00
check_mysql_root
2023-08-23 20:30:06 +00:00
# remove the hrs-db and hirs_db user
if [ $OPTION = "ACA_SET_REMOVE" ] || [ $OPTION = "ACA_PKG_REMOVE" ]; then
pushd $SCRIPT_DIR/../db/ &>/dev/null
./db_drop.sh $DB_ADMIN_PWD
popd &>/dev/null
fi
2023-08-23 20:30:06 +00:00
# remove pki files and config files if not installed by rpm
2023-08-23 20:30:06 +00:00
echo "Removing certificates and config files..."
2024-02-23 20:19:02 +00:00
# Remove /opt/hirs only if not configured by a package based install:
if [ $OPTION = "ACA_SET_REMOVE" ]; then
2024-02-21 18:16:13 +00:00
if [ -d "/etc/hirs" ]; then
rm -rf /etc/hirs >/dev/null 2>&1
fi
if [ -d "/opt/hirs" ]; then
rm -rf /opt/hirs >/dev/null 2>&1
fi
fi
2023-08-23 20:30:06 +00:00
2024-02-23 20:19:02 +00:00
if [ -d $LOG_DIR ]; then
rm -rf $LOG_DIR;
fi
# Remove current ACA process
echo "Shutting down the aca..."
ps axf | grep HIRS_AttestationCAPortal.war | grep -v grep | awk '{print "kill " $1}' | sh >/dev/null 2>&1
2023-10-05 20:05:21 +00:00
echo "ACA setup removal complete."