#!/bin/bash
#
#Filename:postinstall_init.sh
#Description:系统安装完成后,对系统进行一些配置,以符合自己的试验环境
#Author:renpingsheng
#Email:995883352@qq.com
#Version:1.0
#Date:2017.5.5
setenforce 0
#更改selinux的配置文件,禁用selinux,成功则打印“配置完成”
sed -i.bak '1,$s@SELINUX=enforcing@SELINUX=disabled@g' /etc/selinux/config && echo "SElinux is setting OK!"
#定义一些常用的别名
cat <<EOF >>/root/.bashrc && echo "The file bashrc is setting ok!"
alias "cdnet"="cd /etc/sysconfig/network-scripts/"
alias "grep"="grep --color=auto"
alias "renet"="service network restart"
EOF
#备份系统已有的repo文件
cd /etc/yum.repos.d/
[ -d repo_bak ] || mkdir repo_bak
mv *.repo repo_bak
echo "The old repo file is backup ok!"
#配置内网的yum源
cat <<EOF > CentOS-base.repo
[CentOS-base]
name=CentOS-base
baseurl=http://172.16.0.1/cobbler/ks_mirror/CentOS-6.8-x86_64/
enabled=1
gpgcheck=0
[epel]
name=CentOS-epel
baseurl=http://172.16.0.1/fedora-epel/6/x86_64/
enabled=1
gpgcheck=0
EOF
echo "The repository is setting ok!"
#清空yum缓存,生成新的yum缓存
yum clean all && yum makecache &> /dev/null
#安装一些常用的软件
for software in vim createrepo psmisc tree lftp htop lrzsz nmap wget traceroute; do
rpm -q $software
#判断软件是否已经安装
if [ $? == 1 ]; then
yum install -y $software >> /dev/null && echo "The package $software is install OK!"
else
echo "The Package $software is already installed!"
fi
done
#释放定义的变量
unset software
#安装系统开发组件
yum groupinstall -y "Development tools" >> /dev/null && echo "Development tools suite is installed ok!"
#配置vim别名
echo "alias vi=vim" >> /root/.bashrc
#配置vim环境
cat <<EOF >> /root/.vimrc && echo "The vimrc file is setting ok!"
set hlsearch
set nu
set ai
set ic
set sm
syntax on
set fileformat=unix
EOF
#使.bashrc文件立即生效
source /root/.bashrc
#使.vimrc文件立即生效
source /root/.vimrc
#重启系统
shutdown -r now
原创文章,作者:renpingsheng,如若转载,请注明出处:http://www.178linux.com/74868

