The following script can automatically identify whether the Centos version is 5, 6, or 7, and add different versions of the source
#! /Bin/bash
ARCH = '/usr/bin/getconf LONG_BIT'
REPOD = "/etc/yum. repos. d"
OSVER = '/bin/awk-F "[.]"' {print $3} '/etc/redhat-release'
OSVER7 = '/bin/awk-F "[.]"' {print $4} '/etc/redhat-release'
If ["$ (ls-A $ REPOD)"]; then
[-D $ {REPOD}/repos. old] |/bin/mkdir $ {REPOD}/repos. old
/Bin/mv $ {REPOD}/*. repo $ {REPOD}/repos. old/-f
Fi
If [$ {ARCH} x = 64x-a $ {OSVER} x = 5x]; then
/Bin/cat >$ {REPOD}/CentOS-Base.repo <EOF
[Base]
Name = CentOS-\ $ releasever-Base
Base url = http://xx.xx.xx.xx/5/ OS /x86_64
Gpgcheck = 0
[Updates]
Name = CentOS-\ $ releasever-Updates
Base url = http://xx.xx.xx.xx/5/updates/x86_64
Gpgcheck = 0
[Extras]
Name = CentOS-\ $ releasever-Extras
Base url = http://xx.xx.xx.xx/5/extras/x86_64
Gpgcheck = 0
EOF
Elif [$ {ARCH} x = 64x-a $ {OSVER} x = 6x]; then
/Bin/cat >$ {REPOD}/CentOS-Base.repo <EOF
[Base]
Name = CentOS-\ $ releasever-Base
Base url = http://xx.xx.xx.xx/6/ OS /x86_64
Gpgcheck = 0
[Updates]
Name = CentOS-\ $ releasever-Updates
Base url = http://xx.xx.xx.xx/6/updates/x86_64
Gpgcheck = 0
[Extras]
Name = CentOS-\ $ releasever-Extras
Base url = http://xx.xx.xx.xx/6/extras/x86_64
Gpgcheck = 0
EOF
Elif [$ {ARCH} x = 64x-a $ {OSVER7} x = 7x]; then
/Bin/cat >$ {REPOD}/CentOS-Base.repo <EOF
[Base]
Name = CentOS-\ $ releasever-Base
Base url = http://xx.xx.xx.xx/7/ OS /x86_64
Gpgcheck = 0
[Updates]
Name = CentOS-\ $ releasever-Updates
Base url = http://xx.xx.xx.xx/7/updates/x86_64
Gpgcheck = 0
[Extras]
Name = CentOS-\ $ releasever-Extras
Base url = http://xx.xx.xx.xx/7/extras/x86_64
Gpgcheck = 0
EOF
Else
Echo "only support CentOS [5/6/7]. x86_64"
Exit 1
Fi