File: //scripts/uninstall-codeguard
#!/bin/bash
# uninstall-codeguard
# Created by David Koston (dave@kostonconsulting.com) for CodeGuard (codeguard.com)
# Copyright (c) 2014 Koston Consulting. All rights reserved. Copying is prohibited
# The following code is subject to the ________ license
# This license can be found at /usr/local/cpanel/3rdparty/codeguard/LICENSE
# Unauthorized use is prohibited
STATUS=UNINSTALLING
APP=CODEGUARD
CPANELPLUGINFILE=/var/cpanel/codeguard/lib/configs/codeguard.cpanelplugin
WHMINSTALLDIR=/usr/local/cpanel/whostmgr/docroot/cgi/addons/codeguard
#CPANELINSTALLDIR=/usr/local/cpanel/base/3rdparty/codeguard
CPANELINSTALLDIR=/usr/local/cpanel/base/frontend/x3/codeguard
PAPERLANTERNINSTALLDIR=/usr/local/cpanel/base/frontend/paper_lantern/codeguard
INSTALLDIR=/var/cpanel/codeguard
function check_for_root(){
#Check for root
USER=`whoami`
if [[ "$USER" -ne "root" ]]; then
echo "This script can only be run by root"
exit
fi
}
function remove_cpanel_files(){
if [ -d ${CPANELINSTALLDIR} ]; then
rm -rf ${CPANELINSTALLDIR}
fi
}
function remove_paperlantern_files(){
if [ -d ${PAPERLANTERNINSTALLDIR} ]; then
rm -rf ${PAPERLANTERNINSTALLDIR}
fi
}
function remove_whm_files(){
if [ -d ${WHMINSTALLDIR} ]; then
rm -rf ${WHMINSTALLDIR}
fi
}
function remove_app_files(){
if [ -d ${INSTALLDIR} ]; then
rm -rf ${INSTALLDIR}
fi
}
function remove_icons(){
echo " ${STATUS} 'CodeGuard' icon"
/usr/local/cpanel/bin/unregister_cpanelplugin "${CPANELPLUGINFILE}" >/dev/null 2>&1
}
function unregister_appconfig(){
#APPCONFIG=$(/usr/local/cpanel/bin/show_appconfig)
#if [[ $APPCONFIG =~ codeguard\-whm\-appconfig\-v2 ]]; then
# echo ""
#else
echo "....."
echo ""
echo " UNREGISTERING ${APP} for WHM with cPanel's AppConfig system"
echo ""
/usr/local/cpanel/bin/unregister_appconfig /var/cpanel/codeguard/lib/configs/codeguard-whm-appconfig-v2.conf >/dev/null 2>&1
/usr/local/cpanel/bin/unregister_appconfig /var/cpanel/apps/codeguard-whm-appconfig-v2.conf >/dev/null 2>&1
echo "....."
#fi
#if [[ $APPCONFIG =~ codeguard\-cpanel\-appconfig\-v2 ]]; then
# echo ""
#else
echo "....."
echo ""
echo " UNREGISTERING ${APP} for cPanel with cPanel's AppConfig system"
echo ""
/usr/local/cpanel/bin/unregister_appconfig /var/cpanel/codeguard/lib/configs/codeguard-cpanel-appconfig-v2.conf >/dev/null 2>&1
/usr/local/cpanel/bin/unregister_appconfig /var/cpanel/apps/codeguard-cpanel-appconfig-v2.conf >/dev/null 2>&1
rm -f /usr/local/cpanel/base/frontend/x3/dynamicui/dynamicui_codeguard_backups.conf >/dev/null 2>&1
rm -f /usr/local/cpanel/base/frontend/paper_lantern/dynamicui/dynamicui_codeguard_backups.conf >/dev/null 2>&1
echo "....."
#fi
}
function unregister_hooks(){
echo " Unregistering cPanel Hooks"
HOOKOUTPUT=$(php /var/cpanel/codeguard/lib/hooks/hook-installer.php uninstall 2>&1)
}
function remove_update_cron(){
crontab -l | grep -v '/usr/bin/php /var/cpanel/codeguard/scripts/update.php' | crontab -
}
echo "###################################################################"
echo "# #"
echo "# CodeGuard Website Backup Plugin for cPanel(R)/WHM(R) #"
echo "# #"
echo "###################################################################"
check_for_root
echo ""
echo "${STATUS} ${APP} BACKUP"
unregister_appconfig
#cPanel Hooks
unregister_hooks
#remove_icons
echo "${STATUS} ${APP} PLUGIN FILES"
remove_app_files
remove_cpanel_files
remove_paperlantern_files
remove_whm_files
remove_update_cron
echo ""
echo "############################################################"
echo "################### UNINSTALL COMPLETE #####################"
echo "############################################################"
echo ""
exit 0