From 947e86f7c37fc231cd49ccfda9a5c93464d876df Mon Sep 17 00:00:00 2001 From: bunkerity Date: Mon, 12 Jul 2021 15:56:01 +0200 Subject: [PATCH] linux - uninstall script --- helpers/bunkerized-nginx | 0 helpers/docker.sh | 0 helpers/install.sh | 10 +++--- helpers/uninstall.sh | 71 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 5 deletions(-) mode change 100644 => 100755 helpers/bunkerized-nginx mode change 100644 => 100755 helpers/docker.sh mode change 100644 => 100755 helpers/install.sh create mode 100755 helpers/uninstall.sh diff --git a/helpers/bunkerized-nginx b/helpers/bunkerized-nginx old mode 100644 new mode 100755 diff --git a/helpers/docker.sh b/helpers/docker.sh old mode 100644 new mode 100755 diff --git a/helpers/install.sh b/helpers/install.sh old mode 100644 new mode 100755 index b7edd31..ee614c3 --- a/helpers/install.sh +++ b/helpers/install.sh @@ -748,19 +748,19 @@ echo "[*] Prepare log files and folders" if [ ! -e "/var/log/nginx" ] ; then do_and_check_cmd mkdir /var/log/nginx fi -if [ ! -e /var/log/nginx/access.log ] ; then +if [ ! -e "/var/log/nginx/access.log" ] ; then do_and_check_cmd touch /var/log/nginx/access.log fi -if [ ! -e /var/log/nginx/error.log ] ; then +if [ ! -e "/var/log/nginx/error.log" ] ; then do_and_check_cmd touch /var/log/nginx/error.log fi -if [ ! -e /var/log/nginx/modsec_audit.log ] ; then +if [ ! -e "/var/log/nginx/modsec_audit.log" ] ; then do_and_check_cmd touch /var/log/nginx/modsec_audit.log fi -if [ ! -e /var/log/nginx/jobs.log ] ; then +if [ ! -e "/var/log/nginx/jobs.log" ] ; then do_and_check_cmd touch /var/log/nginx/jobs.log fi -if [ ! -e /var/log/nginx/ui.log ] ; then +if [ ! -e "/var/log/nginx/ui.log" ] ; then do_and_check_cmd touch /var/log/nginx/ui.log fi do_and_check_cmd chown -R root:nginx /var/log/nginx diff --git a/helpers/uninstall.sh b/helpers/uninstall.sh new file mode 100755 index 0000000..6223ba4 --- /dev/null +++ b/helpers/uninstall.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +function do_and_check_cmd() { + if [ "$CHANGE_DIR" != "" ] ; then + cd "$CHANGE_DIR" + fi + output=$("$@" 2>&1) + ret="$?" + if [ $ret -ne 0 ] ; then + echo "[!] Error from command : $*" + echo "$output" + exit $ret + fi + #echo $output + return 0 +} + + +# Check if we are root +if [ $(id -u) -ne 0 ] ; then + echo "[!] Run me as root" + exit 1 +fi + +# Detect OS +OS="" +if [ "$(grep Debian /etc/os-release)" != "" ] ; then + OS="debian" +elif [ "$(grep Ubuntu /etc/os-release)" != "" ] ; then + OS="ubuntu" +elif [ "$(grep CentOS /etc/os-release)" != "" ] ; then + OS="centos" +elif [ "$(grep Alpine /etc/os-release)" != "" ] ; then + OS="alpine" +fi +if [ "$OS" = "" ] ; then + echo "[!] Unsupported Operating System" + exit 1 +fi + +# Remove /opt/bunkerized-nginx +if [ -e "/opt/bunkerized-nginx" ] ; then + echo "[*] Remove /opt/bunkerized-nginx" + do_and_check_cmd rm -rf /opt/bunkerized-nginx +fi + +# Remove UI service +if [ -e "/etc/systemd/system/bunkerized-nginx-ui.service" ] ; then + echo "[*] Remove bunkerized-nginx-ui service" + do_and_check_cmd systemctl stop bunkerized-nginx-ui + do_and_check_cmd systemctl disable bunkerized-nginx-ui + do_and_check_cmd rm -f /etc/systemd/system/bunkerized-nginx-ui.service + do_and_check_cmd systemctl daemon-reload + do_and_check_cmd systemctl reset-failed +fi + +# Remove cron +echo "[*] Remove cron" +if [ "$OS" = "debian" ] || [ "$OS" = "ubuntu" ] ; then + CRON_PATH="/var/spool/cron/crontabs/nginx" +elif [ "$OS" = "centos" ] ; then + CRON_PATH="/var/spool/cron/nginx" +elif [ "$OS" = "alpine" ] ; then + CRON_PATH="/etc/crontabs/nginx" +fi +if [ -e "$CRON_PATH" ] ; then + do_and_check_cmd rm -f "$CRON_PATH" +fi + +# We're done +echo "[*] bunkerized-nginx successfully uninstalled"