适合于刚装好的系统进行一些初始化的配置:
#!/bin/bash
#初始化配置脚本
BEGINCOLOR="\e[1;33m"
ENDCOLOR="\e[0m"
BASEARCH="x86_64"
NIC_NAME="ens33"
VAR=`grep -o "[0-9]\+" /etc/redhat-release|head -1`
echo -e "${BEGINCOLOR}启动脚本,检测到系统是Centos$VAR${ENDCOLOR}"
if [ $VAR -eq 6 ];then
NIC_NAME="eth0"
fi
#配置个性化shell脚本风格
echo -e "${BEGINCOLOR}开始shell脚本风格...${ENDCOLOR}"
cat > ~/.vimrc << EOF
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: chenxu")
call setline(5,"#QQ: 314236848")
call setline(6,"#Date: ".strftime("%Y-%m-%d"))
call setline(7,"#FileName: ".expand("%"))
call setline(8,"#URL: http://www.magedu.com")
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
echo -e "${BEGINCOLOR}shell已配置,开始配置别名...${ENDCOLOR}"
#添加几个别名
cat >> ~/.bashrc << EOF
alias viens="vim /etc/sysconfig/network-scripts/ifcfg-$NIC_NAME"
alias scandisk="echo '- - -' > /sys/class/scsi_host/host0/scan ;echo '- - -' > /sys/class/scsi_host/host1/scan ;echo '- - -' > /sys/class/scsi_host/host2/scan "
EOF
echo -e "${BEGINCOLOR}别名已添加,开始修改yum...${ENDCOLOR}"
#修改yum源
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat > /etc/yum.repos.d/base.repo << EOF
[base]
name=aliyun base
baseurl='https://mirrors.aliyun.com/centos/$VAR/os/$BASEARCH/'
'https://mirrors.tuna.tsinghua.edu.cn/centos/$VAR/os/x86_64/'
#baseurl=https://mirrors.aliyun.com/centos/7/updates/x86_64/
gpgcheck=0
gpgkey='https://mirrors.aliyun.com/centos/$VAR/os/x86_64/RPM-GPG-KEY-CentOS-$VAR'
enabled = 1
#enabled=1
EOF
cat > /etc/yum.repos.d/local.repo << EOF
[local]
name=local
baseurl='http://172.22.5.7/centos/$VAR/os/$BASEARCH/'
gpgcheck=0
EOF
cat > /etc/yum.repos.d/epel.repo << EOF
[epel]
name=epel base
baseurl='https://mirrors.aliyun.com/epel/$VAR/x86_64/'
gpgcheck=0
gpgkey='https://mirrors.aliyun.com/centos/$VAR/os/x86_64/RPM-GPG-KEY-CentOS-$VAR'
enabled=1
EOF
echo -e "${BEGINCOLOR}yum源配置完成,开始配置PATH变量...${ENDCOLOR}"
#修改PATH和PS1
echo 'PATH=/script:$PATH' > /etc/profile.d/script.sh
echo 'PS1="\[\e[1;37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[36;40m\]\w\[\e[0m\]]\\$ "' > /etc/profile.d/env.sh
echo -e "${BEGINCOLOR}PATH配置完成,开始修改防火墙配置...${ENDCOLOR}"
#关闭防火墙和selinux
if [ $VAR -eq 6 ];then
service iptables stop &> /dev/null
chkconfig iptables off &> /dev/null
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config &> /dev/null
elif [ $VAR -eq 7 ];then
systemctl stop firewalld &> /dev/null
systemctl disable firewalld &> /dev/null
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config &> /dev/null
fi
echo -e "${BEGINCOLOR}已关闭防火墙和selinux!${ENDCOLOR}"
echo -e "${BEGINCOLOR}初始化完成!需要重启selinux才能生效${ENDCOLOR}"
exit
Linux学习笔记7:初始化脚本
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.