#!/bin/bash

# this script is created by tangbo.

# e_mail:79313760@qq.com

# version:1.0 

#################################################

#################################################

#set -x

# Set Language and must be root

export LANG="zh_CN.GB18030"

  if [[ "$(whoami)" != "root" ]]

     then

     echo "please,Run This Script As root." >&2

     exit 1

  fi


#soure function library

. /etc/init.d/functions


#config YUM CentOS-Base.repo  

ConfigYum(){

echo "Exchange CentOS-Base.repo"

      cd /etc/yum.repos.d/

      cp CentOS-Base.repo CentOS-Base.repo.backup.$(date +%F)

      ping -c1 www.baidu.com &> /dev/null

      [ $? -ne 0 ] && echo $"Networking not configured - exiting." && exit 1

      wget --quiet -o /dev/null http://mirrors.163.com/.help/CentOS6-Base-163.repo &>/dev/null   

      mv CentOS6-Base-163.repo CentOS-Base.repo

      yum clean all &> /dev/null

      echo "Exchange CentOS-Base.repo Success"

      sleep 1

             }


#Install Init Packages

installTool(){

echo "Please,Wait,Installing:sysstat ntp net-snmp lrzsz"

      yum -y install sysstat ntp net-snmp lrzsz  >/dev/null  2>&1 

      echo -e "installTool\nversion information:\n`rpm -qa sysstat ntp net-snmp lrzsz`"

      sleep 1

             }


#Close Selinux and Iptables 

initFirewall(){

echo "Close Selinux and Iptables"

      cp /etc/selinux/config /etc/selinux/config.`date +"%Y-%m-%d_%H-%M-%S"`

      /etc/init.d/iptables stop &> /dev/null

      service iptables status

      sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config

      setenforce 0

      grep SELINUX=disabled /etc/selinux/config 

      echo "Close selinux ->OK iptables->OK"

      sleep 1

              }


#Init Auto Startup service 

initService(){

echo "STOP Service"

     export LANG="en_US.UTF-8"

     for test in `chkconfig --list | grep 3:on | awk '{print $1}'`

         do

         # print $test 

         chkconfig --level 3 $test off

         done

    for tangbo in crond network syslog sshd

do

chkconfig --level 3 $tangbo on &>/dev/null 

        done

#export LANG="zh_CN.GB18030"

echo "stop not service->OK"

sleep 1

 

}

#Change SSH port and stop root

initSsh(){

echo "#---sshConfig change 22,stop root ---#"

   export LANG="en_US.UTF-8"

   cp /etc/ssh/sshd_config /etc/ssh/sshd_config.`date +"%Y-%m-%d_%H-%M-%S"`

   sed -i 's%#Port 22%Port 4022%' /etc/ssh/sshd_config

   sed -i 's%#PermitRootLogin yes%PermitRootLogin no%' /etc/ssh/sshd_config

   sed -i 's%#Port 22%Port 4022%' /etc/ssh/sshd_config

   sed -i 's%#Port 22%Port 4022%' /etc/ssh/sshd_config

   /etc/init.d/sshd reload && echo "ssh chang true" || echo "ssh chang false"

   

          }

#set sync-System-Time  

syncSystemTime(){

echo "set sync-system-time-success"

echo "*/2 * * * * /usr/sbin/ntpdate time.nist.gov &> /dev/null  2>&1" >>/var/spool/cron/root

       }

#set file limits

openFiles(){

echo "#---file=65535---#"

    export LANG="en_US.UTF-8"

    \cp /etc/security/limits.conf /etc/security/limits.conf.`date +"%Y-%m-%d_%H-%M-%S"`

    sed -i '/# End of file/i\*\t\t-\tnofile\t\t65535' /etc/security/limits.conf

    ulimit -HSn 65535 

    echo "set files success"

    sleep 1

           }

#set alias

alias(){

echo "set alias"

    echo "alias grep='grep --color'" >> /root/.bashrc

    source /root/.bashrc

    sleep 1

           }