new_system_set/newset.sh
2024-03-26 20:32:21 +08:00

115 lines
3.2 KiB
Bash

#!/bin/bash
#新系统脚本
#by author of wzj
#2021年8月20日
#####################
#安装基本工具
BASE_INSTALL()
{
echo -e "\033[32m------------------------------------------ 安装基本工具 --------------------------------------------\033[0m"
sleep 1.5
for i in wget
do
yum install -y ${i}
done
}
REPO_REPLACE()
{
echo -e "\033[32m------------------------------------------ 备份旧yum源并导入阿里源 --------------------------------------------\033[0m"
sleep 1.5
DATE=`date +"%Y-%m-%d"`
if [ ! -d /etc/yum.repos.d/bak/${DATE} ];then
mkdir -p /etc/yum.repos.d/bak/${DATE}
fi
for i in `ls /etc/yum.repos.d|grep -v bak`
do
\mv /etc/yum.repos.d/${i} /etc/yum.repos.d/bak/${DATE}
done
#wget http://mirrors.aliyun.com/repo/Centos-7.repo -O /etc/yum.repos.d/CentOS-Base.repo
#wget http://mirrors.aliyun.com/repo/Centos-7.repo -P /etc/yum.repos.d/
#wget http://mirrors.aliyun.com/repo/epel-7.repo -P /etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
yum install -y epel-release
}
TOOL_INSTALL()
{
echo -e "\033[32m-------------------------------------------- 安装常用工具 --------------------------------------------\033[0m"
sleep 1.5
for TOOL in net-tools lrzsz vim unzip git screen nethogs speedtest-cli lm_sensors bzip2 jq expect bind-utils telnet
do
echo -e "\033[33m安装${TOOL}...\033[0m"
sleep 1
#rpm -qa|grep ${TOOL} >>/dev/null 2>&1
#if [ $? -ne 0 ];then
yum -y install ${TOOL}
#fi
done
yum groupinstall "Development Tools" -y
}
FIREWALLD()
{
#echo -e "\033[32m关闭防火墙FIREWALLD\033[0m"
#sleep 1.5
#systemctl disable firewalld
#systemctl stop firewalld
echo -e "\033[32m-------------------------------------------- 下载firewalld简便工具 --------------------------------------------\033[0m"
wget -O /usr/bin/fwd https://mirror.liuyan.wang/shell/fwd.sh && chmod +x /usr/bin/fwd
}
IPTABLES()
{
echo -e "\033[32m-------------------------------------------- 关闭防火墙IPTABLES --------------------------------------------\033[0m"
sleep 1.5
setenforce 0
if [ ! -f /etc/selinux/config.bak ];then
cp -r /etc/selinux/config /etc/selinux/config.bak
fi
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
}
PS1(){
cat>>/etc/profile<<EOF
##########以下是用户登录及操作记录代码##############
PS1='\e[1;37m[\e[m\e[1;32m\u\e[m\e[1;33m@\e[m\e[1;35m\H\e[m \e[4m\`pwd\`\e[m\e[1;37m]\e[m\e[1;36m\e[m\n$'
USER_IP=\`who -u am i 2>/dev/null| awk '{print \$NF}'|sed -e 's/[()]//g'\`
if [ "\$USER_IP" = "" ]
then
USER_IP=\`hostname\`
fi
if [ ! -d /var/log/history ]
then
mkdir -p /var/log/history
chmod 777 /var/log/history
fi
if [ ! -d /var/log/history/\${LOGNAME} ]
then
mkdir -p /var/log/history/\${LOGNAME}
chmod 300 /var/log/history/\${LOGNAME}
fi
export HISTSIZE=4096
DT=\`date "+%Y-%m-%d_%H:%M:%S"\`
export HISTFILE="/var/log/history/\${LOGNAME}/\${USER_IP}-log.\${DT}"
chmod 600 /var/log/history/\${LOGNAME}/*log* 2>/dev/null
######################代码结束#######################
EOF
}
TimeZone(){
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
}
BASE_INSTALL
REPO_REPLACE
TOOL_INSTALL
FIREWALLD
IPTABLES
PS1
TimeZone
source /etc/profile