#!/usr/bin/env bash # Cleanup server # Min. Requirement : GNU/Linux Ubuntu 18.04 # Last Build : 11/12/2021 # Author : MasEDI.Net (me@masedi.net) # Since Version : 1.0.0 # Include helper functions. if [[ "$(type -t run)" != "function" ]]; then BASE_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd ) # shellcheck disable=SC1091 . "${BASE_DIR}/helper.sh" fi # Define scripts directory. if grep -q "scripts" <<< "${BASE_DIR}"; then SCRIPTS_DIR="${BASE_DIR}" else SCRIPTS_DIR="${BASE_DIR}/scripts" fi # Make sure only root can run this installer script. requires_root # Make sure only supported distribution can run this installer script. preflight_system_check echo "Cleaning up server..." # Fix broken install, first? if [[ "${FIX_BROKEN_INSTALL}" == true ]]; then echo "Trying to fix broken packages..." [ -f /var/lib/dpkg/lock ] && run rm /var/lib/dpkg/lock [ -f /var/lib/dpkg/lock-frontend ] && run rm /var/lib/dpkg/lock-frontend [ -f /var/cache/apt/archives/lock ] && run rm /var/cache/apt/archives/lock run dpkg --configure -a run apt-get install -qq -y --fix-broken fi # Remove Apache2 service if exists. if [[ -n $(command -v apache2) || -n $(command -v httpd) ]]; then warning -e "\nIt seems that Apache/httpd server installed on this server." echo "Any other HTTP web server will be removed, otherwise they will conflict." echo "" #read -rt 120 -p "Press [Enter] to continue..." /etc/lemper/lemper.conf" else echo "Found default lemper account, but not removed." fi fi # Autoremove unused packages. echo -e "\nCleaning up unused packages..." run apt-get autoremove -qq -y if [[ -z $(command -v apache2) && -z $(command -v nginx) && -z $(command -v mysql) ]]; then status "Your server cleaned up." else warning "Your server cleaned up, but some installation not removed." fi