码迷,mamicode.com
首页 > 其他好文 > 详细

自用初始化脚本

时间:2020-05-03 14:47:20      阅读:50      评论:0      收藏:0      [点我收藏+]

标签:epo   x86_64   后缀   pts   复制   输入   pre   ref   log   

#!/bin/bash
#
#********************************************************************
#Date:             2020-04-30
#FileName:        NetMenu.sh
#Copyright (C):     2020 All rights reserved
#********************************************************************
. /data/func/NetReset
. /data/func/Init_Reset
PS3="选择编号:"
local MENU=禁用SELINUX
关防火墙
修改网卡名
修改提示符
设置yum仓库
安装常用包
添加mailrc与vimrc
全部实现
退出
select M in $MENU ;do
    case $REPLY in 
    1) 
        Down_Selinux
        ;;
    2)
        Down_Firewall
        ;;
    3)
        Change_Grub
        Make_Eth0
        ;;
    4)  set_ps1
        ;;
    5)  set_yumrepo
        ;;
    6)  install_package
        ;;
    7)  set_vim_mail
        ;;
    8)  Down_Selinu
        Down_FireWall
        Change_Grub
        Make_Eth0
        set_ps1
        set_yumrepo
        install_package
        set_vim_mail
        ;;
    9)
        break 
        ;;
    *)
        echo "请输入正确的数字"
    esac
done

 


#!/bin/bash
#
#********************************************************************
#Date: 2020-04-30
#FileName: Init_Reset.sh
#Copyright (C): 2020 All rights reserved
#********************************************************************

 set_ps1(){

echo "PS1=‘\[\e[1;32m\][\[\e[0m\]\t \[\e[1;33m\]\u\[\e[36m\]@\h\[\e[1;31m\] \W\[\e[1;32m\]]\[\e[0m\]\\$ ‘" > /etc/profile.d/reset.sh
    [ $? -eq 0 ] && echo -e "\e[1;32mPS1设置完成\e[0m"  || echo -e "\e[1;31m创建文件失败\e[0m"
}
set_yumrepo(){
    cd /etc/yum.repos.d/
    [ -n backup ] ||  mkdir backup 
    mv *.repo backup/
    local version=`uname -a | grep -o [0-9] |head -n1`
    if [ $version -eq 8 ];then cat > base.repo << EOF
[BaseOS]
name=BaseOS
baseurl=https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/
gpgcheck=0
enabled=1

[epel]
name=EPEL
baseurl=https://mirrors.aliyun.com/epel/\$releaserver/Everything/\$basearch
gpgcheck=0
enabled=1

[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/os
gpgcheck=0
enabled=1
EOF
    cat > AppStream.repo << EOF
[AppStream]
name=AppStream
baseurl=https://mirrors.aliyun.com/centos/8/AppStream/x86_64/os/
gpgcheck=0
enabled=1
EOF
    continue
    else 
    cat > base.repo << EOF
[BaseOS]
name=BaseOS
baseurl=https://mirrors.aliyun.com/centos/\$releasever/os/x86_64/
gpgcheck=0
enabled=1

[epel]
name=EPEL
baseurl=https://mirrors.aliyun.com/epel/\$releasever/\$basearch
failovermethod=priority
gpgcheck=0
enabled=1

[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/
gpgcheck=0
enabled=1
EOF
    continue
    fi
}


install_package(){
    local packages="
    vim
    tree
    autofs
    net-tools
    gcc
    make
    "
    for i in $package;do
        rpm -q $i &> /dev/null echo -e "\e[1;31m初始列表已安装\e[0m" || yum -y install $i
        echo echo -e "\e[1;32m$i已安装\e[0m"
    done
    [ $? -eq 0 ]  ||  echo -e "\e[1;31m安装失败\e[0m"
}

set_vim_mail(){
cat > /etc/profile.d/.vimrc << EOF
set ts=4
set expandtab
set ignorecase
set cursorline
set autoindent
set nu
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,"#Date:          ".strftime("%Y-%m-%d"))
    call setline(5,"#FileName:     ".expand("%"))
    call setline(6,"#Description:      The test script") 
    call setline(7,"#********************************************************************") 
    call setline(8,"") 
    fi
}
autocmd BufNewFile * normal G
EOF
[ $? -eq 0 ] && echo -e "\e[1;32m已在/etc/profile.d/创建.vimrc\e[0m" ||  echo -e "\e[1;31m创建。mailrc失败\e[0m"
cat > /etc/profile.d/.mailrc << EOF
set from="1506092727@qq.com"
set smtp=smtp.qq.com
set smtp-auth-user="1506092727@qq.com"
set smtp-auth-password="vqgyhsytcnfrgejj"
set smtp-auth=login
set ssl-verify=ignore
EOF
[ $? -eq 0 ] && echo -e "\e[1;32m已在/etc/profile.d 创建.mailrc\e[0m" ||  echo -e "\e[1;31m创建.mailrc失败\e[0m"
}
#!/bin/bash
#
#********************************************************************
#Date:             2020-04-30
#FileName:        Down_Selinux.sh
#Copyright (C):     2020 All rights reserved
#********************************************************************

Down_Selinux(){
    sed -Ei s/^(SELINUX=).*/\1disabled/ /etc/selinux/config
    [ $? -eq 0 ] && echo -e "\e[1;32selinux关闭\e[0m" || echo -e "\e[1;31m设置SELINUX出现错误\e[0m"
}
Down_Firewall(){
    systemctl disable --now firewalld
    systemctl disable firewalld.service
    [ $? -eq 0 ] && echo -e "\e[1;32m已关闭防火墙\e[0m" || echo -e "\e[1;31m关闭防火墙出现错误\e[0m"
}
Change_Grub(){
  sed -Ei s/^(GRUB_CMDLINE_LINUX=.*quiet)"$/\1 net.ifnames=0"/ /etc/default/grub
  grub2-mkconfig -o /boot/grub2/grub.cfg &> /dev/null
  [ $? -eq 0 ] && echo -e "\e[1;32mgrub文件已更改\e[0m" || echo -e "\e[1;31mgrub出现错误\e[0m"
}
Make_Eth0(){
    local NET_BAK=/data/netset/
    mkdir $NET_BAK
    cd /etc/sysconfig/network-scripts/
    mv * $NET_BAK
    [ $? -eq 0 ] && echo -e "\e[1;32m原文件已复制到$NET_BAK\e[0m" || echo -e "\e[1;31m移动文件失败\e[0m"
    read -p "输入IP后缀:" IPEND && cat > ifcfg-eth0 << @
DEVICE=eth0
NAME=eth0
IPADDR=10.0.0.$IPEND
PREFIX=24
GATEWAY=10.0.0.2
DNS1=180.76.76.76
DNS2=223.6.6.6
BOOTPROTO=static
@
    [ $? -eq 0 ] && echo -e "\e[1;32m已更新静态IP文件\e[0m" ||  echo -e "\e[1;31m创建文件失败\e[0m"
}

自用初始化脚本

标签:epo   x86_64   后缀   pts   复制   输入   pre   ref   log   

原文地址:https://www.cnblogs.com/zy2271/p/12821783.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!