📄 Viewing: install.sh
#!/bin/bash
#
##
# Linux Malware Detect v0.6
# (C) 2002-2011, R-fx Networks <proj@r-fx.org>
# (C) 2011, Ryan MacDonald <ryan@r-fx.org>
# inotifywait (C) 2007, Rohan McGovern <rohan@mcgovern.id.au>
# Mojo Fork (C) 2013, Joseph Laws <jlaws@mojohost.com>
# This program may be freely redistributed under the terms of the GNU GPL v2
##
#
inspath=/usr/local/mojo/security/maldet
email_addr="jlaws@mojohost.com"
logf=$inspath/event_log
cnftemp=.ca.def
maldetReinstall ()
{
echo "Removing $inspath and /etc/cron.daily/maldet for fresh install..."
rm -fr "$inspath"
chattr -i /etc/cron.daily/maldet
rm -f /etc/cron.daily/maldet
scanPath
}
maldetInitial ()
{
echo "Initial system install of maldet starting..."
if [[ ! -f /etc/mojo.conf ]]; then
echo "/etc/mojo.conf does not exist."
touch /etc/mojo.conf
chmod 644 /etc/mojo.conf
fi
oldPath
scanPath
}
mojoCheck ()
{
if [[ -f "/etc/mojo.conf" ]]; then
oldPath
scanPath
else
touch /etc/mojo.conf
oldPath
scanPath
fi
}
choosePath ()
{
echo;echo "What SCANPATH should we use for daily scans? [ENTER FOR /home/httpd/html]"
read -e SCANPATH
if [[ "${SCANPATH}" == "" ]] && [[ -d "/home/httpd/html" ]]; then
SCANPATH="/home/httpd/html"
writeScanpath
maldet_Install
elif [[ "${SCANPATH}" == "" ]] && [[ ! -d "{SCANPATH}" ]]; then
echo "${SCANPATH} does not exist. Try again."
choosePath
elif [[ "${SCANPATH}" != "" ]] && [[ -d "${SCANPATH}" ]]; then
echo "Using user-submitted SCANPATH of ${SCANPATH}"
SCANPATH="${SCANPATH}"
writeScanpath
maldet_Install
else
echo "${SCANPATH} does not exist. Please try again."
choosePath
fi
}
oldPath ()
{
if [[ -d /usr/local/maldetect ]]; then
echo "Old /usr/local/maldetect location found. Removing..."
rm -fr /usr/local/maldetect*
echo "Old /usr/local/maldetect location removed."
fi
}
scanPath ()
{
##Check cPanel and DA first
if [[ $(awk -F: '{print $1}' /etc/passwd | grep -sw cpanel) != "" ]] && [[ $(ps auxf | grep -v grep | grep -sw cpservd) != "" ]]; then
echo "cPanel found, using /home for SCANPATH"
SCANPATH=/home
writeScanpath
maldet_Install
fi
if [[ $(awk -F: '{print $1}' /etc/passwd | grep -sw diradmin) != "" ]] && [[ $(ps auxf | grep -v grep | grep -sw directadmin) != "" ]]; then
echo;echo "DirectAdmin found, using /home for SCANPATH"
SCANPATH=/home
writeScanpath
maldet_Install
fi
SCANPATHCRON=$(grep -sw SITEPATH /etc/cron.daily/maldet | awk -F'=' '{print $2}')
SCANPATHMOJO=$(grep -sw SCANPATH /etc/mojo.conf | awk -F'=' '{print $2}')
if [[ "${SCANPATHCRON}" == "" ]] && [[ "${SCANPATHMOJO}" == "" ]]; then
echo "Both cron and mojo.conf have NO SCANPATH value."
if [[ "${INITIAL}" == "YES" ]]; then
SCANPATH=/home/httpd/html
writeScanpath
maldet_Install
else
echo;choosePath
fi
elif [[ "${SCANPATHMOJO}" == "" ]]; then
echo "Maldet cron has SCANPATH value of: ${SCANPATHCRON}. Adding to /etc/mojo.conf..."
SCANPATH="${SCANPATHCRON}"
writeScanpath
maldet_Install
elif [[ "${SCANPATHCRON}" == "" ]]; then
echo "mojo.conf has SCANPATH value of: ${SCANPATHMOJO}"
SCANPATH="${SCANPATHMOJO}"
maldet_Install
elif [[ "${SCANPATHCRON}" == "${SCANPATHMOJO}" ]]; then
SCANPATH="${SCANPATHCRON}"
echo "Maldet cron and mojo.conf agree on SCANPATH of ${SCANPATH}"
maldet_Install
else
echo "Maldet cron ($SCANPATHCRON) and mojo.conf ($SCANPATHMOJO) SCANPATH values are different, sticking with ${SCANPATHMOJO}. Manually edit /etc/mojo.conf to override."
SCANPATH="${SCANPATHMOJO}"
maldet_Install
fi
}
writeScanpath ()
{
echo "SCANPATH=${SCANPATH}" >> /etc/mojo.conf
}
maldet_Install ()
{
if [ ! -d "$inspath" ] && [ -d "files" ]; then
mkdir -p $inspath
chmod 755 $inspath
cp -pR files/* $inspath
chmod 755 $inspath/maldet
ln -fs $inspath/maldet /usr/local/sbin/maldet
ln -fs $inspath/maldet /usr/local/sbin/lmd
cp $inspath/inotify/libinotifytools.so.0 /usr/lib/
cp -f CHANGELOG COPYING.GPL README $inspath/
else
$inspath/maldet -k >> /dev/null 2>&1
mv $inspath $inspath.bk$$
rm -f $inspath.last
ln -fs $inspath.bk$$ $inspath.last
mkdir -p $inspath
chmod 755 $inspath
cp -pR files/* $inspath
chmod 755 $inspath/maldet
ln -fs $inspath/maldet /usr/local/sbin/maldet
ln -fs $inspath/maldet /usr/local/sbin/lmd
cp $inspath/inotify/libinotifytools.so.0 /usr/lib/
cp -f $inspath.bk$$/ignore_* $inspath/ >> /dev/null 2>&1
cp -f $inspath.bk$$/sess/* $inspath/sess/ >> /dev/null 2>&1
cp -f $inspath.bk$$/tmp/* $inspath/tmp/ >> /dev/null 2>&1
cp -f $inspath.bk$$/quarantine/* $inspath/quarantine/ >> /dev/null 2>&1
cp -f CHANGELOG COPYING.GPL README $inspath/
fi
if [ -d "/etc/cron.daily" ]; then
if [[ -f "/etc/cron.daily/maldet" ]]; then
if [[ $(lsattr /etc/cron.daily/maldet | grep -v '\-------------') != "" ]]; then
chattr -i /etc/cron.daily/maldet
fi
if [[ -f "/etc/cron.daily/maldet_outofdate" ]]; then
rm -f /etc/cron.daily/maldet_outofdate
fi
rm -f /etc/cron.daily/maldet
fi
cp -f cron.daily /etc/cron.daily/maldet
chmod 755 /etc/cron.daily/maldet
chattr +i /etc/cron.daily/maldet
fi
if [ -d "/etc/cron.d" ]; then
cp -f cron.d.pub /etc/cron.d/maldet_pub
chmod 644 /etc/cron.d/maldet_pub
fi
touch $logf
echo "Linux Malware Detect v0.6"
echo " (C) 2002-2011, R-fx Networks <proj@r-fx.org>"
echo " (C) 2011, Ryan MacDonald <ryan@r-fx.org>"
echo "inotifywait (C) 2007, Rohan McGovern <rohan@mcgovern.id.au>"
echo "Mojo Fork (C) 2013, Joseph Laws <jlaws@mojohost.com>"
echo "This program may be freely redistributed under the terms of the GNU GPL"
echo ""
echo "Installation completed to $inspath"
echo "Config File: $inspath/conf.maldet"
echo " Exec File: $inspath/maldet"
echo " Exec Link: /usr/local/sbin/maldet"
echo " Exec Link: /usr/local/sbin/lmd"
echo " Daily Cron: /etc/cron.daily/maldet"
echo " Scan Path: ${SCANPATH}"
echo ""
}
if [[ "$1" == "--reinstall" ]]; then
maldetReinstall
elif [[ "$1" == "--initial" ]]; then
INITIAL=YES
maldetInitial
else
mojoCheck
fi
🌑 DarkStealth — WP Plugin Edition
Directory: /usr/src/maldet-latest