denyhosts/build.sh

180 lines
6.0 KiB
Bash

:
check_os()
{
if cat /etc/issue | grep -i 'ubuntu' >> /dev/null 2>&1 ; then
OS=ubuntu
OS_VER=$(cat /etc/issue | head -n1 | awk '{print$2}')
echo -e SYSTEM: UBUNTU $(uname -m) ${OS_VER}\\nKERNEL: $(uname -sr)
elif test -f /etc/debian_version ; then
OS=debian
OS_VER=$(cat /etc/debian_version)
echo -e SYSTEM: DEBIAN $(uname -m) ${OS_VER}\\nKERNEL: $(uname -sr)
elif test -f /etc/centos-release ; then
OS=centos
OS_VER=$(cat /etc/centos-release | grep -o -E '[0-9.]{3,}') 2>> /dev/null
echo -e SYSTEM: CENTOS $(uname -m) ${OS_VER}\\nKERNEL: $(uname -sr)
else
echo The system does not support
exit 3
fi
}
pkg_install()
{
if test "$OS" = "ubuntu" -o "$OS" = "debian"; then
apt -y install build-essential
apt -y install make
apt -y install tmux
apt -y install libclamav-dev libip4tc-dev libcurl4-openssl-dev #(或者libcurl4-gnutls-dev)
apt -y install libsystemd-dev libjson-c-dev libpcre2-dev clamav-freshclam
apt -y install libltdl-dev
# Debian系统使用libiptc库需要nftables切换到iptables
# Switching to the legacy version:(切换到 iptables)
update-alternatives --set iptables /usr/sbin/iptables-legacy
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
update-alternatives --set arptables /usr/sbin/arptables-legacy
update-alternatives --set ebtables /usr/sbin/ebtables-legacy
freshclam # 更新病毒库(必要)
else
yum -y groupinstall "Development Tools"
yum -y install make
yum -y install tmux
yum -y install bzip2-devel
yum -y install libxslt-devel libxml2-devel
yum -y install clamav clamav-update clamav-lib clamav-devel json-c-devel pcre2-devel
yum -y install iptables-devel libcurl-devel
yum -y install systemd-devel libtool-ltdl-devel
yum -y install centos-release-scl
yum -y install devtoolset-11-gcc
#source /opt/rh/devtoolset-11/enable #临时
if test "`grep "devtoolset" /etc/profile`" = ""; then
echo "source /opt/rh/devtoolset-11/enable" >> /etc/profile #永久
fi
source /opt/rh/devtoolset-11/enable
freshclam # 更新病毒库(必要)
fi
}
main()
{
#cd clamscan/libclamav
#bash build.sh
#cd ../..
make clean; make
if test "$OS" = "centos"; then
if test -f /etc/cron.d/clamav-update; then # 去除自动更新病毒库
mv /etc/cron.d/clamav-update /root
fi
if test -f /etc/freshclam.conf; then # 更改病毒库镜像
sed -i "s/DatabaseMirror .*/DatabaseMirror clamavdb.c3sl.ufpr.br/g" /etc/freshclam.conf
fi
fi
if test -f /etc/clamav/freshclam.conf; then
sed -i "s/DatabaseMirror .*/DatabaseMirror clamavdb.c3sl.ufpr.br/g" /etc/clamav/freshclam.conf
else
:
fi
if test "$OS" = "debian"; then
condition=$(awk -v num1=${OS_VER} -v num2=11 'BEGIN{print(num1>num2)?"0":"1"}')
if test "$condition" = "1"; then # Debian系统版本小于11时, libclamav库版本低时
cd clamscan/libclamav/; bash build.sh
cp /usr/lib/x86_64-linux-gnu/libclamav.so.9.0.5 /usr/lib/x86_64-linux-gnu/libclamav.so.9.0.5.backup
cp .libs/libclamav.so.9.0.5 /usr/lib/x86_64-linux-gnu/
cd ../../
fi
fi
tmux new-session -s main -d; tmux send -t main 'killall rhost; ./rhost -d' ENTER
tmux at -t main
}
binary()
{
cd ~
if ! test -f RHOST; then
mkdir -p RHOST
fi
if test "$OS" = "centos"; then
wget -T 30 https://git.aixiao.me/attachments/18147490-6d10-4407-8537-03b3c1eeb357 -O RHOST/rhost
wget -T 30 https://git.aixiao.me/attachments/e6309b7b-0e98-4a11-8fc1-7c624649f3b8 -O RHOST/rhost.conf
wget -T 30 https://git.aixiao.me/attachments/1ddf1579-b660-4d91-821d-82fe5f0ec8c0 -O RHOST/freshclam.conf
if test -f /etc/cron.d/clamav-update; then # 去除自动更新病毒库
mv /etc/cron.d/clamav-update /root
fi
if test -f /etc/freshclam.conf; then # 更改病毒库镜像
sed -i "s/DatabaseMirror .*/DatabaseMirror clamavdb.c3sl.ufpr.br/g" /etc/freshclam.conf
fi
if test -f /etc/clamav/freshclam.conf; then
sed -i "s/DatabaseMirror .*/DatabaseMirror clamavdb.c3sl.ufpr.br/g" /etc/clamav/freshclam.conf
else
:
fi
chmod +x RHOST/rhost
cd ~/RHOST/
tmux new-session -s main -d; tmux send -t main 'killall rhost; ./rhost -d' ENTER
tmux at -t main
elif test "$OS" = "debian"; then
wget -T 30 https://git.aixiao.me/attachments/40a3317f-48eb-4465-9ae3-fc46251c5bcc -O RHOST/rhost
wget -T 30 https://git.aixiao.me/attachments/e6309b7b-0e98-4a11-8fc1-7c624649f3b8 -O RHOST/rhost.conf
wget -T 30 https://git.aixiao.me/attachments/1ddf1579-b660-4d91-821d-82fe5f0ec8c0 -O RHOST/freshclam.conf
chmod +x RHOST/rhost
condition=$(awk -v num1=${OS_VER} -v num2=11 'BEGIN{print(num1>num2)?"0":"1"}')
if test "$condition" = "1"; then # Debian系统版本小于11时, libclamav库版本低时
cd clamscan/libclamav/; bash build.sh
cp /usr/lib/x86_64-linux-gnu/libclamav.so.9.0.5 /usr/lib/x86_64-linux-gnu/libclamav.so.9.0.5.backup
cp .libs/libclamav.so.9.0.5 /usr/lib/x86_64-linux-gnu/
cd ../../
fi
cd ~/RHOST/
tmux new-session -s main -d; tmux send -t main 'killall rhost; ./rhost -d' ENTER
tmux at -t main
fi
}
check_os
pkg_install
if test "${1}" = "binary"; then
binary
exit 0
fi
main