• s28.CentOS、Ubuntu、Rocky Linux系统初始化脚本v6版本


    CentOS、Ubuntu、Rocky系统初始化脚本

    Shell脚本源码地址:

    Gitee:https://gitee.com/raymond9/shell

    Github:https://github.com/raymond999999/shell

    可以去上面的Gitee或Github仓库代码拉取脚本。

    版本功能
    v6版更新内容1.由于CentOS 6和8官方已经停止支持,也就移除了其相关内容;
    2…分别有reset_v6_1版本(镜像仓库采用sed直接替换网址方式;修改ip地址采用nmcli命令方式)和reset_v6_2版本(镜像仓库和修改ip地址采用配置文件方式);
    3.reset_v6_1添加了CentOS Stream 9用Perl语言更改镜像源的方法,优化了某些镜像仓库失效的bug,修改了某些bug。
    v5版更新内容1.优化了某些镜像仓库失效的bug;
    2.CentOS stream 9和Rocky 9修改ip的方式更改,做了相应的修改;
    3.分别有reset_v5_1版本(镜像仓库采用sed直接替换网址方式;修改ip地址采用nmcli命令方式)和reset_v5_2版本(镜像仓库和修改ip地址采用配置文件方式);
    4.把设置PS1、设置默认文本编辑器为vim和设置history格式单独分开;
    5.修改了某些bug。
    v4版更新内容1.添加对CentOS stream 9、Rocky 9和Ubuntu 22.04系统的支持;
    2.添加Ubuntu 22.04修改IP地址和网关地址、双网卡更改IP地址;
    3.添加禁用ctrl+alt+del重启功能;
    4.修改了某些bug。
    v3版更新内容1.添加双网卡更改IP地址;
    2.添加设置系统时区。
    v2版更新内容1.添加对CentOS stream 8系统支持,添加了CentOS stream 8镜像仓库;
    2.由于CentOS 8已被废弃,修改成centos-vault的历史镜像仓库;
    3.优化Ubuntu 20.04禁用swap不生效的问题。
    v1版支持功能1.支持CentOS 6/7/8、Ubuntu 18.04/20.04、Rocky 8系统;
    2.支持功能禁用SELinux、关闭防火墙、优化SSH、设置系统别名、设置vimrc配置文件、设置软件包仓库、Minimal安装建议安装软件、安装邮件服务并配置邮件、更改SSH端口号、修改网卡名、修改IP地址和网关地址、设置主机名、设置PS1和系统环境变量、禁用SWAP、优化内核参数、优化资源限制参数、Ubuntu设置root用户登录、Ubuntu卸载无用软件包。

    下面是reset_v6_1脚本内容:

    [root@rocky9 ~]# cat reset_v6_1.sh
    #!/bin/bash
    #
    #***************************************************************************************************
    #Author:        Raymond
    #QQ:            88563128
    #Date:          2023-11-15
    #FileName:      reset_v6_1.sh
    #URL:           raymond.blog.csdn.net
    #Description:   reset for CentOS 7 & CentOS Stream 8/9 & Ubuntu 18.04/20.04/22.04 & Rocky 8/9
    #Copyright (C): 2023 All rights reserved
    #***************************************************************************************************
    COLOR="echo -e \\033[01;31m"
    END='\033[0m'
    
    os(){
        OS_ID=`sed -rn '/^NAME=/s@.*="([[:alpha:]]+).*"$@\1@p' /etc/os-release`
        OS_NAME=`sed -rn '/^NAME=/s@.*="([[:alpha:]]+) (.*)"$@\2@p' /etc/os-release`
        OS_RELEASE=`sed -rn '/^VERSION_ID=/s@.*="?([0-9.]+)"?@\1@p' /etc/os-release`
        OS_RELEASE_VERSION=`sed -rn '/^VERSION_ID=/s@.*="?([0-9]+)\.?.*"?@\1@p' /etc/os-release`
    }
    
    disable_selinux(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            if [ `getenforce` == "Enforcing" ];then
                sed -ri.bak 's/^(SELINUX=).*/\1disabled/' /etc/selinux/config
                ${COLOR}"${OS_ID} ${OS_RELEASE} SELinux已禁用,请重新启动系统后才能生效!"${END}
            else
                ${COLOR}"${OS_ID} ${OS_RELEASE} SELinux已被禁用,不用设置!"${END}
            fi
        else
            ${COLOR}"${OS_ID} ${OS_RELEASE} SELinux默认没有安装,不用设置!"${END}
        fi
    }
    
    disable_firewall(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            rpm -q firewalld &> /dev/null && { systemctl disable --now firewalld &> /dev/null; ${COLOR}"${OS_ID} ${OS_RELEASE} Firewall防火墙已关闭!"${END}; } || ${COLOR}"${OS_ID} ${OS_RELEASE} iptables防火墙已关闭!"${END}
        else
            dpkg -s ufw &> /dev/null && { systemctl disable --now ufw &> /dev/null; ${COLOR}"${OS_ID} ${OS_RELEASE} ufw防火墙已关闭!"${END}; } || ${COLOR}"${OS_ID} ${OS_RELEASE}  没有ufw防火墙服务,不用关闭!"${END}
        fi
    }
    
    optimization_sshd(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            sed -ri.bak -e 's/^#(UseDNS).*/\1 no/' -e 's/^(GSSAPIAuthentication).*/\1 no/' /etc/ssh/sshd_config
        else
            sed -ri.bak -e 's/^#(UseDNS).*/\1 no/' -e 's/^#(GSSAPIAuthentication).*/\1 no/' /etc/ssh/sshd_config
        fi
        systemctl restart sshd
        ${COLOR}"${OS_ID} ${OS_RELEASE} SSH已优化完成!"${END}
    }
    
    set_centos_alias(){
        if [ ${OS_RELEASE_VERSION} == "7" -o ${OS_RELEASE_VERSION} == "8" ];then
            cat >>~/.bashrc <<-EOF
    alias cdnet="cd /etc/sysconfig/network-scripts"
    alias vie0="vim /etc/sysconfig/network-scripts/ifcfg-eth0"
    alias vie1="vim /etc/sysconfig/network-scripts/ifcfg-eth1"
    alias scandisk="echo '- - -' > /sys/class/scsi_host/host0/scan;echo '- - -' > /sys/class/scsi_host/host1/scan;echo '- - -' > /sys/class/scsi_host/host2/scan"
    EOF
        else
            cat >>~/.bashrc <<-EOF
    alias cdnet="cd /etc/NetworkManager/system-connections"
    alias vie0="vim /etc/NetworkManager/system-connections/eth0.nmconnection"
    alias vie1="vim /etc/NetworkManager/system-connections/eth1.nmconnection"
    alias scandisk="echo '- - -' > /sys/class/scsi_host/host0/scan;echo '- - -' > /sys/class/scsi_host/host1/scan;echo '- - -' > /sys/class/scsi_host/host2/scan"
    EOF
        fi
        ${COLOR}"${OS_ID} ${OS_RELEASE} 系统别名已设置成功,请重新登陆后生效!"${END}
    }
    
    set_ubuntu_alias(){
        cat >>~/.bashrc <<-EOF
    alias cdnet="cd /etc/netplan"
    alias scandisk="echo '- - -' > /sys/class/scsi_host/host0/scan;echo '- - -' > /sys/class/scsi_host/host1/scan;echo '- - -' > /sys/class/scsi_host/host2/scan"
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} 系统别名已设置成功,请重新登陆后生效!"${END}
    }
    
    set_alias(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            if grep -Eqi "(.*cdnet|.*vie0|.*vie1|.*scandisk)" ~/.bashrc;then
                sed -i -e '/.*cdnet/d'  -e '/.*vie0/d' -e '/.*vie1/d' -e '/.*scandisk/d' ~/.bashrc
                set_centos_alias
            else
                set_centos_alias
            fi
        fi
        if [ ${OS_ID} == "Ubuntu" ];then
            if grep -Eqi "(.*cdnet|.*scandisk)" ~/.bashrc;then
                sed -i -e '/.*cdnet/d' -e '/.*scandisk/d' ~/.bashrc
                set_ubuntu_alias
            else
                set_ubuntu_alias
            fi
        fi
    }
    
    set_vimrc(){
        read -p "请输入作者名: " AUTHOR
        read -p "请输入QQ号: " QQ
        read -p "请输入网址: " V_URL
        cat >~/.vimrc <<-EOF
    set ts=4
    set expandtab
    set ignorecase
    set cursorline
    set autoindent
    autocmd BufNewFile *.sh exec ":call SetTitle()"
    func SetTitle()
        if expand("%:e") == 'sh'
        call setline(1,"#!/bin/bash")
        call setline(2,"#")
        call setline(3,"#**********************************************************************************************")
        call setline(4,"#Author:        ${AUTHOR}")
        call setline(5,"#QQ:            ${QQ}")
        call setline(6,"#Date:          ".strftime("%Y-%m-%d"))
        call setline(7,"#FileName:      ".expand("%"))
        call setline(8,"#URL:           ${V_URL}")
        call setline(9,"#Description:   The test script")
        call setline(10,"#Copyright (C): ".strftime("%Y")." All rights reserved")
        call setline(11,"#*********************************************************************************************")
        call setline(12,"")
        endif
    endfunc
    autocmd BufNewFile * normal G
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} vimrc设置完成,请重新系统启动才能生效!"${END}
    }
    
    aliyun(){
        URL=mirrors.aliyun.com
    }
    
    huawei(){
        URL=repo.huaweicloud.com
    }
    
    tencent(){
        URL=mirrors.tencent.com
    }
    
    tuna(){
        URL=mirrors.tuna.tsinghua.edu.cn
    }
    
    netease(){
        URL=mirrors.163.com
    }
    
    sohu(){
        URL=mirrors.sohu.com
    }
    
    nju(){
        URL=mirrors.nju.edu.cn
    }
    
    ustc(){
        URL=mirrors.ustc.edu.cn
    }
    
    sjtu(){
        URL=mirrors.sjtug.sjtu.edu.cn
    }
    
    set_yum_rocky8_9(){
        sed -i.bak -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://'${URL}'/rocky|g' /etc/yum.repos.d/[Rr]ocky*.repo
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} YUM源设置完成!"${END}
    }
    
    set_yum_rocky8_9_2(){
        sed -i.bak -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://'${URL}'/rockylinux|g' /etc/yum.repos.d/[Rr]ocky*.repo
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} YUM源设置完成!"${END}
    }
    
    set_yum_centos_stream9(){
        PERL_FILE=update_mirror.pl
        if [ ! -e ${PERL_FILE} ];then
            ${COLOR}"缺少${PERL_FILE}文件"${END}
            exit
        else
            ${COLOR}"${PERL_FILE}文件已准备好,继续后续配置!"${END}       
        fi
        rpm -q perl &> /dev/null || { ${COLOR}"安装perl工具,请稍等..."${END};yum -y install perl &> /dev/null; }
        perl ./update_mirror.pl /etc/yum.repos.d/centos*.repo
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} YUM源设置完成!"${END}
    }
    
    set_yum_centos_stream8(){
        sed -i.bak -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://'${URL}'/centos|g' /etc/yum.repos.d/CentOS-*.repo
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} YUM源设置完成!"${END}
    }
    
    set_epel_rocky_centos8_9(){
        rpm -q epel-release &> /dev/null || { ${COLOR}"安装epel-release工具,请稍等..."${END};yum -y install epel-release &> /dev/null; }
        sed -i.bak -e 's|^metalink=|#metalink=|g' -e 's|^#baseurl=https://download.example/pub/epel|baseurl=https://'${URL}'/epel|g' /etc/yum.repos.d/epel*.repo
        if [ ${OS_RELEASE_VERSION} == "9" ];then
            sed -i -e 's|^enabled=1|enabled=0|g' /etc/yum.repos.d/epel-cisco*.repo
        fi
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} EPEL源设置完成!"${END}
    }
    
    set_epel_2_rocky_centos8_9(){
        rpm -q epel-release &> /dev/null || { ${COLOR}"安装epel-release工具,请稍等..."${END};yum -y install epel-release &> /dev/null; }
        sed -i.bak -e 's|^metalink=|#metalink=|g' -e 's|^#baseurl=https://download.example/pub/epel|baseurl=https://'${URL}'/fedora-epel|g' /etc/yum.repos.d/epel*.repo
        if [ ${OS_RELEASE_VERSION} == "9" ];then
            sed -i -e 's|^enabled=1|enabled=0|g' /etc/yum.repos.d/epel-cisco*.repo
        fi
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} EPEL源设置完成!"${END}
    }
    
    set_epel_3_rocky_centos8_9(){
        rpm -q epel-release &> /dev/null || { ${COLOR}"安装epel-release工具,请稍等..."${END};yum -y install epel-release &> /dev/null; }
        sed -i.bak -e 's|^metalink=|#metalink=|g' -e 's|^#baseurl=https://download.example/pub/epel|baseurl=https://'${URL}'/fedora/epel|g' /etc/yum.repos.d/epel*.repo
        if [ ${OS_RELEASE_VERSION} == "9" ];then
            sed -i -e 's|^enabled=1|enabled=0|g' /etc/yum.repos.d/epel-cisco*.repo
        fi
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} EPEL源设置完成!"${END}
    }
    
    set_yum_centos7(){
        sed -i.bak -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://'${URL}'|g' /etc/yum.repos.d/CentOS-*.repo
        ${COLOR}"更新镜像源中,请稍等..."${END}
        yum clean all &> /dev/null
        yum makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} YUM源设置完成!"${END}
    }
    
    set_epel_centos7(){
        rpm -q epel-release &> /dev/null || { ${COLOR}"安装epel-release工具,请稍等..."${END};yum -y install epel-release &> /dev/null; }
        sed -i.bak -e 's!^metalink=!#metalink=!g' -e 's!^#baseurl=!baseurl=!g' -e 's!https\?://download\.fedoraproject\.org/pub/epel!https://'${URL}'/epel!g' -e 's!https\?://download\.example/pub/epel!https://'${URL}'/epel!g' /etc/yum.repos.d/epel*.repo
        ${COLOR}"更新镜像源中,请稍等..."${END}
        yum clean all &> /dev/null
        yum makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} EPEL源设置完成!"${END}
    }
    
    set_epel_2_centos7(){
        rpm -q epel-release &> /dev/null || { ${COLOR}"安装epel-release工具,请稍等..."${END};yum -y install epel-release &> /dev/null; }
        sed -i.bak -e 's!^metalink=!#metalink=!g' -e 's!^#baseurl=!baseurl=!g' -e 's!https\?://download\.fedoraproject\.org/pub/epel!https://'${URL}'/fedora-epel!g' -e 's!https\?://download\.example/pub/epel!https://'${URL}'/fedora-epel!g' /etc/yum.repos.d/epel*.repo
        ${COLOR}"更新镜像源中,请稍等..."${END}
        yum clean all &> /dev/null
        yum makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} EPEL源设置完成!"${END}
    }
    
    set_epel_3_centos7(){
        rpm -q epel-release &> /dev/null || { ${COLOR}"安装epel-release工具,请稍等..."${END};yum -y install epel-release &> /dev/null; }
        sed -i.bak -e 's!^metalink=!#metalink=!g' -e 's!^#baseurl=!baseurl=!g' -e 's!https\?://download\.fedoraproject\.org/pub/epel!https://'${URL}'/fedora/epel!g' -e 's!https\?://download\.example/pub/epel!https://'${URL}'/fedora/epel!g' /etc/yum.repos.d/epel*.repo
        ${COLOR}"更新镜像源中,请稍等..."${END}
        yum clean all &> /dev/null
        yum makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} EPEL源设置完成!"${END}
    }
    
    rocky8_9_base_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)阿里镜像源
    2)网易镜像源
    3)搜狐镜像源
    4)南京大学镜像源
    5)中科大镜像源
    6)上海交通大学镜像源
    7)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-7): " NUM
            case ${NUM} in
            1)
                aliyun
                set_yum_rocky8_9_2
                ;;
            2)
                netease
                set_yum_rocky8_9
                ;;
            3)
                sohu
                set_yum_rocky8_9
                ;;
            4)
                nju
                set_yum_rocky8_9
                ;;
            5)
                ustc
                set_yum_rocky8_9
                ;;
            6)
                sjtu
                set_yum_rocky8_9
                ;;
            7)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-7)!"${END}
                ;;
            esac
        done
    }
    
    centos_stream9_base_menu(){
        ${COLOR}"由于CentOS Stream 9镜像源是Perl语言实现的,在更改镜像源之前先确保把'update_mirror.pl'文件和reset脚本放在同一个目录下,否则后面程序会退出,默认的CentOS Stream 9镜像源设置的是阿里云,要修改镜像源,请去'update_mirror.pl'文件里修改url变量!"${END}
        sleep 10
        set_yum_centos_stream9
    }
    
    centos_stream8_base_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)阿里镜像源
    2)华为镜像源
    3)腾讯镜像源
    4)清华镜像源
    5)网易镜像源
    6)南京大学镜像源
    7)中科大镜像源
    8)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-8): " NUM
            case ${NUM} in
            1)
                aliyun
                set_yum_centos_stream8
                ;;
            2)
                huawei
                set_yum_centos_stream8
                ;;
            3)
                tencent
                set_yum_centos_stream8
                ;;
            4)
                tuna
                set_yum_centos_stream8
                ;;
            5)
                netease
                set_yum_centos_stream8
                ;;
            6)
                nju
                set_yum_centos_stream8
                ;;
            7)
                ustc
                set_yum_centos_stream8
                ;;
            8)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-8)!"${END}
                ;;
            esac
        done
    }
    
    centos7_base_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)阿里镜像源
    2)华为镜像源
    3)腾讯镜像源
    4)清华镜像源
    5)网易镜像源
    6)南京大学镜像源
    7)中科大镜像源
    8)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-8): " NUM
            case ${NUM} in
            1)
                aliyun
                set_yum_centos7
                ;;
            2)
                huawei
                set_yum_centos7
                ;;
            3)
                tencent
                set_yum_centos7
                ;;
            4)
                tuna
                set_yum_centos7
                ;;
            5)
                netease
                set_yum_centos7
                ;;
            6)
                nju
                set_yum_centos7
                ;;
            7)
                ustc
                set_yum_centos7
                ;;
            8)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-8)!"${END}
                ;;
            esac
        done
    }
    
    rocky_centos8_9_epel_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)阿里镜像源
    2)华为镜像源
    3)腾讯镜像源
    4)清华镜像源
    5)搜狐镜像源
    6)南京大学镜像源
    7)中科大镜像源
    8)上海交通大学镜像源
    9)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-9): " NUM
            case ${NUM} in
            1)
                aliyun
                set_epel_rocky_centos8_9
                ;;
            2)
                huawei
                set_epel_rocky_centos8_9
                ;;
            3)
                tencent
                set_epel_rocky_centos8_9
                ;;
            4)
                tuna
                set_epel_rocky_centos8_9
                ;;
            5)
                sohu
                set_epel_2_rocky_centos8_9
                ;;
            6)
                nju
                set_epel_rocky_centos8_9
                ;;
            7)
                ustc
                set_epel_rocky_centos8_9
                ;;
            8)
                sjtu
                set_epel_3_rocky_centos8_9
                ;;
            9)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-9)!"${END}
                ;;
            esac
        done
    }
    
    centos7_epel_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)阿里镜像源
    2)华为镜像源
    3)腾讯镜像源
    4)清华镜像源
    5)搜狐镜像源
    6)南京大学镜像源
    7)中科大镜像源
    8)上海交通大学镜像源
    9)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-9): " NUM
            case ${NUM} in
            1)
                aliyun
                set_epel_centos7
                ;;
            2)
                huawei
                set_epel_centos7
                ;;
            3)
                tencent
                set_epel_centos7
                ;;
            4)
                tuna
                set_epel_centos7
                ;;
            5)
                sohu
                set_epel_2_centos7
                ;;
            6)
                nju
                set_epel_centos7
                ;;
            7)
                ustc
                set_epel_centos7
                ;;
            8)
                sjtu
                set_epel_3_centos7
                ;;
            9)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-9)!"${END}
                ;;
            esac
        done
    }
    
    rocky_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)base仓库
    2)epel仓库
    3)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-3): " NUM
            case ${NUM} in
            1)
                rocky8_9_base_menu
                ;;
            2)
                rocky_centos8_9_epel_menu
                ;;
            3)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-3)!"${END}
                ;;
            esac
        done
    }
    
    centos_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)base仓库
    2)epel仓库
    3)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-3): " NUM
            case ${NUM} in
            1)
                if [ ${OS_NAME} == "Stream" ];then
                    if [ ${OS_RELEASE_VERSION} == "8" ];then
                        centos_stream8_base_menu
                    else
                        centos_stream9_base_menu
                    fi
                else
                    centos7_base_menu
                fi
                ;;
            2)
                if [ ${OS_RELEASE_VERSION} == "8" -o ${OS_RELEASE_VERSION} == "9" ];then
                    rocky_centos8_9_epel_menu
                else
                    centos7_epel_menu
                fi
                ;;
            3)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-3)!"${END}
                ;;
            esac
        done
    }
    
    set_apt(){
        OLD_URL=`sed -rn "s@^deb http://(.*)/ubuntu/? $(lsb_release -cs) main.*@\1@p" /etc/apt/sources.list`
        sed -i.bak 's/'${OLD_URL}'/'${URL}'/g' /etc/apt/sources.list
        if [ ${OS_RELEASE_VERSION} == "18" ];then
    	    SEC_URL=`sed -rn "s@^deb http://(.*)/ubuntu $(lsb_release -cs)-security main.*@\1@p" /etc/apt/sources.list`
            sed -i.bak 's/'${SEC_URL}'/'${URL}'/g' /etc/apt/sources.list
        fi
        ${COLOR}"更新镜像源中,请稍等..."${END}
        apt update &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} APT源设置完成!"${END}
    }
    
    apt_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)阿里镜像源
    2)华为镜像源
    3)腾讯镜像源
    4)清华镜像源
    5)网易镜像源
    6)南京大学镜像源
    7)中科大镜像源
    8)上海交通大学镜像源
    9)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-9): " NUM
            case ${NUM} in
            1)
                aliyun
                set_apt
                ;;
            2)
                huawei
                set_apt
                ;;
            3)
                tencent
                set_apt
                ;;
            4)
                tuna
                set_apt
                ;;
            5)
                netease
                set_apt
                ;;
            6)
                nju
                set_apt
                ;;
            7)
                ustc
                set_apt
                ;;
            8)
                sjtu
                set_apt
                ;;
            9)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-9)!"${END}
                ;;
            esac
        done
    }
    
    set_mirror_repository(){
        if [ ${OS_ID} == "CentOS" ];then
            centos_menu
        elif [ ${OS_ID} == "Rocky" ];then
            rocky_menu
        else
            apt_menu
        fi
    }
    
    centos_minimal_install(){
        ${COLOR}'开始安装“Minimal安装建议安装软件包”,请稍等......'${END}
        yum -y install gcc make autoconf gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel vim lrzsz tree tmux lsof tcpdump wget net-tools iotop bc bzip2 zip unzip nfs-utils man-pages &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} Minimal安装建议安装软件包已安装完成!"${END}
    }
    
    ubuntu_minimal_install(){
        ${COLOR}'开始安装“Minimal安装建议安装软件包”,请稍等......'${END}
        apt -y install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev gcc openssh-server iotop unzip zip
        ${COLOR}"${OS_ID} ${OS_RELEASE} Minimal安装建议安装软件包已安装完成!"${END}
    }
    
    minimal_install(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ] &> /dev/null;then
            centos_minimal_install
        else
            ubuntu_minimal_install
        fi
    }
    
    set_mail(){                                                                                                 
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            rpm -q postfix &> /dev/null || { yum -y install postfix &> /dev/null; systemctl enable --now postfix &> /dev/null; }
            rpm -q mailx &> /dev/null || yum -y install mailx &> /dev/null
        else
            dpkg -s mailutils &> /dev/null || apt -y install mailutils
        fi
        read -p "请输入邮箱地址: " MAIL
        read -p "请输入邮箱授权码: " AUTH
        SMTP=`echo ${MAIL} |awk -F"@" '{print $2}'`
        cat >~/.mailrc <<-EOF
    set from=${MAIL}
    set smtp=smtp.${SMTP}
    set smtp-auth-user=${MAIL}
    set smtp-auth-password=${AUTH}
    set smtp-auth=login
    set ssl-verify=ignore
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} 邮件设置完成,请重新登录后才能生效!"${END}
    }
    
    set_sshd_port(){
        disable_selinux
        disable_firewall
        read -p "请输入端口号: " PORT
        sed -i 's/#Port 22/Port '${PORT}'/' /etc/ssh/sshd_config
        ${COLOR}"${OS_ID} ${OS_RELEASE} 更改SSH端口号已完成,请重启系统后生效!"${END}
    }
    
    set_centos_eth(){
        #修改网卡名称配置文件
    	if grep -Eqi "(net\.ifnames|biosdevname)" /etc/default/grub;then
            ${COLOR}"${OS_ID} ${OS_RELEASE} 网卡名配置文件已修改,不用修改!"${END}
        else
            sed -ri.bak '/^GRUB_CMDLINE_LINUX=/s@"$@ net.ifnames=0 biosdevname=0"@' /etc/default/grub
            grub2-mkconfig -o /boot/grub2/grub.cfg >& /dev/null
            ${COLOR}"${OS_ID} ${OS_RELEASE} 网卡名已修改成功,请重新启动系统后才能生效!"${END}
        fi
    }
    
    set_ubuntu_eth(){
        #修改网卡名称配置文件
    	if grep -Eqi "(net\.ifnames|biosdevname)" /etc/default/grub;then
            ${COLOR}"${OS_ID} ${OS_RELEASE} 网卡名配置文件已修改,不用修改!"${END}
        else
            sed -ri.bak '/^GRUB_CMDLINE_LINUX=/s@"$@net.ifnames=0 biosdevname=0"@' /etc/default/grub
            grub-mkconfig -o /boot/grub/grub.cfg >& /dev/null
            ${COLOR}"${OS_ID} ${OS_RELEASE} 网卡名已修改成功,请重新启动系统后才能生效!"${END}
        fi
    }
    
    set_eth(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            set_centos_eth
        else
            set_ubuntu_eth
        fi
    }
    
    check_ip(){
        local IP=$1
        VALID_CHECK=$(echo ${IP}|awk -F. '$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}')
        if echo ${IP}|grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >/dev/null; then
            if [ ${VALID_CHECK} == "yes" ]; then
                echo "IP ${IP}  available!"
                return 0
            else
                echo "IP ${IP} not available!"
                return 1
            fi
        else
            echo "IP format error!"
            return 1
        fi
    }
    
    set_centos_ip(){
        ETHNAME=`ip addr | awk -F"[ :]" '/^2/{print $3}'`
        while true; do
            read -p "请输入IP地址: " IP
            check_ip ${IP}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " C_PREFIX
        while true; do
            read -p "请输入网关地址: " GATEWAY
            check_ip ${GATEWAY}
            [ $? -eq 0 ] && break
        done
        nmcli connection add type ethernet con-name eth0 ifname eth0 ipv4.method manual ipv4.address "${IP}/${C_PREFIX}" ipv4.gateway "${GATEWAY}" ipv4.dns "223.5.5.5,180.76.76.76" autoconnect yes >& /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} IP地址、网关地址和DNS已修改成功,10秒后,机器会自动重启!"${END}
        sleep 10
        nmcli connection delete ${ETHNAME} >& /dev/null
        reboot
    }
    
    set_ubuntu_ip(){
        while true; do
            read -p "请输入IP地址: " IP
            check_ip ${IP}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " U_PREFIX
        while true; do
            read -p "请输入网关地址: " GATEWAY
            check_ip ${GATEWAY}
            [ $? -eq 0 ] && break
        done
        cat > /etc/netplan/01-netcfg.yaml <<-EOF
    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0:
          dhcp4: no
          dhcp6: no
          addresses: [${IP}/${U_PREFIX}] 
          gateway4: ${GATEWAY}
          nameservers:
            addresses: [223.5.5.5, 180.76.76.76]
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} IP地址、网关地址和DNS已修改成功,请重新启动系统后生效!"${END}
    }
    
    set_ubuntu_22_ip(){
        while true; do
            read -p "请输入IP地址: " IP
            check_ip ${IP}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " U_PREFIX
        while true; do
            read -p "请输入网关地址: " GATEWAY
            check_ip ${GATEWAY}
            [ $? -eq 0 ] && break
        done
        cat > /etc/netplan/00-installer-config.yaml <<-EOF
    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0:
          dhcp4: no
          dhcp6: no
          addresses: [${IP}/${U_PREFIX}]
          routes:
            - to: default
              via: ${GATEWAY}
          nameservers:
            addresses: [223.5.5.5, 180.76.76.76]
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} IP地址、网关地址和DNS已修改成功,请重新启动系统后生效!"${END}
    }
    
    set_ip(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            set_centos_ip
        elif [ ${OS_RELEASE_VERSION} == "18" -o ${OS_RELEASE_VERSION} == "20" ];then
            set_ubuntu_ip 
        else
            set_ubuntu_22_ip
        fi
    }
    
    set_dual_centos_ip(){
        ETHNAME=`ip addr | awk -F"[ :]" '/^2/{print $3}'`
        ETHNAME2=`ip addr | awk -F"[ :]" '/^3/{print $3}'`
        while true; do
            read -p "请输入第一块网卡IP地址: " IP
            check_ip ${IP}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " C_PREFIX
        while true; do
            read -p "请输入网关地址: " GATEWAY
            check_ip ${GATEWAY}
            [ $? -eq 0 ] && break
        done
        nmcli connection add type ethernet con-name eth0 ifname eth0 ipv4.method manual ipv4.address "${IP}/${C_PREFIX}" ipv4.gateway "${GATEWAY}" ipv4.dns "223.5.5.5,180.76.76.76" autoconnect yes >& /dev/null
        while true; do
            read -p "请输入第二块网卡IP地址: " IP2
            check_ip ${IP2}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " C_PREFIX2
        nmcli connection add type ethernet con-name eth1 ifname eth1 ipv4.method manual ipv4.address "${IP2}/${C_PREFIX2}" autoconnect yes >& /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} IP地址、网关地址和DNS已修改成功,10秒后,机器会自动重启!"${END}
        sleep 10
        nmcli connection delete ${ETHNAME} >& /dev/null; nmcli connection delete ${ETHNAME2} >& /dev/null
        reboot
    }
    
    set_dual_ubuntu_ip(){
        while true; do
            read -p "请输入第一块网卡IP地址: " IP
            check_ip ${IP}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " U_PREFIX
        while true; do
            read -p "请输入网关地址: " GATEWAY
            check_ip ${GATEWAY}
            [ $? -eq 0 ] && break
        done
        while true; do
            read -p "请输入第二块网卡IP地址: " IP2
            check_ip ${IP2}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " U_PREFIX2
        cat > /etc/netplan/01-netcfg.yaml <<-EOF
    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0:
          dhcp4: no
          dhcp6: no
          addresses: [${IP}/${U_PREFIX}] 
          gateway4: ${GATEWAY}
          nameservers:
            addresses: [223.5.5.5, 180.76.76.76]
        eth1:
          dhcp4: no
          dhcp6: no
          addresses: [${IP2}/${U_PREFIX2}] 
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} IP地址、网关地址和DNS已修改成功,请重新启动系统后生效!"${END}
    }
    
    set_dual_ubuntu_22_ip(){
        while true; do
            read -p "请输入第一块网卡IP地址: " IP
            check_ip ${IP}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " U_PREFIX
        while true; do
            read -p "请输入网关地址: " GATEWAY
            check_ip ${GATEWAY}
            [ $? -eq 0 ] && break
        done
        while true; do
            read -p "请输入第二块网卡IP地址: " IP2
            check_ip ${IP2}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " U_PREFIX2
        cat > /etc/netplan/00-installer-config.yaml <<-EOF
    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0:
          dhcp4: no
          dhcp6: no
          addresses: [${IP}/${U_PREFIX}] 
          routes:
            - to: default
              via: ${GATEWAY}
          nameservers:
            addresses: [223.5.5.5, 180.76.76.76]
        eth1:
          dhcp4: no
          dhcp6: no
          addresses: [${IP2}/${U_PREFIX2}] 
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} IP地址、网关地址和DNS已修改成功,请重新启动系统后生效!"${END}
    }
    
    set_dual_ip(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            set_dual_centos_ip
        elif [ ${OS_RELEASE_VERSION} == "18" -o ${OS_RELEASE_VERSION} == "20" ];then
            set_dual_ubuntu_ip 
        else
            set_dual_ubuntu_22_ip
        fi
    }
    
    set_hostname(){
        read -p "请输入主机名: " HOST
        hostnamectl set-hostname ${HOST}
        ${COLOR}"${OS_ID} ${OS_RELEASE} 主机名设置成功,请重新登录生效!"${END}
    }
    
    red(){
        P_COLOR=31
    }
    
    green(){
        P_COLOR=32
    }
    
    yellow(){
        P_COLOR=33
    }
    
    blue(){
        P_COLOR=34
    }
    
    violet(){
        P_COLOR=35
    }
    
    cyan_blue(){
        P_COLOR=36
    }
    
    random_color(){
        P_COLOR="$[RANDOM%7+31]"
    }
    
    centos_ps1(){
        C_PS1=$(echo "PS1='\[\e[1;${P_COLOR}m\][\u@\h \W]\\$ \[\e[0m\]'" >> ~/.bashrc)
    }
    
    ubuntu_ps1(){
        U_PS1=$(echo 'PS1="\[\e[1;'''${P_COLOR}'''m\]${debian_chroot:+($debian_chroot)}\u@\h:\w\\$ \[\e[0m\]"' >> ~/.bashrc)
    }
    
    set_ps1_env(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            if grep -Eqi "^PS1" ~/.bashrc;then
                sed -i '/^PS1/d' ~/.bashrc
                centos_ps1
            else
                centos_ps1
            fi
        fi
        if [ ${OS_ID} == "Ubuntu" ];then
            if grep -Eqi "^PS1" ~/.bashrc;then
                sed -i '/^PS1/d' ~/.bashrc
                ubuntu_ps1
            else
                ubuntu_ps1
            fi
        fi
    }
    
    set_ps1(){
        TIPS="${COLOR}${OS_ID} ${OS_RELEASE} PS1设置成功,请重新登录生效!${END}"
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)31 红色
    2)32 绿色
    3)33 黄色
    4)34 蓝色
    5)35 紫色
    6)36 青色
    7)随机颜色
    8)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入颜色编号(1-8): " NUM
            case ${NUM} in
            1)
                red
                set_ps1_env
                ${TIPS}
                ;;
            2)
                green
                set_ps1_env
                ${TIPS}
                ;;
            3)
                yellow
                set_ps1_env
                ${TIPS}
                ;;
            4)
                blue
                set_ps1_env
                ${TIPS}
                ;;
            5)
                violet
                set_ps1_env
                ${TIPS}
                ;;
            6)
                cyan_blue
                set_ps1_env
                ${TIPS}
                ;;
            7)
                random_color
                set_ps1_env
                ${TIPS}
                ;;
            8)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-8)!"${END}
                ;;
            esac
        done
    }
    
    set_vim(){
        echo "export EDITOR=vim" >> ~/.bashrc
    }
    
    set_vim_env(){
        if grep -Eqi ".*EDITOR" ~/.bashrc;then
            sed -i '/.*EDITOR/d' ~/.bashrc
            set_vim
        else
            set_vim
        fi
        ${COLOR}"${OS_ID} ${OS_RELEASE} 默认文本编辑器设置成功,请重新登录生效!"${END}
    }
    
    set_history(){
        echo 'export HISTTIMEFORMAT="%F %T "' >> ~/.bashrc 
    }
    
    set_history_env(){
        if grep -Eqi ".*HISTTIMEFORMAT" ~/.bashrc;then
            sed -i '/.*HISTTIMEFORMAT/d' ~/.bashrc
            set_history
        else
            set_history
        fi
        ${COLOR}"${OS_ID} ${OS_RELEASE} history格式设置成功,请重新登录生效!"${END}
    }
    
    set_swap(){
        sed -ri 's/.*swap.*/#&/' /etc/fstab
        if [ ${OS_ID} == "Ubuntu" ];then
            if [ ${OS_RELEASE_VERSION} == 20 -o ${OS_RELEASE_VERSION} == 22 ];then
                SD_NAME=`lsblk|awk -F"[ └─]" '/SWAP/{printf $3}'`
                systemctl mask dev-${SD_NAME}.swap &> /dev/null
            fi
        fi
        swapoff -a
        ${COLOR}"${OS_ID} ${OS_RELEASE} 禁用swap成功!"${END}
    }
    
    set_kernel(){
        cat > /etc/sysctl.conf <<-EOF
    # Controls source route verification
    net.ipv4.conf.default.rp_filter = 1
    net.ipv4.ip_nonlocal_bind = 1
    net.ipv4.ip_forward = 1
    
    # Do not accept source routing
    net.ipv4.conf.default.accept_source_route = 0
    
    # Controls the System Request debugging functionality of the kernel
    kernel.sysrq = 0
    
    # Controls whether core dumps will append the PID to the core filename.
    # Useful for debugging multi-threaded applications.
    kernel.core_uses_pid = 1
    
    # Controls the use of TCP syncookies
    net.ipv4.tcp_syncookies = 1
    
    # Disable netfilter on bridges.
    net.bridge.bridge-nf-call-ip6tables = 0
    net.bridge.bridge-nf-call-iptables = 0
    net.bridge.bridge-nf-call-arptables = 0
    
    # Controls the default maxmimum size of a mesage queue
    kernel.msgmnb = 65536
    
    # Controls the maximum size of a message, in bytes
    kernel.msgmax = 65536
    
    # Controls the maximum shared segment size, in bytes
    kernel.shmmax = 68719476736
    
    # Controls the maximum number of shared memory segments, in pages
    kernel.shmall = 4294967296
    
    # TCP kernel paramater
    net.ipv4.tcp_mem = 786432 1048576 1572864
    net.ipv4.tcp_rmem = 4096        87380   4194304
    net.ipv4.tcp_wmem = 4096        16384   4194304
    net.ipv4.tcp_window_scaling = 1
    net.ipv4.tcp_sack = 1
    
    # socket buffer
    net.core.wmem_default = 8388608
    net.core.rmem_default = 8388608
    net.core.rmem_max = 16777216
    net.core.wmem_max = 16777216
    net.core.netdev_max_backlog = 262144
    net.core.somaxconn = 20480
    net.core.optmem_max = 81920
    
    # TCP conn
    net.ipv4.tcp_max_syn_backlog = 262144
    net.ipv4.tcp_syn_retries = 3
    net.ipv4.tcp_retries1 = 3
    net.ipv4.tcp_retries2 = 15
    
    # tcp conn reuse
    net.ipv4.tcp_tw_reuse = 1
    net.ipv4.tcp_tw_recycle = 0
    net.ipv4.tcp_fin_timeout = 30
    net.ipv4.tcp_timestamps = 0
    
    net.ipv4.tcp_max_tw_buckets = 20000
    net.ipv4.tcp_max_orphans = 3276800
    net.ipv4.tcp_synack_retries = 1
    net.ipv4.tcp_syncookies = 1
    
    # keepalive conn
    net.ipv4.tcp_keepalive_time = 300
    net.ipv4.tcp_keepalive_intvl = 30
    net.ipv4.tcp_keepalive_probes = 3
    net.ipv4.ip_local_port_range = 10001    65000
    
    # swap
    vm.overcommit_memory = 0
    vm.swappiness = 10
    
    #net.ipv4.conf.eth1.rp_filter = 0
    #net.ipv4.conf.lo.arp_ignore = 1
    #net.ipv4.conf.lo.arp_announce = 2
    #net.ipv4.conf.all.arp_ignore = 1
    #net.ipv4.conf.all.arp_announce = 2
    EOF
        sysctl -p &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} 优化内核参数成功!"${END}
    }
    
    set_limits(){
        cat >> /etc/security/limits.conf <<-EOF
    root     soft   core     unlimited
    root     hard   core     unlimited
    root     soft   nproc    1000000
    root     hard   nproc    1000000
    root     soft   nofile   1000000
    root     hard   nofile   1000000
    root     soft   memlock  32000
    root     hard   memlock  32000
    root     soft   msgqueue 8192000
    root     hard   msgqueue 8192000
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} 优化资源限制参数成功!"${END}
    }
    
    set_localtime(){
        ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
        echo 'Asia/Shanghai' >/etc/timezone
        if [ ${OS_ID} == "Ubuntu" ];then
            cat >> /etc/default/locale <<-EOF
    LC_TIME=en_DK.UTF-8
    EOF
        fi
        ${COLOR}"${OS_ID} ${OS_RELEASE} 系统时区已设置成功,请重启系统后生效!"${END}
    }
    
    disable_restart(){
        if [ -f /usr/lib/systemd/system/ctrl-alt-del.target ];then
            cp /usr/lib/systemd/system/ctrl-alt-del.target{,.bak}
            rm -f /usr/lib/systemd/system/ctrl-alt-del.target
            ${COLOR}"${OS_ID} ${OS_RELEASE} 禁用ctrl+alt+del重启处理成功!"${END}
        else
            ${COLOR}"${OS_ID} ${OS_RELEASE} 禁用ctrl+alt+del已处理!"${END}
        fi
    }
    
    set_root_login(){
        read -p "请输入密码: " PASSWORD
        echo ${PASSWORD} |sudo -S sed -ri 's@#(PermitRootLogin )prohibit-password@\1yes@' /etc/ssh/sshd_config
        sudo systemctl restart sshd
        sudo -S passwd root <<-EOF
    ${PASSWORD}
    ${PASSWORD}
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} root用户登录已设置完成,请重新登录后生效!"${END}
    }
    
    ubuntu_remove(){
        apt purge ufw lxd lxd-client lxcfs liblxc-common
        ${COLOR}"${OS_ID} ${OS_RELEASE} 无用软件包卸载完成!"${END}
    }
    
    menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    ********************************************************************
    *                           初始化脚本菜单                         *
    * 1.禁用SELinux                    15.设置PS1(请进入选择颜色)      *
    * 2.关闭防火墙                     16.设置默认文本编辑器为vim      *
    * 3.优化SSH                        17.设置history格式              *
    * 4.设置系统别名                   18.禁用SWAP                     *
    * 5.1-4全设置                      19.优化内核参数                 *
    * 6.设置vimrc配置文件              20.优化资源限制参数             *
    * 7.设置镜像仓库                   21.设置系统时区                 *
    * 8.Minimal安装建议安装软件        22.禁用ctrl+alt+del重启         *
    * 9.安装邮件服务并配置邮件         23.Ubuntu设置root用户登录       *
    * 10.更改SSH端口号                 24.Ubuntu卸载无用软件包         *
    * 11.修改网卡名                    25.重启系统                     *
    * 12.修改IP地址和网关地址(单网卡)  26.关机                         *
    * 13.修改IP地址和网关地址(双网卡)  27.退出                         *
    * 14.设置主机名                                                    *
    ********************************************************************
    EOF
            echo -e '\E[0m'
    
            read -p "请选择相应的编号(1-27): " choice
            case ${choice} in
            1)
                disable_selinux
                ;;
            2)
                disable_firewall
                ;;
            3)
                optimization_sshd
                ;;
            4)
                set_alias
                ;;
            5)
                disable_selinux
                disable_firewall
                optimization_sshd
                set_alias
                ;;
            6)
                set_vimrc
                ;;
            7)
                set_mirror_repository
                ;;
            8)
                minimal_install
                ;;
            9)
                set_mail
                ;;
            10)
                set_sshd_port
                ;;
            11)
                set_eth
                ;;
            12)
                set_ip
                ;;
            13)
                set_dual_ip
                ;;
            14)
                set_hostname
                ;;
            15)
                set_ps1
                ;;
            16)
                set_vim_env
                ;;
            17)
                set_history_env
                ;;
            18)
                set_swap
                ;;
            19)
                set_kernel
                ;;
            20)
                set_limits
                ;;
            21)
                set_localtime
                ;;
            22)
                disable_restart
                ;;
            23)
                set_root_login
                ;;
            24)
                ubuntu_remove
                ;;
            25)
                reboot
                ;;
            26)
                shutdown -h now
                ;;
            27)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-27)!"${END}
                ;;
            esac
        done
    }
    
    main(){
        os
        menu
    }
    
    main
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    • 450
    • 451
    • 452
    • 453
    • 454
    • 455
    • 456
    • 457
    • 458
    • 459
    • 460
    • 461
    • 462
    • 463
    • 464
    • 465
    • 466
    • 467
    • 468
    • 469
    • 470
    • 471
    • 472
    • 473
    • 474
    • 475
    • 476
    • 477
    • 478
    • 479
    • 480
    • 481
    • 482
    • 483
    • 484
    • 485
    • 486
    • 487
    • 488
    • 489
    • 490
    • 491
    • 492
    • 493
    • 494
    • 495
    • 496
    • 497
    • 498
    • 499
    • 500
    • 501
    • 502
    • 503
    • 504
    • 505
    • 506
    • 507
    • 508
    • 509
    • 510
    • 511
    • 512
    • 513
    • 514
    • 515
    • 516
    • 517
    • 518
    • 519
    • 520
    • 521
    • 522
    • 523
    • 524
    • 525
    • 526
    • 527
    • 528
    • 529
    • 530
    • 531
    • 532
    • 533
    • 534
    • 535
    • 536
    • 537
    • 538
    • 539
    • 540
    • 541
    • 542
    • 543
    • 544
    • 545
    • 546
    • 547
    • 548
    • 549
    • 550
    • 551
    • 552
    • 553
    • 554
    • 555
    • 556
    • 557
    • 558
    • 559
    • 560
    • 561
    • 562
    • 563
    • 564
    • 565
    • 566
    • 567
    • 568
    • 569
    • 570
    • 571
    • 572
    • 573
    • 574
    • 575
    • 576
    • 577
    • 578
    • 579
    • 580
    • 581
    • 582
    • 583
    • 584
    • 585
    • 586
    • 587
    • 588
    • 589
    • 590
    • 591
    • 592
    • 593
    • 594
    • 595
    • 596
    • 597
    • 598
    • 599
    • 600
    • 601
    • 602
    • 603
    • 604
    • 605
    • 606
    • 607
    • 608
    • 609
    • 610
    • 611
    • 612
    • 613
    • 614
    • 615
    • 616
    • 617
    • 618
    • 619
    • 620
    • 621
    • 622
    • 623
    • 624
    • 625
    • 626
    • 627
    • 628
    • 629
    • 630
    • 631
    • 632
    • 633
    • 634
    • 635
    • 636
    • 637
    • 638
    • 639
    • 640
    • 641
    • 642
    • 643
    • 644
    • 645
    • 646
    • 647
    • 648
    • 649
    • 650
    • 651
    • 652
    • 653
    • 654
    • 655
    • 656
    • 657
    • 658
    • 659
    • 660
    • 661
    • 662
    • 663
    • 664
    • 665
    • 666
    • 667
    • 668
    • 669
    • 670
    • 671
    • 672
    • 673
    • 674
    • 675
    • 676
    • 677
    • 678
    • 679
    • 680
    • 681
    • 682
    • 683
    • 684
    • 685
    • 686
    • 687
    • 688
    • 689
    • 690
    • 691
    • 692
    • 693
    • 694
    • 695
    • 696
    • 697
    • 698
    • 699
    • 700
    • 701
    • 702
    • 703
    • 704
    • 705
    • 706
    • 707
    • 708
    • 709
    • 710
    • 711
    • 712
    • 713
    • 714
    • 715
    • 716
    • 717
    • 718
    • 719
    • 720
    • 721
    • 722
    • 723
    • 724
    • 725
    • 726
    • 727
    • 728
    • 729
    • 730
    • 731
    • 732
    • 733
    • 734
    • 735
    • 736
    • 737
    • 738
    • 739
    • 740
    • 741
    • 742
    • 743
    • 744
    • 745
    • 746
    • 747
    • 748
    • 749
    • 750
    • 751
    • 752
    • 753
    • 754
    • 755
    • 756
    • 757
    • 758
    • 759
    • 760
    • 761
    • 762
    • 763
    • 764
    • 765
    • 766
    • 767
    • 768
    • 769
    • 770
    • 771
    • 772
    • 773
    • 774
    • 775
    • 776
    • 777
    • 778
    • 779
    • 780
    • 781
    • 782
    • 783
    • 784
    • 785
    • 786
    • 787
    • 788
    • 789
    • 790
    • 791
    • 792
    • 793
    • 794
    • 795
    • 796
    • 797
    • 798
    • 799
    • 800
    • 801
    • 802
    • 803
    • 804
    • 805
    • 806
    • 807
    • 808
    • 809
    • 810
    • 811
    • 812
    • 813
    • 814
    • 815
    • 816
    • 817
    • 818
    • 819
    • 820
    • 821
    • 822
    • 823
    • 824
    • 825
    • 826
    • 827
    • 828
    • 829
    • 830
    • 831
    • 832
    • 833
    • 834
    • 835
    • 836
    • 837
    • 838
    • 839
    • 840
    • 841
    • 842
    • 843
    • 844
    • 845
    • 846
    • 847
    • 848
    • 849
    • 850
    • 851
    • 852
    • 853
    • 854
    • 855
    • 856
    • 857
    • 858
    • 859
    • 860
    • 861
    • 862
    • 863
    • 864
    • 865
    • 866
    • 867
    • 868
    • 869
    • 870
    • 871
    • 872
    • 873
    • 874
    • 875
    • 876
    • 877
    • 878
    • 879
    • 880
    • 881
    • 882
    • 883
    • 884
    • 885
    • 886
    • 887
    • 888
    • 889
    • 890
    • 891
    • 892
    • 893
    • 894
    • 895
    • 896
    • 897
    • 898
    • 899
    • 900
    • 901
    • 902
    • 903
    • 904
    • 905
    • 906
    • 907
    • 908
    • 909
    • 910
    • 911
    • 912
    • 913
    • 914
    • 915
    • 916
    • 917
    • 918
    • 919
    • 920
    • 921
    • 922
    • 923
    • 924
    • 925
    • 926
    • 927
    • 928
    • 929
    • 930
    • 931
    • 932
    • 933
    • 934
    • 935
    • 936
    • 937
    • 938
    • 939
    • 940
    • 941
    • 942
    • 943
    • 944
    • 945
    • 946
    • 947
    • 948
    • 949
    • 950
    • 951
    • 952
    • 953
    • 954
    • 955
    • 956
    • 957
    • 958
    • 959
    • 960
    • 961
    • 962
    • 963
    • 964
    • 965
    • 966
    • 967
    • 968
    • 969
    • 970
    • 971
    • 972
    • 973
    • 974
    • 975
    • 976
    • 977
    • 978
    • 979
    • 980
    • 981
    • 982
    • 983
    • 984
    • 985
    • 986
    • 987
    • 988
    • 989
    • 990
    • 991
    • 992
    • 993
    • 994
    • 995
    • 996
    • 997
    • 998
    • 999
    • 1000
    • 1001
    • 1002
    • 1003
    • 1004
    • 1005
    • 1006
    • 1007
    • 1008
    • 1009
    • 1010
    • 1011
    • 1012
    • 1013
    • 1014
    • 1015
    • 1016
    • 1017
    • 1018
    • 1019
    • 1020
    • 1021
    • 1022
    • 1023
    • 1024
    • 1025
    • 1026
    • 1027
    • 1028
    • 1029
    • 1030
    • 1031
    • 1032
    • 1033
    • 1034
    • 1035
    • 1036
    • 1037
    • 1038
    • 1039
    • 1040
    • 1041
    • 1042
    • 1043
    • 1044
    • 1045
    • 1046
    • 1047
    • 1048
    • 1049
    • 1050
    • 1051
    • 1052
    • 1053
    • 1054
    • 1055
    • 1056
    • 1057
    • 1058
    • 1059
    • 1060
    • 1061
    • 1062
    • 1063
    • 1064
    • 1065
    • 1066
    • 1067
    • 1068
    • 1069
    • 1070
    • 1071
    • 1072
    • 1073
    • 1074
    • 1075
    • 1076
    • 1077
    • 1078
    • 1079
    • 1080
    • 1081
    • 1082
    • 1083
    • 1084
    • 1085
    • 1086
    • 1087
    • 1088
    • 1089
    • 1090
    • 1091
    • 1092
    • 1093
    • 1094
    • 1095
    • 1096
    • 1097
    • 1098
    • 1099
    • 1100
    • 1101
    • 1102
    • 1103
    • 1104
    • 1105
    • 1106
    • 1107
    • 1108
    • 1109
    • 1110
    • 1111
    • 1112
    • 1113
    • 1114
    • 1115
    • 1116
    • 1117
    • 1118
    • 1119
    • 1120
    • 1121
    • 1122
    • 1123
    • 1124
    • 1125
    • 1126
    • 1127
    • 1128
    • 1129
    • 1130
    • 1131
    • 1132
    • 1133
    • 1134
    • 1135
    • 1136
    • 1137
    • 1138
    • 1139
    • 1140
    • 1141
    • 1142
    • 1143
    • 1144
    • 1145
    • 1146
    • 1147
    • 1148
    • 1149
    • 1150
    • 1151
    • 1152
    • 1153
    • 1154
    • 1155
    • 1156
    • 1157
    • 1158
    • 1159
    • 1160
    • 1161
    • 1162
    • 1163
    • 1164
    • 1165
    • 1166
    • 1167
    • 1168
    • 1169
    • 1170
    • 1171
    • 1172
    • 1173
    • 1174
    • 1175
    • 1176
    • 1177
    • 1178
    • 1179
    • 1180
    • 1181
    • 1182
    • 1183
    • 1184
    • 1185
    • 1186
    • 1187
    • 1188
    • 1189
    • 1190
    • 1191
    • 1192
    • 1193
    • 1194
    • 1195
    • 1196
    • 1197
    • 1198
    • 1199
    • 1200
    • 1201
    • 1202
    • 1203
    • 1204
    • 1205
    • 1206
    • 1207
    • 1208
    • 1209
    • 1210
    • 1211
    • 1212
    • 1213
    • 1214
    • 1215
    • 1216
    • 1217
    • 1218
    • 1219
    • 1220
    • 1221
    • 1222
    • 1223
    • 1224
    • 1225
    • 1226
    • 1227
    • 1228
    • 1229
    • 1230
    • 1231
    • 1232
    • 1233
    • 1234
    • 1235
    • 1236
    • 1237
    • 1238
    • 1239
    • 1240
    • 1241
    • 1242
    • 1243
    • 1244
    • 1245
    • 1246
    • 1247
    • 1248
    • 1249
    • 1250
    • 1251
    • 1252
    • 1253
    • 1254
    • 1255
    • 1256
    • 1257
    • 1258
    • 1259
    • 1260
    • 1261
    • 1262
    • 1263
    • 1264
    • 1265
    • 1266
    • 1267
    • 1268
    • 1269
    • 1270
    • 1271
    • 1272
    • 1273
    • 1274
    • 1275
    • 1276
    • 1277
    • 1278
    • 1279
    • 1280
    • 1281
    • 1282
    • 1283
    • 1284
    • 1285
    • 1286
    • 1287
    • 1288
    • 1289
    • 1290
    • 1291
    • 1292
    • 1293
    • 1294
    • 1295
    • 1296
    • 1297
    • 1298
    • 1299
    • 1300
    • 1301
    • 1302
    • 1303
    • 1304
    • 1305
    • 1306
    • 1307
    • 1308
    • 1309
    • 1310
    • 1311
    • 1312
    • 1313
    • 1314
    • 1315
    • 1316
    • 1317
    • 1318
    • 1319
    • 1320
    • 1321
    • 1322
    • 1323
    • 1324
    • 1325
    • 1326
    • 1327
    • 1328
    • 1329
    • 1330
    • 1331
    • 1332
    • 1333
    • 1334
    • 1335
    • 1336
    • 1337
    • 1338
    • 1339
    • 1340
    • 1341
    • 1342
    • 1343
    • 1344
    • 1345
    • 1346
    • 1347
    • 1348
    • 1349
    • 1350
    • 1351
    • 1352
    • 1353
    • 1354
    • 1355
    • 1356
    • 1357
    • 1358
    • 1359
    • 1360
    • 1361
    • 1362
    • 1363
    • 1364
    • 1365
    • 1366
    • 1367
    • 1368
    • 1369
    • 1370
    • 1371
    • 1372
    • 1373
    • 1374
    • 1375
    • 1376
    • 1377
    • 1378
    • 1379
    • 1380
    • 1381
    • 1382
    • 1383
    • 1384
    • 1385
    • 1386
    • 1387
    • 1388
    • 1389
    • 1390
    • 1391
    • 1392
    • 1393
    • 1394
    • 1395
    • 1396
    • 1397
    • 1398
    • 1399
    • 1400
    • 1401
    • 1402
    • 1403
    • 1404
    • 1405
    • 1406
    • 1407
    • 1408
    • 1409
    • 1410
    • 1411
    • 1412
    • 1413
    • 1414
    • 1415
    • 1416
    • 1417
    • 1418
    • 1419
    • 1420
    • 1421
    • 1422
    • 1423
    • 1424
    • 1425
    • 1426
    • 1427
    • 1428
    • 1429
    • 1430
    • 1431
    • 1432
    • 1433
    • 1434
    • 1435
    • 1436
    • 1437
    • 1438
    • 1439
    • 1440
    • 1441
    • 1442
    • 1443
    • 1444

    CentOS Stream 9修改镜像仓库需要下面的perl脚本。

    [root@rocky9 ~]# cat update_mirror.pl
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use autodie;
    
    # 要修改镜像源,请去修改url变量!
    my $url = 'mirrors.aliyun.com';
    my $mirrors = "https://$url/centos-stream";
    
    if (@ARGV < 1) {
        die "Usage: $0   ...\n";
    }
    
    while (my $filename = shift @ARGV) {
        my $backup_filename = $filename . '.bak';
        rename $filename, $backup_filename;
    
        open my $input, "<", $backup_filename;
        open my $output, ">", $filename;
    
        while (<$input>) {
            s/^metalink/# metalink/;
    
            if (m/^name/) {
                my (undef, $repo, $arch) = split /-/;
                $repo =~ s/^\s+|\s+$//g;
                ($arch = defined $arch ? lc($arch) : '') =~ s/^\s+|\s+$//g;
    
                if ($repo =~ /^Extras/) {
                    $_ .= "baseurl=${mirrors}/SIGs/\$releasever-stream/extras" . ($arch eq 'source' ? "/${arch}/" : "/\$basearch/") . "extras-common\n";
                } else {
                    $_ .= "baseurl=${mirrors}/\$releasever-stream/$repo" . ($arch eq 'source' ? "/" : "/\$basearch/") . ($arch ne '' ? "${arch}/tree/" : "os") . "\n";
                }
            }
    
            print $output $_;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40

    下面是reset_v6_2脚本内容:

    [root@rocky9 ~]# cat reset_v6_2.sh
    #!/bin/bash
    #
    #***************************************************************************************************
    #Author:        Raymond
    #QQ:            88563128
    #Date:          2023-11-15
    #FileName:      reset_v6_2.sh
    #URL:           raymond.blog.csdn.net
    #Description:   reset for CentOS 7 & CentOS Stream 8/9 & Ubuntu 18.04/20.04/22.04 & Rocky 8/9
    #Copyright (C): 2023 All rights reserved
    #***************************************************************************************************
    COLOR="echo -e \\033[01;31m"
    END='\033[0m'
    
    os(){
        OS_ID=`sed -rn '/^NAME=/s@.*="([[:alpha:]]+).*"$@\1@p' /etc/os-release`
        OS_NAME=`sed -rn '/^NAME=/s@.*="([[:alpha:]]+) (.*)"$@\2@p' /etc/os-release`
        OS_RELEASE=`sed -rn '/^VERSION_ID=/s@.*="?([0-9.]+)"?@\1@p' /etc/os-release`
        OS_RELEASE_VERSION=`sed -rn '/^VERSION_ID=/s@.*="?([0-9]+)\.?.*"?@\1@p' /etc/os-release`
    }
    
    disable_selinux(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            if [ `getenforce` == "Enforcing" ];then
                sed -ri.bak 's/^(SELINUX=).*/\1disabled/' /etc/selinux/config
                ${COLOR}"${OS_ID} ${OS_RELEASE} SELinux已禁用,请重新启动系统后才能生效!"${END}
            else
                ${COLOR}"${OS_ID} ${OS_RELEASE} SELinux已被禁用,不用设置!"${END}
            fi
        else
            ${COLOR}"${OS_ID} ${OS_RELEASE} SELinux默认没有安装,不用设置!"${END}
        fi
    }
    
    disable_firewall(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            rpm -q firewalld &> /dev/null && { systemctl disable --now firewalld &> /dev/null; ${COLOR}"${OS_ID} ${OS_RELEASE} Firewall防火墙已关闭!"${END}; } || ${COLOR}"${OS_ID} ${OS_RELEASE} iptables防火墙已关闭!"${END}
        else
            dpkg -s ufw &> /dev/null && { systemctl disable --now ufw &> /dev/null; ${COLOR}"${OS_ID} ${OS_RELEASE} ufw防火墙已关闭!"${END}; } || ${COLOR}"${OS_ID} ${OS_RELEASE}  没有ufw防火墙服务,不用关闭!"${END}
        fi
    }
    
    optimization_sshd(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            sed -ri.bak -e 's/^#(UseDNS).*/\1 no/' -e 's/^(GSSAPIAuthentication).*/\1 no/' /etc/ssh/sshd_config
        else
            sed -ri.bak -e 's/^#(UseDNS).*/\1 no/' -e 's/^#(GSSAPIAuthentication).*/\1 no/' /etc/ssh/sshd_config
        fi
        systemctl restart sshd
        ${COLOR}"${OS_ID} ${OS_RELEASE} SSH已优化完成!"${END}
    }
    
    set_centos_alias(){
        if [ ${OS_RELEASE_VERSION} == "7" -o ${OS_RELEASE_VERSION} == "8" ];then
            cat >>~/.bashrc <<-EOF
    alias cdnet="cd /etc/sysconfig/network-scripts"
    alias vie0="vim /etc/sysconfig/network-scripts/ifcfg-eth0"
    alias vie1="vim /etc/sysconfig/network-scripts/ifcfg-eth1"
    alias scandisk="echo '- - -' > /sys/class/scsi_host/host0/scan;echo '- - -' > /sys/class/scsi_host/host1/scan;echo '- - -' > /sys/class/scsi_host/host2/scan"
    EOF
        else
            cat >>~/.bashrc <<-EOF
    alias cdnet="cd /etc/NetworkManager/system-connections"
    alias vie0="vim /etc/NetworkManager/system-connections/eth0.nmconnection"
    alias vie1="vim /etc/NetworkManager/system-connections/eth1.nmconnection"
    alias scandisk="echo '- - -' > /sys/class/scsi_host/host0/scan;echo '- - -' > /sys/class/scsi_host/host1/scan;echo '- - -' > /sys/class/scsi_host/host2/scan"
    EOF
        fi
        ${COLOR}"${OS_ID} ${OS_RELEASE} 系统别名已设置成功,请重新登陆后生效!"${END}
    }
    
    set_ubuntu_alias(){
        cat >>~/.bashrc <<-EOF
    alias cdnet="cd /etc/netplan"
    alias scandisk="echo '- - -' > /sys/class/scsi_host/host0/scan;echo '- - -' > /sys/class/scsi_host/host1/scan;echo '- - -' > /sys/class/scsi_host/host2/scan"
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} 系统别名已设置成功,请重新登陆后生效!"${END}
    }
    
    set_alias(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            if grep -Eqi "(.*cdnet|.*vie0|.*vie1|.*scandisk)" ~/.bashrc;then
                sed -i -e '/.*cdnet/d'  -e '/.*vie0/d' -e '/.*vie1/d' -e '/.*scandisk/d' ~/.bashrc
                set_centos_alias
            else
                set_centos_alias
            fi
        fi
        if [ ${OS_ID} == "Ubuntu" ];then
            if grep -Eqi "(.*cdnet|.*scandisk)" ~/.bashrc;then
                sed -i -e '/.*cdnet/d' -e '/.*scandisk/d' ~/.bashrc
                set_ubuntu_alias
            else
                set_ubuntu_alias
            fi
        fi
    }
    
    set_vimrc(){
        read -p "请输入作者名: " AUTHOR
        read -p "请输入QQ号: " QQ
        read -p "请输入网址: " V_URL
        cat >~/.vimrc <<-EOF
    set ts=4
    set expandtab
    set ignorecase
    set cursorline
    set autoindent
    autocmd BufNewFile *.sh exec ":call SetTitle()"
    func SetTitle()
        if expand("%:e") == 'sh'
        call setline(1,"#!/bin/bash")
        call setline(2,"#")
        call setline(3,"#**********************************************************************************************")
        call setline(4,"#Author:        ${AUTHOR}")
        call setline(5,"#QQ:            ${QQ}")
        call setline(6,"#Date:          ".strftime("%Y-%m-%d"))
        call setline(7,"#FileName:      ".expand("%"))
        call setline(8,"#URL:           ${V_URL}")
        call setline(9,"#Description:   The test script")
        call setline(10,"#Copyright (C): ".strftime("%Y")." All rights reserved")
        call setline(11,"#*********************************************************************************************")
        call setline(12,"")
        endif
    endfunc
    autocmd BufNewFile * normal G
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} vimrc设置完成,请重新系统启动才能生效!"${END}
    }
    
    aliyun(){
        URL=mirrors.aliyun.com
    }
    
    huawei(){
        URL=repo.huaweicloud.com
    }
    
    tencent(){
        URL=mirrors.tencent.com
    }
    
    tuna(){
        URL=mirrors.tuna.tsinghua.edu.cn
    }
    
    netease(){
        URL=mirrors.163.com
    }
    
    sohu(){
        URL=mirrors.sohu.com
    }
    
    nju(){
        URL=mirrors.nju.edu.cn
    }
    
    ustc(){
        URL=mirrors.ustc.edu.cn
    }
    
    sjtu(){
        URL=mirrors.sjtug.sjtu.edu.cn
    }
    
    set_yum_rocky9(){
        [ -d /etc/yum.repos.d/backup ] || mkdir /etc/yum.repos.d/backup
        (ls -l /etc/yum.repos.d/ |grep -q repo) && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup || ${COLOR}"没有repo文件!"${END}
        cat > /etc/yum.repos.d/base.repo <<-EOF
    [BaseOS]
    name=BaseOS
    baseurl=https://${URL}/rocky/\$releasever/BaseOS/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-\$releasever
    
    [AppStream]
    name=AppStream
    baseurl=https://${URL}/rocky/\$releasever/AppStream/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-\$releasever
    
    [extras]
    name=extras
    baseurl=https://${URL}/rocky/\$releasever/extras/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-\$releasever
    EOF
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} YUM源设置完成!"${END}
    }
    
    set_yum_rocky9_2(){
        [ -d /etc/yum.repos.d/backup ] || mkdir /etc/yum.repos.d/backup
        (ls -l /etc/yum.repos.d/ |grep -q repo) && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup || ${COLOR}"没有repo文件!"${END}
        cat > /etc/yum.repos.d/base.repo <<-EOF
    [BaseOS]
    name=BaseOS
    baseurl=https://${URL}/rockylinux/\$releasever/BaseOS/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-\$releasever
    
    [AppStream]
    name=AppStream
    baseurl=https://${URL}/rockylinux/\$releasever/AppStream/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-\$releasever
    
    [extras]
    name=extras
    baseurl=https://${URL}/rockylinux/\$releasever/extras/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-\$releasever
    EOF
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} YUM源设置完成!"${END}
    }
    
    set_yum_rocky8(){
        [ -d /etc/yum.repos.d/backup ] || mkdir /etc/yum.repos.d/backup
        (ls -l /etc/yum.repos.d/ |grep -q repo) && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup || ${COLOR}"没有repo文件!"${END}
        cat > /etc/yum.repos.d/base.repo <<-EOF
    [BaseOS]
    name=BaseOS
    baseurl=https://${URL}/rocky/\$releasever/BaseOS/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
    
    [AppStream]
    name=AppStream
    baseurl=https://${URL}/rocky/\$releasever/AppStream/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
    
    [extras]
    name=extras
    baseurl=https://${URL}/rocky/\$releasever/extras/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
    EOF
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} YUM源设置完成!"${END}
    }
    
    set_yum_rocky8_2(){
        [ -d /etc/yum.repos.d/backup ] || mkdir /etc/yum.repos.d/backup
        (ls -l /etc/yum.repos.d/ |grep -q repo) && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup || ${COLOR}"没有repo文件!"${END}
        cat > /etc/yum.repos.d/base.repo <<-EOF
    [BaseOS]
    name=BaseOS
    baseurl=https://${URL}/rockylinux/\$releasever/BaseOS/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
    
    [AppStream]
    name=AppStream
    baseurl=https://${URL}/rockylinux/\$releasever/AppStream/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
    
    [extras]
    name=extras
    baseurl=https://${URL}/rockylinux/\$releasever/extras/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
    EOF
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} YUM源设置完成!"${END}
    }
    
    set_yum_centos_stream9(){
        [ -d /etc/yum.repos.d/backup ] || mkdir /etc/yum.repos.d/backup
        (ls -l /etc/yum.repos.d/ |grep -q repo) && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup || ${COLOR}"没有repo文件!"${END}
        cat > /etc/yum.repos.d/base.repo <<-EOF
    [BaseOS]
    name=BaseOS
    baseurl=https://${URL}/centos-stream/\$stream/BaseOS/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    
    [AppStream]
    name=AppStream
    baseurl=https://${URL}/centos-stream/\$stream/AppStream/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    
    [extras-common]
    name=extras-common
    baseurl=https://${URL}/centos-stream/SIGs/\$stream/extras/\$basearch/extras-common/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    EOF
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} YUM源设置完成!"${END}
    }
    
    set_yum_centos_stream8(){
        [ -d /etc/yum.repos.d/backup ] || mkdir /etc/yum.repos.d/backup
        (ls -l /etc/yum.repos.d/ |grep -q repo) && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup || ${COLOR}"没有repo文件!"${END}
        cat > /etc/yum.repos.d/base.repo <<-EOF
    [BaseOS]
    name=BaseOS
    baseurl=https://${URL}/centos/\$stream/BaseOS/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    
    [AppStream]
    name=AppStream
    baseurl=https://${URL}/centos/\$stream/AppStream/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    
    [extras]
    name=extras
    baseurl=https://${URL}/centos/\$stream/extras/\$basearch/os/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    EOF
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} YUM源设置完成!"${END}
    }
    
    set_epel_rocky_centos8_9(){
        cat > /etc/yum.repos.d/epel.repo <<-EOF
    [epel]
    name=epel
    baseurl=https://${URL}/epel/\$releasever/Everything/\$basearch/
    gpgcheck=1
    gpgkey=https://${URL}/epel/RPM-GPG-KEY-EPEL-\$releasever
    EOF
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} EPEL源设置完成!"${END}
    }
    
    set_epel_2_rocky_centos8_9(){
        cat > /etc/yum.repos.d/epel.repo <<-EOF
    [epel]
    name=epel
    baseurl=https://${URL}/fedora-epel/\$releasever/Everything/\$basearch/
    gpgcheck=1
    gpgkey=https://${URL}/fedora-epel/RPM-GPG-KEY-EPEL-\$releasever
    EOF
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} EPEL源设置完成!"${END}
    }
    
    set_epel_3_rocky_centos8_9(){
        cat > /etc/yum.repos.d/epel.repo <<-EOF
    [epel]
    name=epel
    baseurl=https://${URL}/fedora/epel/\$releasever/Everything/\$basearch/
    gpgcheck=1
    gpgkey=https://${URL}/fedora/epel/RPM-GPG-KEY-EPEL-\$releasever
    EOF
        ${COLOR}"更新镜像源中,请稍等..."${END}
        dnf clean all &> /dev/null
        dnf makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} EPEL源设置完成!"${END}
    }
    
    set_yum_centos7(){    
        [ -d /etc/yum.repos.d/backup ] || mkdir /etc/yum.repos.d/backup
        (ls -l /etc/yum.repos.d/ |grep -q repo) && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup || ${COLOR}"没有repo文件!"${END}
        cat > /etc/yum.repos.d/base.repo <<-EOF
    [base]
    name=base
    baseurl=https://${URL}/centos/\$releasever/os/\$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever
    
    [extras]
    name=extras
    baseurl=https://${URL}/centos/\$releasever/extras/\$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever
    
    [updates]
    name=updates
    baseurl=https://${URL}/centos/\$releasever/updates/\$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever
    EOF
        ${COLOR}"更新镜像源中,请稍等..."${END}
        yum clean all &> /dev/null
        yum makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} YUM源设置完成!"${END}
    }
    
    set_epel_centos7(){
        cat > /etc/yum.repos.d/epel.repo <<-EOF
    [epel]
    name=epel
    baseurl=https://${URL}/epel/\$releasever/\$basearch/
    gpgcheck=1
    gpgkey=https://${URL}/epel/RPM-GPG-KEY-EPEL-\$releasever
    EOF
        ${COLOR}"更新镜像源中,请稍等..."${END}
        yum clean all &> /dev/null
        yum makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} EPEL源设置完成!"${END}
    }
    
    set_epel_2_centos7(){
        cat > /etc/yum.repos.d/epel.repo <<-EOF
    [epel]
    name=epel
    baseurl=https://${URL}/fedora-epel/\$releasever/\$basearch/
    gpgcheck=1
    gpgkey=https://${URL}/fedora-epel/RPM-GPG-KEY-EPEL-\$releasever
    EOF
        ${COLOR}"更新镜像源中,请稍等..."${END}
        yum clean all &> /dev/null
        yum makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} EPEL源设置完成!"${END}
    }
    
    set_epel_3_centos7(){
        cat > /etc/yum.repos.d/epel.repo <<-EOF
    [epel]
    name=epel
    baseurl=https://${URL}/fedora/epel/\$releasever/\$basearch/
    gpgcheck=1
    gpgkey=https://${URL}/fedora/epel/RPM-GPG-KEY-EPEL-\$releasever
    EOF
        ${COLOR}"更新镜像源中,请稍等..."${END}
        yum clean all &> /dev/null
        yum makecache &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} EPEL源设置完成!"${END}
    }
    
    rocky9_base_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)阿里镜像源
    2)网易镜像源
    3)搜狐镜像源
    4)南京大学镜像源
    5)中科大镜像源
    6)上海交通大学镜像源
    7)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-7): " NUM
            case ${NUM} in
            1)
                aliyun
                set_yum_rocky9_2
                ;;
            2)
                netease
                set_yum_rocky9
                ;;
            3)
                sohu
                set_yum_rocky9
                ;;
            4)
                nju
                set_yum_rocky9
                ;;
            5)
                ustc
                set_yum_rocky9
                ;;
            6)
                sjtu
                set_yum_rocky9
                ;;
            7)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-7)!"${END}
                ;;
            esac
        done
    }
    
    rocky8_base_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)阿里镜像源
    2)网易镜像源
    3)搜狐镜像源
    4)南京大学镜像源
    5)中科大镜像源
    6)上海交通大学镜像源
    7)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-7): " NUM
            case ${NUM} in
            1)
                aliyun
                set_yum_rocky8_2
                ;;
            2)
                netease
                set_yum_rocky8
                ;;
            3)
                sohu
                set_yum_rocky8
                ;;
            4)
                nju
                set_yum_rocky8
                ;;
            5)
                ustc
                set_yum_rocky8
                ;;
            6)
                sjtu
                set_yum_rocky8
                ;;
            7)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-7)!"${END}
                ;;
            esac
        done
    }
    
    centos_stream9_base_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)阿里镜像源
    2)清华镜像源
    3)南京大学镜像源
    4)中科大镜像源
    5)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-5): " NUM
            case ${NUM} in
            1)
                aliyun
                set_yum_centos_stream9
                ;;
            2)
                tuna
                set_yum_centos_stream9
                ;;
            3)
                nju
                set_yum_centos_stream9
                ;;
            4)
                ustc
                set_yum_centos_stream9
                ;;
            5)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-5)!"${END}
                ;;
            esac
        done
    }
    
    centos_stream8_base_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)阿里镜像源
    2)华为镜像源
    3)腾讯镜像源
    4)清华镜像源
    5)网易镜像源
    6)南京大学镜像源
    7)中科大镜像源
    8)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-8): " NUM
            case ${NUM} in
            1)
                aliyun
                set_yum_centos_stream8
                ;;
            2)
                huawei
                set_yum_centos_stream8
                ;;
            3)
                tencent
                set_yum_centos_stream8
                ;;
            4)
                tuna
                set_yum_centos_stream8
                ;;
            5)
                netease
                set_yum_centos_stream8
                ;;
            6)
                nju
                set_yum_centos_stream8
                ;;
            7)
                ustc
                set_yum_centos_stream8
                ;;
            8)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-8)!"${END}
                ;;
            esac
        done
    }
    
    centos7_base_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)阿里镜像源
    2)华为镜像源
    3)腾讯镜像源
    4)清华镜像源
    5)网易镜像源
    6)南京大学镜像源
    7)中科大镜像源
    8)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-8): " NUM
            case ${NUM} in
            1)
                aliyun
                set_yum_centos7
                ;;
            2)
                huawei
                set_yum_centos7
                ;;
            3)
                tencent
                set_yum_centos7
                ;;
            4)
                tuna
                set_yum_centos7
                ;;
            5)
                netease
                set_yum_centos7
                ;;
            6)
                nju
                set_yum_centos7
                ;;
            7)
                ustc
                set_yum_centos7
                ;;
            8)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-8)!"${END}
                ;;
            esac
        done
    }
    
    rocky_centos8_9_epel_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)阿里镜像源
    2)华为镜像源
    3)腾讯镜像源
    4)清华镜像源
    5)搜狐镜像源
    6)南京大学镜像源
    7)中科大镜像源
    8)上海交通大学镜像源
    9)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-9): " NUM
            case ${NUM} in
            1)
                aliyun
                set_epel_rocky_centos8_9
                ;;
            2)
                huawei
                set_epel_rocky_centos8_9
                ;;
            3)
                tencent
                set_epel_rocky_centos8_9
                ;;
            4)
                tuna
                set_epel_rocky_centos8_9
                ;;
            5)
                sohu
                set_epel_2_rocky_centos8_9
                ;;
            6)
                nju
                set_epel_rocky_centos8_9
                ;;
            7)
                ustc
                set_epel_rocky_centos8_9
                ;;
            8)
                sjtu
                set_epel_3_rocky_centos8_9
                ;;
            9)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-9)!"${END}
                ;;
            esac
        done
    }
    
    centos7_epel_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)阿里镜像源
    2)华为镜像源
    3)腾讯镜像源
    4)清华镜像源
    5)搜狐镜像源
    6)南京大学镜像源
    7)中科大镜像源
    8)上海交通大学镜像源
    9)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-9): " NUM
            case ${NUM} in
            1)
                aliyun
                set_epel_centos7
                ;;
            2)
                huawei
                set_epel_centos7
                ;;
            3)
                tencent
                set_epel_centos7
                ;;
            4)
                tuna
                set_epel_centos7
                ;;
            5)
                sohu
                set_epel_2_centos7
                ;;
            6)
                nju
                set_epel_centos7
                ;;
            7)
                ustc
                set_epel_centos7
                ;;
            8)
                sjtu
                set_epel_3_centos7
                ;;
            9)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-9)!"${END}
                ;;
            esac
        done
    }
    
    rocky_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)base仓库
    2)epel仓库
    3)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-3): " NUM
            case ${NUM} in
            1)
                if [ ${OS_RELEASE_VERSION} == "8" ];then
                    rocky8_base_menu
                else
                    rocky9_base_menu
                fi
                ;;
            2)
                rocky_centos8_9_epel_menu
                ;;
            3)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-3)!"${END}
                ;;
            esac
        done
    }
    
    centos_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)base仓库
    2)epel仓库
    3)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-3): " NUM
            case ${NUM} in
            1)
                if [ ${OS_NAME} == "Stream" ];then
                    if [ ${OS_RELEASE_VERSION} == "8" ];then
                        centos_stream8_base_menu
                    else
                        centos_stream9_base_menu
                    fi
                else
                    centos7_base_menu
                fi
                ;;
            2)
                if [ ${OS_RELEASE_VERSION} == "8" -o ${OS_RELEASE_VERSION} == "9" ];then
                    rocky_centos8_9_epel_menu
                else
                    rocky_centos7_epel_menu
                fi
                ;;
            3)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-3)!"${END}
                ;;
            esac
        done
    }
    
    set_apt(){
        mv /etc/apt/sources.list /etc/apt/sources.list.bak
        cat > /etc/apt/sources.list <<-EOF
    deb http://${URL}/ubuntu/ $(lsb_release -cs) main restricted universe multiverse
    deb-src http://${URL}/ubuntu/ $(lsb_release -cs) main restricted universe multiverse
    
    deb http://${URL}/ubuntu/ $(lsb_release -cs)-security main restricted universe multiverse
    deb-src http://${URL}/ubuntu/ $(lsb_release -cs)-security main restricted universe multiverse
    
    deb http://${URL}/ubuntu/ $(lsb_release -cs)-updates main restricted universe multiverse
    deb-src http://${URL}/ubuntu/ $(lsb_release -cs)-updates main restricted universe multiverse
    
    deb http://${URL}/ubuntu/ $(lsb_release -cs)-proposed main restricted universe multiverse
    deb-src http://${URL}/ubuntu/ $(lsb_release -cs)-proposed main restricted universe multiverse
    
    deb http://${URL}/ubuntu/ $(lsb_release -cs)-backports main restricted universe multiverse
    deb-src http://${URL}/ubuntu/ $(lsb_release -cs)-backports main restricted universe multiverse
    EOF
        ${COLOR}"更新镜像源中,请稍等..."${END}
        apt update &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} APT源设置完成!"${END}
    }
    
    apt_menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)阿里镜像源
    2)华为镜像源
    3)腾讯镜像源
    4)清华镜像源
    5)网易镜像源
    6)南京大学镜像源
    7)中科大镜像源
    8)上海交通大学镜像源
    9)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入镜像源编号(1-9): " NUM
            case ${NUM} in
            1)
                aliyun
                set_apt
                ;;
            2)
                huawei
                set_apt
                ;;
            3)
                tencent
                set_apt
                ;;
            4)
                tuna
                set_apt
                ;;
            5)
                netease
                set_apt
                ;;
            6)
                nju
                set_apt
                ;;
            7)
                ustc
                set_apt
                ;;
            8)
                sjtu
                set_apt
                ;;
            9)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-9)!"${END}
                ;;
            esac
        done
    }
    
    set_mirror_repository(){
        if [ ${OS_ID} == "CentOS" ];then
            centos_menu
        elif [ ${OS_ID} == "Rocky" ];then
            rocky_menu
        else
            apt_menu
        fi
    }
    
    centos_minimal_install(){
        ${COLOR}'开始安装“Minimal安装建议安装软件包”,请稍等......'${END}
        yum -y install gcc make autoconf gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel vim lrzsz tree tmux lsof tcpdump wget net-tools iotop bc bzip2 zip unzip nfs-utils man-pages &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} Minimal安装建议安装软件包已安装完成!"${END}
    }
    
    ubuntu_minimal_install(){
        ${COLOR}'开始安装“Minimal安装建议安装软件包”,请稍等......'${END}
        apt -y install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev gcc openssh-server iotop unzip zip
        ${COLOR}"${OS_ID} ${OS_RELEASE} Minimal安装建议安装软件包已安装完成!"${END}
    }
    
    minimal_install(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ] &> /dev/null;then
            centos_minimal_install
        else
            ubuntu_minimal_install
        fi
    }
    
    set_mail(){                                                                                                 
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            rpm -q postfix &> /dev/null || { yum -y install postfix &> /dev/null; systemctl enable --now postfix &> /dev/null; }
            rpm -q mailx &> /dev/null || yum -y install mailx &> /dev/null
        else
            dpkg -s mailutils &> /dev/null || apt -y install mailutils
        fi
        read -p "请输入邮箱地址: " MAIL
        read -p "请输入邮箱授权码: " AUTH
        SMTP=`echo ${MAIL} |awk -F"@" '{print $2}'`
        cat >~/.mailrc <<-EOF
    set from=${MAIL}
    set smtp=smtp.${SMTP}
    set smtp-auth-user=${MAIL}
    set smtp-auth-password=${AUTH}
    set smtp-auth=login
    set ssl-verify=ignore
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} 邮件设置完成,请重新登录后才能生效!"${END}
    }
    
    set_sshd_port(){
        disable_selinux
        disable_firewall
        read -p "请输入端口号: " PORT
        sed -i 's/#Port 22/Port '${PORT}'/' /etc/ssh/sshd_config
        ${COLOR}"${OS_ID} ${OS_RELEASE} 更改SSH端口号已完成,请重启系统后生效!"${END}
    }
    
    set_centos_eth(){
        ETHNAME=`ip addr | awk -F"[ :]" '/^2/{print $3}'`
        #修改网卡名称配置文件
    	if grep -Eqi "(net\.ifnames|biosdevname)" /etc/default/grub;then
            ${COLOR}"${OS_ID} ${OS_RELEASE} 网卡名配置文件已修改,不用修改!"${END}
        else
            sed -ri.bak '/^GRUB_CMDLINE_LINUX=/s@"$@ net.ifnames=0 biosdevname=0"@' /etc/default/grub
            grub2-mkconfig -o /boot/grub2/grub.cfg >& /dev/null
        fi
    
        #修改网卡文件名
        if [ ${OS_RELEASE_VERSION} == "7" -o ${OS_RELEASE_VERSION} == "8" ];then
            mv /etc/sysconfig/network-scripts/ifcfg-${ETHNAME} /etc/sysconfig/network-scripts/ifcfg-eth0
        else
            mv /etc/NetworkManager/system-connections/${ETHNAME}.nmconnection /etc/NetworkManager/system-connections/eth0.nmconnection
        fi
        ${COLOR}"${OS_ID} ${OS_RELEASE} 网卡名已修改成功,请重新启动系统后才能生效!"${END}
    }
    
    set_ubuntu_eth(){
        #修改网卡名称配置文件
    	if grep -Eqi "(net\.ifnames|biosdevname)" /etc/default/grub;then
            ${COLOR}"${OS_ID} ${OS_RELEASE} 网卡名配置文件已修改,不用修改!"${END}
        else
            sed -ri.bak '/^GRUB_CMDLINE_LINUX=/s@"$@net.ifnames=0 biosdevname=0"@' /etc/default/grub
            grub-mkconfig -o /boot/grub/grub.cfg >& /dev/null
            ${COLOR}"${OS_ID} ${OS_RELEASE} 网卡名已修改成功,请重新启动系统后才能生效!"${END}
        fi
    }
    
    set_eth(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            set_centos_eth
        else
            set_ubuntu_eth
        fi
    }
    
    check_ip(){
        local IP=$1
        VALID_CHECK=$(echo ${IP}|awk -F. '$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}')
        if echo ${IP}|grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >/dev/null; then
            if [ ${VALID_CHECK} == "yes" ]; then
                echo "IP ${IP}  available!"
                return 0
            else
                echo "IP ${IP} not available!"
                return 1
            fi
        else
            echo "IP format error!"
            return 1
        fi
    }
    
    set_centos_ip(){
        while true; do
            read -p "请输入IP地址: " IP
            check_ip ${IP}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " C_PREFIX
        while true; do
            read -p "请输入网关地址: " GATEWAY
            check_ip ${GATEWAY}
            [ $? -eq 0 ] && break
        done
        cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<-EOF
    NAME=eth0
    DEVICE=eth0
    ONBOOT=yes
    BOOTPROTO=none
    TYPE=Ethernet
    IPADDR=${IP}
    PREFIX=${C_PREFIX}
    GATEWAY=${GATEWAY}
    DNS1=223.5.5.5
    DNS2=180.76.76.76
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} IP地址、网关地址和DNS已修改成功,请重新启动系统后生效!"${END}
    }
    
    set_centos_9_ip(){
        while true; do
            read -p "请输入IP地址: " IP
            check_ip ${IP}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " C_PREFIX
        while true; do
            read -p "请输入网关地址: " GATEWAY
            check_ip ${GATEWAY}
            [ $? -eq 0 ] && break
        done
        cat > /etc/NetworkManager/system-connections/eth0.nmconnection <<-EOF
    [connection]
    id=eth0
    type=ethernet
    interface-name=eth0
    
    [ethernet]
    
    [ipv4]
    address1=${IP}/${C_PREFIX},${GATEWAY}
    dns=223.5.5.5;180.76.76.76;
    method=manual
    
    [ipv6]
    addr-gen-mode=default
    method=auto
    
    [proxy]
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} IP地址、网关地址和DNS已修改成功,请重新启动系统后生效!"${END}
    }
    
    set_ubuntu_ip(){
        while true; do
            read -p "请输入IP地址: " IP
            check_ip ${IP}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " U_PREFIX
        while true; do
            read -p "请输入网关地址: " GATEWAY
            check_ip ${GATEWAY}
            [ $? -eq 0 ] && break
        done
        cat > /etc/netplan/01-netcfg.yaml <<-EOF
    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0:
          dhcp4: no
          dhcp6: no
          addresses: [${IP}/${U_PREFIX}] 
          gateway4: ${GATEWAY}
          nameservers:
            addresses: [223.5.5.5, 180.76.76.76]
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} IP地址、网关地址和DNS已修改成功,请重新启动系统后生效!"${END}
    }
    
    set_ubuntu_22_ip(){
        while true; do
            read -p "请输入IP地址: " IP
            check_ip ${IP}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " U_PREFIX
        while true; do
            read -p "请输入网关地址: " GATEWAY
            check_ip ${GATEWAY}
            [ $? -eq 0 ] && break
        done
        cat > /etc/netplan/00-installer-config.yaml <<-EOF
    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0:
          dhcp4: no
          dhcp6: no
          addresses: [${IP}/${U_PREFIX}]
          routes:
            - to: default
              via: ${GATEWAY}
          nameservers:
            addresses: [223.5.5.5, 180.76.76.76]
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} IP地址、网关地址和DNS已修改成功,请重新启动系统后生效!"${END}
    }
    
    set_ip(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            if [ ${OS_RELEASE_VERSION} == "7" -o ${OS_RELEASE_VERSION} == "8" ];then
                set_centos_ip
            else
                set_centos_9_ip
            fi
        elif [ ${OS_RELEASE_VERSION} == "18" -o ${OS_RELEASE_VERSION} == "20" ];then
            set_dual_ubuntu_ip 
        else
            set_dual_ubuntu_22_ip
        fi
    }
    
    set_dual_centos_ip(){
        while true; do
            read -p "请输入第一块网卡IP地址: " IP
            check_ip ${IP}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " C_PREFIX
        while true; do
            read -p "请输入网关地址: " GATEWAY
            check_ip ${GATEWAY}
            [ $? -eq 0 ] && break
        done
        cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<-EOF
    NAME=eth0
    DEVICE=eth0
    ONBOOT=yes
    BOOTPROTO=none
    TYPE=Ethernet
    IPADDR=${IP}
    PREFIX=${C_PREFIX}
    GATEWAY=${GATEWAY}
    DNS1=223.5.5.5
    DNS2=180.76.76.76
    EOF
        while true; do
            read -p "请输入第二块网卡IP地址: " IP2
            check_ip ${IP2}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " C_PREFIX2
        cat > /etc/sysconfig/network-scripts/ifcfg-eth1 <<-EOF
    NAME=eth1
    DEVICE=eth1
    ONBOOT=yes
    BOOTPROTO=none
    TYPE=Ethernet
    IPADDR=${IP2}
    PREFIX=${C_PREFIX2}
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} IP地址、网关地址和DNS已修改成功,请重新启动系统后生效!"${END}
    }
    
    set_dual_centos_9_ip(){
        while true; do
            read -p "请输入第一块网卡IP地址: " IP
            check_ip ${IP}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " C_PREFIX
        while true; do
            read -p "请输入网关地址: " GATEWAY
            check_ip ${GATEWAY}
            [ $? -eq 0 ] && break
        done
        cat > /etc/NetworkManager/system-connections/eth0.nmconnection <<-EOF
    [connection]
    id=eth0
    type=ethernet
    interface-name=eth0
    
    [ethernet]
    
    [ipv4]
    address1=${IP}/${C_PREFIX},${GATEWAY}
    dns=223.5.5.5;180.76.76.76;
    method=manual
    
    [ipv6]
    addr-gen-mode=default
    method=auto
    
    [proxy]
    EOF
        while true; do
            read -p "请输入第二块网卡IP地址: " IP2
            check_ip ${IP2}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " C_PREFIX2
        cat > /etc/NetworkManager/system-connections/eth1.nmconnection <<-EOF
    [connection]
    id=eth1
    type=ethernet
    interface-name=eth1
    
    [ethernet]
    
    [ipv4]
    address1=${IP2}/${C_PREFIX2}
    method=manual
    
    [ipv6]
    addr-gen-mode=default
    method=auto
    
    [proxy]
    EOF
        chmod 600 /etc/NetworkManager/system-connections/eth1.nmconnection
        ${COLOR}"${OS_ID} ${OS_RELEASE} IP地址、网关地址和DNS已修改成功,请重新启动系统后生效!"${END}
    }
    
    set_dual_ubuntu_ip(){
        while true; do
            read -p "请输入第一块网卡IP地址: " IP
            check_ip ${IP}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " U_PREFIX
        while true; do
            read -p "请输入网关地址: " GATEWAY
            check_ip ${GATEWAY}
            [ $? -eq 0 ] && break
        done
        while true; do
            read -p "请输入第二块网卡IP地址: " IP2
            check_ip ${IP2}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " U_PREFIX2
        cat > /etc/netplan/01-netcfg.yaml <<-EOF
    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0:
          dhcp4: no
          dhcp6: no
          addresses: [${IP}/${U_PREFIX}] 
          gateway4: ${GATEWAY}
          nameservers:
            addresses: [223.5.5.5, 180.76.76.76]
        eth1:
          dhcp4: no
          dhcp6: no
          addresses: [${IP2}/${U_PREFIX2}] 
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} IP地址、网关地址和DNS已修改成功,请重新启动系统后生效!"${END}
    }
    
    set_dual_ubuntu_22_ip(){
        while true; do
            read -p "请输入第一块网卡IP地址: " IP
            check_ip ${IP}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " U_PREFIX
        while true; do
            read -p "请输入网关地址: " GATEWAY
            check_ip ${GATEWAY}
            [ $? -eq 0 ] && break
        done
        while true; do
            read -p "请输入第二块网卡IP地址: " IP2
            check_ip ${IP2}
            [ $? -eq 0 ] && break
        done
        read -p "请输入子网掩码位数: " U_PREFIX2
        cat > /etc/netplan/00-installer-config.yaml <<-EOF
    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0:
          dhcp4: no
          dhcp6: no
          addresses: [${IP}/${U_PREFIX}] 
          routes:
            - to: default
              via: ${GATEWAY}
          nameservers:
            addresses: [223.5.5.5, 180.76.76.76]
        eth1:
          dhcp4: no
          dhcp6: no
          addresses: [${IP2}/${U_PREFIX2}] 
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} IP地址、网关地址和DNS已修改成功,请重新启动系统后生效!"${END}
    }
    
    set_dual_ip(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            if [ ${OS_RELEASE_VERSION} == "7" -o ${OS_RELEASE_VERSION} == "8" ];then
                set_dual_centos_ip
            else
                set_dual_centos_9_ip
            fi
        elif [ ${OS_RELEASE_VERSION} == "18" -o ${OS_RELEASE_VERSION} == "20" ];then
            set_dual_ubuntu_ip 
        else
            set_dual_ubuntu_22_ip
        fi
    }
    
    set_hostname(){
        read -p "请输入主机名: " HOST
        hostnamectl set-hostname ${HOST}
        ${COLOR}"${OS_ID} ${OS_RELEASE} 主机名设置成功,请重新登录生效!"${END}
    }
    
    red(){
        P_COLOR=31
    }
    
    green(){
        P_COLOR=32
    }
    
    yellow(){
        P_COLOR=33
    }
    
    blue(){
        P_COLOR=34
    }
    
    violet(){
        P_COLOR=35
    }
    
    cyan_blue(){
        P_COLOR=36
    }
    
    random_color(){
        P_COLOR="$[RANDOM%7+31]"
    }
    
    centos_ps1(){
        C_PS1=$(echo "PS1='\[\e[1;${P_COLOR}m\][\u@\h \W]\\$ \[\e[0m\]'" >> ~/.bashrc)
    }
    
    ubuntu_ps1(){
        U_PS1=$(echo 'PS1="\[\e[1;'''${P_COLOR}'''m\]${debian_chroot:+($debian_chroot)}\u@\h:\w\\$ \[\e[0m\]"' >> ~/.bashrc)
    }
    
    set_ps1_env(){
        if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ];then
            if grep -Eqi "^PS1" ~/.bashrc;then
                sed -i '/^PS1/d' ~/.bashrc
                centos_ps1
            else
                centos_ps1
            fi
        fi
        if [ ${OS_ID} == "Ubuntu" ];then
            if grep -Eqi "^PS1" ~/.bashrc;then
                sed -i '/^PS1/d' ~/.bashrc
                ubuntu_ps1
            else
                ubuntu_ps1
            fi
        fi
    }
    
    set_ps1(){
        TIPS="${COLOR}${OS_ID} ${OS_RELEASE} PS1设置成功,请重新登录生效!${END}"
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    1)31 红色
    2)32 绿色
    3)33 黄色
    4)34 蓝色
    5)35 紫色
    6)36 青色
    7)随机颜色
    8)退出
    EOF
            echo -e '\E[0m'
    
            read -p "请输入颜色编号(1-8): " NUM
            case ${NUM} in
            1)
                red
                set_ps1_env
                ${TIPS}
                ;;
            2)
                green
                set_ps1_env
                ${TIPS}
                ;;
            3)
                yellow
                set_ps1_env
                ${TIPS}
                ;;
            4)
                blue
                set_ps1_env
                ${TIPS}
                ;;
            5)
                violet
                set_ps1_env
                ${TIPS}
                ;;
            6)
                cyan_blue
                set_ps1_env
                ${TIPS}
                ;;
            7)
                random_color
                set_ps1_env
                ${TIPS}
                ;;
            8)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-8)!"${END}
                ;;
            esac
        done
    }
    
    set_vim(){
        echo "export EDITOR=vim" >> ~/.bashrc
    }
    
    set_vim_env(){
        if grep -Eqi ".*EDITOR" ~/.bashrc;then
            sed -i '/.*EDITOR/d' ~/.bashrc
            set_vim
        else
            set_vim
        fi
        ${COLOR}"${OS_ID} ${OS_RELEASE} 默认文本编辑器设置成功,请重新登录生效!"${END}
    }
    
    set_history(){
        echo 'export HISTTIMEFORMAT="%F %T "' >> ~/.bashrc 
    }
    
    set_history_env(){
        if grep -Eqi ".*HISTTIMEFORMAT" ~/.bashrc;then
            sed -i '/.*HISTTIMEFORMAT/d' ~/.bashrc
            set_history
        else
            set_history
        fi
        ${COLOR}"${OS_ID} ${OS_RELEASE} history格式设置成功,请重新登录生效!"${END}
    }
    
    set_swap(){
        sed -ri 's/.*swap.*/#&/' /etc/fstab
        if [ ${OS_ID} == "Ubuntu" ];then
            if [ ${OS_RELEASE_VERSION} == 20 -o ${OS_RELEASE_VERSION} == 22 ];then
                SD_NAME=`lsblk|awk -F"[ └─]" '/SWAP/{printf $3}'`
                systemctl mask dev-${SD_NAME}.swap &> /dev/null
            fi
        fi
        swapoff -a
        ${COLOR}"${OS_ID} ${OS_RELEASE} 禁用swap成功!"${END}
    }
    
    set_kernel(){
        cat > /etc/sysctl.conf <<-EOF
    # Controls source route verification
    net.ipv4.conf.default.rp_filter = 1
    net.ipv4.ip_nonlocal_bind = 1
    net.ipv4.ip_forward = 1
    
    # Do not accept source routing
    net.ipv4.conf.default.accept_source_route = 0
    
    # Controls the System Request debugging functionality of the kernel
    kernel.sysrq = 0
    
    # Controls whether core dumps will append the PID to the core filename.
    # Useful for debugging multi-threaded applications.
    kernel.core_uses_pid = 1
    
    # Controls the use of TCP syncookies
    net.ipv4.tcp_syncookies = 1
    
    # Disable netfilter on bridges.
    net.bridge.bridge-nf-call-ip6tables = 0
    net.bridge.bridge-nf-call-iptables = 0
    net.bridge.bridge-nf-call-arptables = 0
    
    # Controls the default maxmimum size of a mesage queue
    kernel.msgmnb = 65536
    
    # Controls the maximum size of a message, in bytes
    kernel.msgmax = 65536
    
    # Controls the maximum shared segment size, in bytes
    kernel.shmmax = 68719476736
    
    # Controls the maximum number of shared memory segments, in pages
    kernel.shmall = 4294967296
    
    # TCP kernel paramater
    net.ipv4.tcp_mem = 786432 1048576 1572864
    net.ipv4.tcp_rmem = 4096        87380   4194304
    net.ipv4.tcp_wmem = 4096        16384   4194304
    net.ipv4.tcp_window_scaling = 1
    net.ipv4.tcp_sack = 1
    
    # socket buffer
    net.core.wmem_default = 8388608
    net.core.rmem_default = 8388608
    net.core.rmem_max = 16777216
    net.core.wmem_max = 16777216
    net.core.netdev_max_backlog = 262144
    net.core.somaxconn = 20480
    net.core.optmem_max = 81920
    
    # TCP conn
    net.ipv4.tcp_max_syn_backlog = 262144
    net.ipv4.tcp_syn_retries = 3
    net.ipv4.tcp_retries1 = 3
    net.ipv4.tcp_retries2 = 15
    
    # tcp conn reuse
    net.ipv4.tcp_tw_reuse = 1
    net.ipv4.tcp_tw_recycle = 0
    net.ipv4.tcp_fin_timeout = 30
    net.ipv4.tcp_timestamps = 0
    
    net.ipv4.tcp_max_tw_buckets = 20000
    net.ipv4.tcp_max_orphans = 3276800
    net.ipv4.tcp_synack_retries = 1
    net.ipv4.tcp_syncookies = 1
    
    # keepalive conn
    net.ipv4.tcp_keepalive_time = 300
    net.ipv4.tcp_keepalive_intvl = 30
    net.ipv4.tcp_keepalive_probes = 3
    net.ipv4.ip_local_port_range = 10001    65000
    
    # swap
    vm.overcommit_memory = 0
    vm.swappiness = 10
    
    #net.ipv4.conf.eth1.rp_filter = 0
    #net.ipv4.conf.lo.arp_ignore = 1
    #net.ipv4.conf.lo.arp_announce = 2
    #net.ipv4.conf.all.arp_ignore = 1
    #net.ipv4.conf.all.arp_announce = 2
    EOF
        sysctl -p &> /dev/null
        ${COLOR}"${OS_ID} ${OS_RELEASE} 优化内核参数成功!"${END}
    }
    
    set_limits(){
        cat >> /etc/security/limits.conf <<-EOF
    root     soft   core     unlimited
    root     hard   core     unlimited
    root     soft   nproc    1000000
    root     hard   nproc    1000000
    root     soft   nofile   1000000
    root     hard   nofile   1000000
    root     soft   memlock  32000
    root     hard   memlock  32000
    root     soft   msgqueue 8192000
    root     hard   msgqueue 8192000
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} 优化资源限制参数成功!"${END}
    }
    
    set_localtime(){
        ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
        echo 'Asia/Shanghai' >/etc/timezone
        if [ ${OS_ID} == "Ubuntu" ];then
            cat >> /etc/default/locale <<-EOF
    LC_TIME=en_DK.UTF-8
    EOF
        fi
        ${COLOR}"${OS_ID} ${OS_RELEASE} 系统时区已设置成功,请重启系统后生效!"${END}
    }
    
    disable_restart(){
        if [ -f /usr/lib/systemd/system/ctrl-alt-del.target ];then
            cp /usr/lib/systemd/system/ctrl-alt-del.target{,.bak}
            rm -f /usr/lib/systemd/system/ctrl-alt-del.target
            ${COLOR}"${OS_ID} ${OS_RELEASE} 禁用ctrl+alt+del重启处理成功!"${END}
        else
            ${COLOR}"${OS_ID} ${OS_RELEASE} 禁用ctrl+alt+del已处理!"${END}
        fi
    }
    
    set_root_login(){
        read -p "请输入密码: " PASSWORD
        echo ${PASSWORD} |sudo -S sed -ri 's@#(PermitRootLogin )prohibit-password@\1yes@' /etc/ssh/sshd_config
        sudo systemctl restart sshd
        sudo -S passwd root <<-EOF
    ${PASSWORD}
    ${PASSWORD}
    EOF
        ${COLOR}"${OS_ID} ${OS_RELEASE} root用户登录已设置完成,请重新登录后生效!"${END}
    }
    
    ubuntu_remove(){
        apt purge ufw lxd lxd-client lxcfs liblxc-common
        ${COLOR}"${OS_ID} ${OS_RELEASE} 无用软件包卸载完成!"${END}
    }
    
    menu(){
        while true;do
            echo -e "\E[$[RANDOM%7+31];1m"
            cat <<-EOF
    ********************************************************************
    *                           初始化脚本菜单                         *
    * 1.禁用SELinux                    15.设置PS1(请进入选择颜色)      *
    * 2.关闭防火墙                     16.设置默认文本编辑器为vim      *
    * 3.优化SSH                        17.设置history格式              *
    * 4.设置系统别名                   18.禁用SWAP                     *
    * 5.1-4全设置                      19.优化内核参数                 *
    * 6.设置vimrc配置文件              20.优化资源限制参数             *
    * 7.设置镜像仓库                   21.设置系统时区                 *
    * 8.Minimal安装建议安装软件        22.禁用ctrl+alt+del重启         *
    * 9.安装邮件服务并配置邮件         23.Ubuntu设置root用户登录       *
    * 10.更改SSH端口号                 24.Ubuntu卸载无用软件包         *
    * 11.修改网卡名                    25.重启系统                     *
    * 12.修改IP地址和网关地址(单网卡)  26.关机                         *
    * 13.修改IP地址和网关地址(双网卡)  27.退出                         *
    * 14.设置主机名                                                    *
    ********************************************************************
    EOF
            echo -e '\E[0m'
    
            read -p "请选择相应的编号(1-27): " choice
            case ${choice} in
            1)
                disable_selinux
                ;;
            2)
                disable_firewall
                ;;
            3)
                optimization_sshd
                ;;
            4)
                set_alias
                ;;
            5)
                disable_selinux
                disable_firewall
                optimization_sshd
                set_alias
                ;;
            6)
                set_vimrc
                ;;
            7)
                set_mirror_repository
                ;;
            8)
                minimal_install
                ;;
            9)
                set_mail
                ;;
            10)
                set_sshd_port
                ;;
            11)
                set_eth
                ;;
            12)
                set_ip
                ;;
            13)
                set_dual_ip
                ;;
            14)
                set_hostname
                ;;
            15)
                set_ps1
                ;;
            16)
                set_vim_env
                ;;
            17)
                set_history_env
                ;;
            18)
                set_swap
                ;;
            19)
                set_kernel
                ;;
            20)
                set_limits
                ;;
            21)
                set_localtime
                ;;
            22)
                disable_restart
                ;;
            23)
                set_root_login
                ;;
            24)
                ubuntu_remove
                ;;
            25)
                reboot
                ;;
            26)
                shutdown -h now
                ;;
            27)
                break
                ;;
            *)
                ${COLOR}"输入错误,请输入正确的数字(1-27)!"${END}
                ;;
            esac
        done
    }
    
    main(){
        os
        menu
    }
    
    main
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    • 450
    • 451
    • 452
    • 453
    • 454
    • 455
    • 456
    • 457
    • 458
    • 459
    • 460
    • 461
    • 462
    • 463
    • 464
    • 465
    • 466
    • 467
    • 468
    • 469
    • 470
    • 471
    • 472
    • 473
    • 474
    • 475
    • 476
    • 477
    • 478
    • 479
    • 480
    • 481
    • 482
    • 483
    • 484
    • 485
    • 486
    • 487
    • 488
    • 489
    • 490
    • 491
    • 492
    • 493
    • 494
    • 495
    • 496
    • 497
    • 498
    • 499
    • 500
    • 501
    • 502
    • 503
    • 504
    • 505
    • 506
    • 507
    • 508
    • 509
    • 510
    • 511
    • 512
    • 513
    • 514
    • 515
    • 516
    • 517
    • 518
    • 519
    • 520
    • 521
    • 522
    • 523
    • 524
    • 525
    • 526
    • 527
    • 528
    • 529
    • 530
    • 531
    • 532
    • 533
    • 534
    • 535
    • 536
    • 537
    • 538
    • 539
    • 540
    • 541
    • 542
    • 543
    • 544
    • 545
    • 546
    • 547
    • 548
    • 549
    • 550
    • 551
    • 552
    • 553
    • 554
    • 555
    • 556
    • 557
    • 558
    • 559
    • 560
    • 561
    • 562
    • 563
    • 564
    • 565
    • 566
    • 567
    • 568
    • 569
    • 570
    • 571
    • 572
    • 573
    • 574
    • 575
    • 576
    • 577
    • 578
    • 579
    • 580
    • 581
    • 582
    • 583
    • 584
    • 585
    • 586
    • 587
    • 588
    • 589
    • 590
    • 591
    • 592
    • 593
    • 594
    • 595
    • 596
    • 597
    • 598
    • 599
    • 600
    • 601
    • 602
    • 603
    • 604
    • 605
    • 606
    • 607
    • 608
    • 609
    • 610
    • 611
    • 612
    • 613
    • 614
    • 615
    • 616
    • 617
    • 618
    • 619
    • 620
    • 621
    • 622
    • 623
    • 624
    • 625
    • 626
    • 627
    • 628
    • 629
    • 630
    • 631
    • 632
    • 633
    • 634
    • 635
    • 636
    • 637
    • 638
    • 639
    • 640
    • 641
    • 642
    • 643
    • 644
    • 645
    • 646
    • 647
    • 648
    • 649
    • 650
    • 651
    • 652
    • 653
    • 654
    • 655
    • 656
    • 657
    • 658
    • 659
    • 660
    • 661
    • 662
    • 663
    • 664
    • 665
    • 666
    • 667
    • 668
    • 669
    • 670
    • 671
    • 672
    • 673
    • 674
    • 675
    • 676
    • 677
    • 678
    • 679
    • 680
    • 681
    • 682
    • 683
    • 684
    • 685
    • 686
    • 687
    • 688
    • 689
    • 690
    • 691
    • 692
    • 693
    • 694
    • 695
    • 696
    • 697
    • 698
    • 699
    • 700
    • 701
    • 702
    • 703
    • 704
    • 705
    • 706
    • 707
    • 708
    • 709
    • 710
    • 711
    • 712
    • 713
    • 714
    • 715
    • 716
    • 717
    • 718
    • 719
    • 720
    • 721
    • 722
    • 723
    • 724
    • 725
    • 726
    • 727
    • 728
    • 729
    • 730
    • 731
    • 732
    • 733
    • 734
    • 735
    • 736
    • 737
    • 738
    • 739
    • 740
    • 741
    • 742
    • 743
    • 744
    • 745
    • 746
    • 747
    • 748
    • 749
    • 750
    • 751
    • 752
    • 753
    • 754
    • 755
    • 756
    • 757
    • 758
    • 759
    • 760
    • 761
    • 762
    • 763
    • 764
    • 765
    • 766
    • 767
    • 768
    • 769
    • 770
    • 771
    • 772
    • 773
    • 774
    • 775
    • 776
    • 777
    • 778
    • 779
    • 780
    • 781
    • 782
    • 783
    • 784
    • 785
    • 786
    • 787
    • 788
    • 789
    • 790
    • 791
    • 792
    • 793
    • 794
    • 795
    • 796
    • 797
    • 798
    • 799
    • 800
    • 801
    • 802
    • 803
    • 804
    • 805
    • 806
    • 807
    • 808
    • 809
    • 810
    • 811
    • 812
    • 813
    • 814
    • 815
    • 816
    • 817
    • 818
    • 819
    • 820
    • 821
    • 822
    • 823
    • 824
    • 825
    • 826
    • 827
    • 828
    • 829
    • 830
    • 831
    • 832
    • 833
    • 834
    • 835
    • 836
    • 837
    • 838
    • 839
    • 840
    • 841
    • 842
    • 843
    • 844
    • 845
    • 846
    • 847
    • 848
    • 849
    • 850
    • 851
    • 852
    • 853
    • 854
    • 855
    • 856
    • 857
    • 858
    • 859
    • 860
    • 861
    • 862
    • 863
    • 864
    • 865
    • 866
    • 867
    • 868
    • 869
    • 870
    • 871
    • 872
    • 873
    • 874
    • 875
    • 876
    • 877
    • 878
    • 879
    • 880
    • 881
    • 882
    • 883
    • 884
    • 885
    • 886
    • 887
    • 888
    • 889
    • 890
    • 891
    • 892
    • 893
    • 894
    • 895
    • 896
    • 897
    • 898
    • 899
    • 900
    • 901
    • 902
    • 903
    • 904
    • 905
    • 906
    • 907
    • 908
    • 909
    • 910
    • 911
    • 912
    • 913
    • 914
    • 915
    • 916
    • 917
    • 918
    • 919
    • 920
    • 921
    • 922
    • 923
    • 924
    • 925
    • 926
    • 927
    • 928
    • 929
    • 930
    • 931
    • 932
    • 933
    • 934
    • 935
    • 936
    • 937
    • 938
    • 939
    • 940
    • 941
    • 942
    • 943
    • 944
    • 945
    • 946
    • 947
    • 948
    • 949
    • 950
    • 951
    • 952
    • 953
    • 954
    • 955
    • 956
    • 957
    • 958
    • 959
    • 960
    • 961
    • 962
    • 963
    • 964
    • 965
    • 966
    • 967
    • 968
    • 969
    • 970
    • 971
    • 972
    • 973
    • 974
    • 975
    • 976
    • 977
    • 978
    • 979
    • 980
    • 981
    • 982
    • 983
    • 984
    • 985
    • 986
    • 987
    • 988
    • 989
    • 990
    • 991
    • 992
    • 993
    • 994
    • 995
    • 996
    • 997
    • 998
    • 999
    • 1000
    • 1001
    • 1002
    • 1003
    • 1004
    • 1005
    • 1006
    • 1007
    • 1008
    • 1009
    • 1010
    • 1011
    • 1012
    • 1013
    • 1014
    • 1015
    • 1016
    • 1017
    • 1018
    • 1019
    • 1020
    • 1021
    • 1022
    • 1023
    • 1024
    • 1025
    • 1026
    • 1027
    • 1028
    • 1029
    • 1030
    • 1031
    • 1032
    • 1033
    • 1034
    • 1035
    • 1036
    • 1037
    • 1038
    • 1039
    • 1040
    • 1041
    • 1042
    • 1043
    • 1044
    • 1045
    • 1046
    • 1047
    • 1048
    • 1049
    • 1050
    • 1051
    • 1052
    • 1053
    • 1054
    • 1055
    • 1056
    • 1057
    • 1058
    • 1059
    • 1060
    • 1061
    • 1062
    • 1063
    • 1064
    • 1065
    • 1066
    • 1067
    • 1068
    • 1069
    • 1070
    • 1071
    • 1072
    • 1073
    • 1074
    • 1075
    • 1076
    • 1077
    • 1078
    • 1079
    • 1080
    • 1081
    • 1082
    • 1083
    • 1084
    • 1085
    • 1086
    • 1087
    • 1088
    • 1089
    • 1090
    • 1091
    • 1092
    • 1093
    • 1094
    • 1095
    • 1096
    • 1097
    • 1098
    • 1099
    • 1100
    • 1101
    • 1102
    • 1103
    • 1104
    • 1105
    • 1106
    • 1107
    • 1108
    • 1109
    • 1110
    • 1111
    • 1112
    • 1113
    • 1114
    • 1115
    • 1116
    • 1117
    • 1118
    • 1119
    • 1120
    • 1121
    • 1122
    • 1123
    • 1124
    • 1125
    • 1126
    • 1127
    • 1128
    • 1129
    • 1130
    • 1131
    • 1132
    • 1133
    • 1134
    • 1135
    • 1136
    • 1137
    • 1138
    • 1139
    • 1140
    • 1141
    • 1142
    • 1143
    • 1144
    • 1145
    • 1146
    • 1147
    • 1148
    • 1149
    • 1150
    • 1151
    • 1152
    • 1153
    • 1154
    • 1155
    • 1156
    • 1157
    • 1158
    • 1159
    • 1160
    • 1161
    • 1162
    • 1163
    • 1164
    • 1165
    • 1166
    • 1167
    • 1168
    • 1169
    • 1170
    • 1171
    • 1172
    • 1173
    • 1174
    • 1175
    • 1176
    • 1177
    • 1178
    • 1179
    • 1180
    • 1181
    • 1182
    • 1183
    • 1184
    • 1185
    • 1186
    • 1187
    • 1188
    • 1189
    • 1190
    • 1191
    • 1192
    • 1193
    • 1194
    • 1195
    • 1196
    • 1197
    • 1198
    • 1199
    • 1200
    • 1201
    • 1202
    • 1203
    • 1204
    • 1205
    • 1206
    • 1207
    • 1208
    • 1209
    • 1210
    • 1211
    • 1212
    • 1213
    • 1214
    • 1215
    • 1216
    • 1217
    • 1218
    • 1219
    • 1220
    • 1221
    • 1222
    • 1223
    • 1224
    • 1225
    • 1226
    • 1227
    • 1228
    • 1229
    • 1230
    • 1231
    • 1232
    • 1233
    • 1234
    • 1235
    • 1236
    • 1237
    • 1238
    • 1239
    • 1240
    • 1241
    • 1242
    • 1243
    • 1244
    • 1245
    • 1246
    • 1247
    • 1248
    • 1249
    • 1250
    • 1251
    • 1252
    • 1253
    • 1254
    • 1255
    • 1256
    • 1257
    • 1258
    • 1259
    • 1260
    • 1261
    • 1262
    • 1263
    • 1264
    • 1265
    • 1266
    • 1267
    • 1268
    • 1269
    • 1270
    • 1271
    • 1272
    • 1273
    • 1274
    • 1275
    • 1276
    • 1277
    • 1278
    • 1279
    • 1280
    • 1281
    • 1282
    • 1283
    • 1284
    • 1285
    • 1286
    • 1287
    • 1288
    • 1289
    • 1290
    • 1291
    • 1292
    • 1293
    • 1294
    • 1295
    • 1296
    • 1297
    • 1298
    • 1299
    • 1300
    • 1301
    • 1302
    • 1303
    • 1304
    • 1305
    • 1306
    • 1307
    • 1308
    • 1309
    • 1310
    • 1311
    • 1312
    • 1313
    • 1314
    • 1315
    • 1316
    • 1317
    • 1318
    • 1319
    • 1320
    • 1321
    • 1322
    • 1323
    • 1324
    • 1325
    • 1326
    • 1327
    • 1328
    • 1329
    • 1330
    • 1331
    • 1332
    • 1333
    • 1334
    • 1335
    • 1336
    • 1337
    • 1338
    • 1339
    • 1340
    • 1341
    • 1342
    • 1343
    • 1344
    • 1345
    • 1346
    • 1347
    • 1348
    • 1349
    • 1350
    • 1351
    • 1352
    • 1353
    • 1354
    • 1355
    • 1356
    • 1357
    • 1358
    • 1359
    • 1360
    • 1361
    • 1362
    • 1363
    • 1364
    • 1365
    • 1366
    • 1367
    • 1368
    • 1369
    • 1370
    • 1371
    • 1372
    • 1373
    • 1374
    • 1375
    • 1376
    • 1377
    • 1378
    • 1379
    • 1380
    • 1381
    • 1382
    • 1383
    • 1384
    • 1385
    • 1386
    • 1387
    • 1388
    • 1389
    • 1390
    • 1391
    • 1392
    • 1393
    • 1394
    • 1395
    • 1396
    • 1397
    • 1398
    • 1399
    • 1400
    • 1401
    • 1402
    • 1403
    • 1404
    • 1405
    • 1406
    • 1407
    • 1408
    • 1409
    • 1410
    • 1411
    • 1412
    • 1413
    • 1414
    • 1415
    • 1416
    • 1417
    • 1418
    • 1419
    • 1420
    • 1421
    • 1422
    • 1423
    • 1424
    • 1425
    • 1426
    • 1427
    • 1428
    • 1429
    • 1430
    • 1431
    • 1432
    • 1433
    • 1434
    • 1435
    • 1436
    • 1437
    • 1438
    • 1439
    • 1440
    • 1441
    • 1442
    • 1443
    • 1444
    • 1445
    • 1446
    • 1447
    • 1448
    • 1449
    • 1450
    • 1451
    • 1452
    • 1453
    • 1454
    • 1455
    • 1456
    • 1457
    • 1458
    • 1459
    • 1460
    • 1461
    • 1462
    • 1463
    • 1464
    • 1465
    • 1466
    • 1467
    • 1468
    • 1469
    • 1470
    • 1471
    • 1472
    • 1473
    • 1474
    • 1475
    • 1476
    • 1477
    • 1478
    • 1479
    • 1480
    • 1481
    • 1482
    • 1483
    • 1484
    • 1485
    • 1486
    • 1487
    • 1488
    • 1489
    • 1490
    • 1491
    • 1492
    • 1493
    • 1494
    • 1495
    • 1496
    • 1497
    • 1498
    • 1499
    • 1500
    • 1501
    • 1502
    • 1503
    • 1504
    • 1505
    • 1506
    • 1507
    • 1508
    • 1509
    • 1510
    • 1511
    • 1512
    • 1513
    • 1514
    • 1515
    • 1516
    • 1517
    • 1518
    • 1519
    • 1520
    • 1521
    • 1522
    • 1523
    • 1524
    • 1525
    • 1526
    • 1527
    • 1528
    • 1529
    • 1530
    • 1531
    • 1532
    • 1533
    • 1534
    • 1535
    • 1536
    • 1537
    • 1538
    • 1539
    • 1540
    • 1541
    • 1542
    • 1543
    • 1544
    • 1545
    • 1546
    • 1547
    • 1548
    • 1549
    • 1550
    • 1551
    • 1552
    • 1553
    • 1554
    • 1555
    • 1556
    • 1557
    • 1558
    • 1559
    • 1560
    • 1561
    • 1562
    • 1563
    • 1564
    • 1565
    • 1566
    • 1567
    • 1568
    • 1569
    • 1570
    • 1571
    • 1572
    • 1573
    • 1574
    • 1575
    • 1576
    • 1577
    • 1578
    • 1579
    • 1580
    • 1581
    • 1582
    • 1583
    • 1584
    • 1585
    • 1586
    • 1587
    • 1588
    • 1589
    • 1590
    • 1591
    • 1592
    • 1593
    • 1594
    • 1595
    • 1596
    • 1597
    • 1598
    • 1599
    • 1600
    • 1601
    • 1602
    • 1603
    • 1604
    • 1605
    • 1606
    • 1607
    • 1608
    • 1609
    • 1610
    • 1611
    • 1612
    • 1613
    • 1614
    • 1615
    • 1616
    • 1617
    • 1618
    • 1619
    • 1620
    • 1621
    • 1622
    • 1623
    • 1624
    • 1625
    • 1626
    • 1627
    • 1628
    • 1629
    • 1630
    • 1631
    • 1632
    • 1633
    • 1634
    • 1635
    • 1636
    • 1637
    • 1638
    • 1639
    • 1640
    • 1641
    • 1642
    • 1643
    • 1644
    • 1645
    • 1646
    • 1647
    • 1648
    • 1649
    • 1650
    • 1651
    • 1652
    • 1653
    • 1654
    • 1655
    • 1656
    • 1657
    • 1658
    • 1659
    • 1660
    • 1661
    • 1662
    • 1663
    • 1664
    • 1665
    • 1666
    • 1667
    • 1668
    • 1669
    • 1670
    • 1671
    • 1672
    • 1673
    • 1674
    • 1675
    • 1676
    • 1677
    • 1678
    • 1679
    • 1680
    • 1681
    • 1682
    • 1683
    • 1684
    • 1685
    • 1686
    • 1687
    • 1688
    • 1689
    • 1690
    • 1691
    • 1692
    • 1693
    • 1694
    • 1695
    • 1696
    • 1697
    • 1698
    • 1699
    • 1700
    • 1701
    • 1702
    • 1703
    • 1704
    • 1705
    • 1706
    • 1707
    • 1708
    • 1709
    • 1710
    • 1711
    • 1712
    • 1713
    • 1714
    • 1715
    • 1716
    • 1717
    • 1718
    • 1719
    • 1720
    • 1721
    • 1722
    • 1723
    • 1724
    • 1725
    • 1726
    • 1727
    • 1728
    • 1729
    • 1730
    • 1731
    • 1732
    • 1733
    • 1734
    • 1735
    • 1736
    • 1737
    • 1738
    • 1739
    • 1740
    • 1741
    • 1742
    • 1743
    • 1744
    • 1745
    • 1746
    • 1747
    • 1748
    • 1749
    • 1750
    • 1751
    • 1752
    • 1753
    • 1754
    • 1755
    • 1756
    • 1757
    • 1758
    • 1759
    • 1760
    • 1761
    • 1762
    • 1763
    • 1764
    • 1765
    • 1766
    • 1767
    • 1768
    • 1769
    • 1770
    • 1771
    • 1772
    • 1773
    • 1774
    • 1775
    • 1776
    • 1777
    • 1778
    • 1779
    • 1780
    • 1781
    • 1782
    • 1783
    • 1784
    • 1785
    • 1786
    • 1787
    • 1788
    • 1789
    • 1790
    • 1791
    • 1792
    • 1793
    • 1794
    • 1795
    • 1796
    • 1797
    • 1798
    • 1799
    • 1800
    • 1801
    • 1802
    • 1803
    • 1804
    • 1805
    • 1806
    • 1807
    • 1808
    • 1809
    • 1810
    • 1811
    • 1812
    • 1813
    • 1814
    • 1815
    • 1816
    • 1817
    • 1818
    • 1819
    • 1820
    • 1821
    • 1822
    • 1823
    • 1824
    • 1825
    • 1826
    • 1827
    • 1828
    • 1829
    • 1830
    • 1831
    • 1832
    • 1833
    • 1834
    • 1835
    • 1836
    • 1837
    • 1838
    • 1839
    • 1840
    • 1841
    • 1842
  • 相关阅读:
    时间序列数据Correlogram图分析
    【rar密码】WinRAR整理密码,如何使用?
    uniapp支付打开支付宝app进行付款
    MS31804四通道低边驱动器可替代DRV8804(串行数据接口控制,4个低边功率驱动,内置高侧续流二极管)
    uniapp微信小程序-项目实战修改密码
    CSS 三栏布局
    省创暨srdp项目复盘
    开发这么久,gradle 和 gradlew 啥区别、怎么选?
    Alibaba Nacos注册中心源码剖析
    autodl中使用git clone模型中,error: git clone failed exit status 129
  • 原文地址:https://blog.csdn.net/qq_25599925/article/details/134439486