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 #
|
# 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"
|
this_script_name="CrowdSec Removal Script"
|
||||||
formatter_url="https://git.hhf.technology/hhf/TaskFormatter/raw/branch/main/bash_task_formatter/task_formatter.sh"
|
formatter_url="https://git.hhf.technology/hhf/TaskFormatter/raw/branch/main/bash_task_formatter/task_formatter.sh"
|
||||||
scriptname=$0
|
scriptname=$0
|
||||||
|
@ -170,68 +170,100 @@ remove_packages() {
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local remove_cmd=""
|
# First stop and disable all CrowdSec-related services
|
||||||
local cleanup_cmd=""
|
systemctl stop 'crowdsec*' 2>/dev/null
|
||||||
|
systemctl disable 'crowdsec*' 2>/dev/null
|
||||||
|
|
||||||
|
local success=0
|
||||||
|
|
||||||
|
# Debian/Ubuntu systems
|
||||||
if command_exists apt-get; then
|
if command_exists apt-get; then
|
||||||
remove_cmd="apt-get remove --purge -y"
|
# Remove CrowdSec packages
|
||||||
cleanup_cmd="apt-get autoremove -y"
|
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
|
elif command_exists yum; then
|
||||||
remove_cmd="yum remove -y"
|
yum remove -y crowdsec crowdsec-firewall-bouncer-iptables '*crowdsec*' 2>/dev/null
|
||||||
cleanup_cmd="yum autoremove -y"
|
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
|
elif command_exists dnf; then
|
||||||
remove_cmd="dnf remove -y"
|
dnf remove -y crowdsec crowdsec-firewall-bouncer-iptables '*crowdsec*' 2>/dev/null
|
||||||
cleanup_cmd="dnf autoremove -y"
|
dnf autoremove -y 2>/dev/null
|
||||||
|
|
||||||
|
# Remove DNF repository
|
||||||
|
rm -f /etc/yum.repos.d/crowdsec.repo
|
||||||
|
dnf clean all
|
||||||
else
|
else
|
||||||
echo -e "No supported package manager found $CROSS_MARK"
|
echo -e "No supported package manager found $CROSS_MARK"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local success=0
|
echo -e "Packages and repositories removed successfully $CHECK_MARK"
|
||||||
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
|
return 0
|
||||||
else
|
|
||||||
echo -e "Some packages failed to remove $CROSS_MARK"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to remove configuration
|
# Function to remove configuration and additional files
|
||||||
remove_config() {
|
remove_config() {
|
||||||
local config_dirs=(
|
# List of locations to clean
|
||||||
|
local paths_to_clean=(
|
||||||
|
# Configuration directories
|
||||||
"/etc/crowdsec"
|
"/etc/crowdsec"
|
||||||
"/var/lib/crowdsec"
|
"/var/lib/crowdsec"
|
||||||
"/usr/local/lib/crowdsec"
|
"/usr/local/lib/crowdsec"
|
||||||
"/usr/share/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
|
local success=0
|
||||||
for dir in "${config_dirs[@]}"; do
|
for path in "${paths_to_clean[@]}"; do
|
||||||
if [ -d "$dir" ]; then
|
if [ -e "$path" ]; then
|
||||||
if ! rm -rf "$dir" 2>/dev/null; then
|
if ! rm -rf "$path" 2>/dev/null; then
|
||||||
echo -e "Failed to remove directory: $dir $CROSS_MARK"
|
echo -e "Failed to remove: $path $CROSS_MARK"
|
||||||
success=1
|
success=1
|
||||||
|
else
|
||||||
|
echo -e "Removed: $path $CHECK_MARK"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
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
|
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
|
return 0
|
||||||
else
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue