当我们新装好虚拟机时我们需要用户环境设置成我们常用的环境。比如别名,提示符,设置vim编写脚本时自动添加信息注释。但是加入我们每装一台机器都自己手动设置那么就会浪费我们的时间,所以就需要我们编写脚本。
#!/bin/bash
#
#***********************************************
#Filename: reset.sh
#Author: D Y
#Description: Initialize user environment
#Create: 2019-08-01 13:54:31
#***********************************************
vr='.vimrc'
[ ! -e $vr ] && touch $vr
echo "set tabstop=4" >> $vr
echo "set cul" >> $vr
echo 'autocmd BufNewFIle *.sh exec " call Setfilehead()" ' >> $vr
echo 'func Setfilehead()' >> $vr
echo 'if expand("%:e") == "sh" ' >> $vr
echo ' call setline(1,"#/bin/bash")' >> $vr
echo " call setline(2, '#')" >> $vr
echo " call setline(3, '#***********************************************')" >> $vr
echo ' call setline(4, "#Filename: ".expand("%"))' >>$vr
echo " call setline(5, '#Author: D Y')" >> $vr
echo " call setline(6, '#Description: ---')" >> $vr
echo " call setline(7, '#QQ: 2841184943')" >> $vr
echo " call setline(8, '#Create: '.strftime('%Y-%m-%d %H:%M:%S'))" >> $vr
echo " call setline(9, '#***********************************************')" >> $vr
echo " endif" >> $vr
echo "endfunc" >> $vr
#PS1
echo "PS1=\e[1;31m[\u@\h \W]\\$\e[0m" >> .bashrc && . .bashrc
#touch /etc/profile.d/env.sh
if [ ! -f /etc/profile.d/env.sh ]; then
touch /etc/profile.d/env.sh
echo "echo -e '\e[1;31mHi,you need to think the impact of your opearation\e[0m'" >> /etc/profile.d/env.sh
fi
#close SELINUX
sed -r 's/(^SELINUX=)enforcing/\1disabled/' /etc/selinux/config
#owner alias
echo "alias cdnet='cd /etc/sysconfig/network-scripts/'" >> .bashrc
echo "alias cp='cp -i'" >> .bashrc
echo "alias editnet1='vim /etc/sysconfig/network-scripts/ifcfg-eth0'" >> .bashrc
echo "alias editnet2='vim /etc/sysconfig/network-scripts/ifcfg-eth1'" >> .bashrc