#!/bin/bash




##检测网络情况
ping -c 2 www.sdo.com > /dev/null 2>&1
if [ $? -eq 0 ];then
  echo ""
else
  echo -e "\033[1;31m网络无法连接, 请检查网络\033[0m"
  exit 1
fi




# check the OS version
if [  "$(lsb_release -is)" != "Ubuntu" -a "$(lsb_release -cs)" != "jammy" ];then
  echo -e "\033[1;31m当前系统版本不支持, 请使用 Ubuntu jammy 版本\033[0m"
  exit 2
fi




##SSH远程登录其他主机不进行确认
sed -i 's/#   StrictHostKeyChecking ask/StrictHostKeyChecking no/g' /etc/ssh/ssh_config




##安装相关软件
if [ ! -d /etc/apt/bak ]; then
    mkdir /etc/apt/bak
    cp /etc/apt/sources.list /etc/apt/bak
    sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
    rm -rf /var/lib/apt/lists/* && apt clean
    apt update
    apt install -y vim wget bash-completion lrzsz net-tools zip unzip nmap
fi




##关闭防火墙
stop_firewall () {
systemctl stop ufw.service
systemctl disable ufw.service
}
stop_firewall




##配置时间同步
config_chrony () {
apt install chrony -y

cat > /etc/chrony/chrony.conf << EOF
confdir /etc/chrony/conf.d
pool ntp.aliyun.com iburst
pool ntp.tencent.com iburst
keyfile /etc/chrony/chrony.keys
driftfile /var/lib/chrony/chrony.drift
ntsdumpdir /var/lib/chrony
logdir /var/log/chrony
maxupdateskew 1.0
rtcsync
makestep 1 -1
leapsectz Asia/Shanghai
bindcmdaddress 127.0.0.1
EOF

systemctl restart chrony.service
systemctl enable chrony.service
}
config_chrony




##配置时区
timedatectl set-timezone Asia/Shanghai




##关闭ubunut自动更新
sed -i 's/"1"/"0"/g' /etc/apt/apt.conf.d/10periodic
sed -i 's/"1"/"0"/g' /etc/apt/apt.conf.d/20auto-upgrades




##对删除命令进行优化
if [ "$(grep -o rm= /etc/profile)" != "rm=" ]; then
  echo 'alias rm="rm -i"' >> /etc/profile
  source /etc/profile
fi




##重启
reboot