Update maintenance/crowdsec_removal.sh
This commit is contained in:
parent
efd36e5cb6
commit
9609920b6f
1 changed files with 70 additions and 38 deletions
|
@ -4,7 +4,7 @@
|
|||
# VARIABLES #
|
||||
#-----------------------------------#
|
||||
|
||||
this_script_url="https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/maintenance/crowdsec-removal.sh" # Replace with actual URL
|
||||
this_script_url="https://example.com/crowdsec-removal.sh" # Replace with actual URL
|
||||
this_script_name="CrowdSec Removal Script"
|
||||
formatter_url="https://git.hhf.technology/hhf/TaskFormatter/raw/branch/main/bash_task_formatter/task_formatter.sh"
|
||||
scriptname=$0
|
||||
|
@ -170,68 +170,100 @@ remove_packages() {
|
|||
return 0
|
||||
fi
|
||||
|
||||
local remove_cmd=""
|
||||
local cleanup_cmd=""
|
||||
# First stop and disable all CrowdSec-related services
|
||||
systemctl stop 'crowdsec*' 2>/dev/null
|
||||
systemctl disable 'crowdsec*' 2>/dev/null
|
||||
|
||||
local success=0
|
||||
|
||||
# Debian/Ubuntu systems
|
||||
if command_exists apt-get; then
|
||||
remove_cmd="apt-get remove --purge -y"
|
||||
cleanup_cmd="apt-get autoremove -y"
|
||||
# Remove CrowdSec packages
|
||||
DEBIAN_FRONTEND=noninteractive apt-get remove --purge -y crowdsec crowdsec-firewall-bouncer-iptables '*crowdsec*' 2>/dev/null
|
||||
DEBIAN_FRONTEND=noninteractive apt-get autoremove -y 2>/dev/null
|
||||
|
||||
# Remove APT repository
|
||||
rm -f /etc/apt/sources.list.d/crowdsec.list
|
||||
apt-get update
|
||||
|
||||
# RHEL/CentOS systems
|
||||
elif command_exists yum; then
|
||||
remove_cmd="yum remove -y"
|
||||
cleanup_cmd="yum autoremove -y"
|
||||
yum remove -y crowdsec crowdsec-firewall-bouncer-iptables '*crowdsec*' 2>/dev/null
|
||||
yum autoremove -y 2>/dev/null
|
||||
|
||||
# Remove YUM repository
|
||||
rm -f /etc/yum.repos.d/crowdsec.repo
|
||||
yum clean all
|
||||
|
||||
# Fedora systems
|
||||
elif command_exists dnf; then
|
||||
remove_cmd="dnf remove -y"
|
||||
cleanup_cmd="dnf autoremove -y"
|
||||
dnf remove -y crowdsec crowdsec-firewall-bouncer-iptables '*crowdsec*' 2>/dev/null
|
||||
dnf autoremove -y 2>/dev/null
|
||||
|
||||
# Remove DNF repository
|
||||
rm -f /etc/yum.repos.d/crowdsec.repo
|
||||
dnf clean all
|
||||
else
|
||||
echo -e "No supported package manager found $CROSS_MARK"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local success=0
|
||||
echo "$packages" | while read -r package; do
|
||||
if ! $remove_cmd "$package"; then
|
||||
echo -e "Failed to remove package: $package $CROSS_MARK"
|
||||
success=1
|
||||
fi
|
||||
done
|
||||
|
||||
if ! $cleanup_cmd; then
|
||||
echo -e "Failed to clean up dependencies $CROSS_MARK"
|
||||
success=1
|
||||
fi
|
||||
|
||||
if [ $success -eq 0 ]; then
|
||||
echo -e "Packages removed successfully $CHECK_MARK"
|
||||
return 0
|
||||
else
|
||||
echo -e "Some packages failed to remove $CROSS_MARK"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo -e "Packages and repositories removed successfully $CHECK_MARK"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Function to remove configuration
|
||||
# Function to remove configuration and additional files
|
||||
remove_config() {
|
||||
local config_dirs=(
|
||||
# List of locations to clean
|
||||
local paths_to_clean=(
|
||||
# Configuration directories
|
||||
"/etc/crowdsec"
|
||||
"/var/lib/crowdsec"
|
||||
"/usr/local/lib/crowdsec"
|
||||
"/usr/share/crowdsec"
|
||||
# Binary and executable files
|
||||
"/usr/local/bin/crowdsec"
|
||||
"/usr/local/bin/cscli"
|
||||
"/usr/bin/crowdsec"
|
||||
"/usr/bin/cscli"
|
||||
# Service files
|
||||
"/etc/systemd/system/crowdsec.service"
|
||||
"/etc/systemd/system/crowdsec-firewall-bouncer.service"
|
||||
"/lib/systemd/system/crowdsec.service"
|
||||
"/lib/systemd/system/crowdsec-firewall-bouncer.service"
|
||||
# Log files
|
||||
"/var/log/crowdsec.log"
|
||||
"/var/log/crowdsec-firewall-bouncer.log"
|
||||
# Additional data directories
|
||||
"/var/run/crowdsec"
|
||||
"/run/crowdsec"
|
||||
# Database files
|
||||
"/var/lib/crowdsec/data/crowdsec.db"
|
||||
)
|
||||
|
||||
local success=0
|
||||
for dir in "${config_dirs[@]}"; do
|
||||
if [ -d "$dir" ]; then
|
||||
if ! rm -rf "$dir" 2>/dev/null; then
|
||||
echo -e "Failed to remove directory: $dir $CROSS_MARK"
|
||||
for path in "${paths_to_clean[@]}"; do
|
||||
if [ -e "$path" ]; then
|
||||
if ! rm -rf "$path" 2>/dev/null; then
|
||||
echo -e "Failed to remove: $path $CROSS_MARK"
|
||||
success=1
|
||||
else
|
||||
echo -e "Removed: $path $CHECK_MARK"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Clean up any remaining crowdsec processes
|
||||
pkill -f crowdsec 2>/dev/null
|
||||
|
||||
# Reload systemd to recognize the changes
|
||||
systemctl daemon-reload 2>/dev/null
|
||||
|
||||
if [ $success -eq 0 ]; then
|
||||
echo -e "Configuration removed successfully $CHECK_MARK"
|
||||
echo -e "All CrowdSec files and configurations removed successfully $CHECK_MARK"
|
||||
return 0
|
||||
else
|
||||
echo -e "Some configuration directories failed to remove $CROSS_MARK"
|
||||
echo -e "Some files or configurations could not be removed $CROSS_MARK"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue