Ali so server Linux system update Yum source shell script _linux Shell

Source: Internet
Author: User
Tags aliyun

All executed scripts need root identity to execute: Execute the command as root: Bash xxx.sh

Function: Automatic detection system and update source
Applicable system version: compatible with all Linux versions on line
How to: Execute a command as root: Bash update_source.sh
What solved the problem: one-click Detection System and update the source
Benefits to customers: The user can only execute the script one time to automatically detect the system and update the source.
Note: Because the system version has a supported cycle, some sources may appear unavailable, including the official source, which is normal

#!/bin/bash ######################################### #Function: Update source #Usage: Bash update_source.sh #Author: Customer Service Department #Company: Alibaba Cloud Computing #Version: 2.0 ####################################### # # Check_os_release () {While True does os_release=$ (grep "Red Hat Enterprise Linux Server release"/etc/issue 2>/de V/null) os_release_2=$ (grep "Red Hat Enterprise Linux Server release"/etc/redhat-release 2>/dev/null) if [$os _re 
    Lease "] && [" $os _release_2 "] then if echo" $os _release "|grep" Release 5 ">/dev/null 2>&1 Then Os_release=redhat5 echo "$os _release" elif echo "$os _release" |grep "Release 6" >/dev/null 2>&1st En os_release=redhat6 echo "$os _release" Else os_release= "" echo "$os _release" fi break fi OS _release=$ (grep "Aliyun Linux release"/etc/issue 2>/dev/null) os_release_2=$ (grep "Aliyun Linux release"/etc/aliyun -release 2>/dev/null)
  If ["$os _release"] && ["$os _release_2"] then if echo "$os _release" |grep "Release 5" >/dev/null 2&gt &1 then Os_release=aliyun5 echo "$os _release" elif echo "$os _release" |grep "Release 6" >/dev/null 2&
   Gt;&1 then os_release=aliyun6 echo "$os _release" Else os_release= "" echo "$os _release" fi Break fi os_release=$ (grep ' CentOS release '/etc/issue 2>/dev/null) os_release_2=$ (grep "CentOS release"/etc/*re Lease 2>/dev/null) If ["$os _release"] && ["$os _release_2"] then if echo "$os _release" |grep "release 5 ">/dev/null 2>&1 then os_release=centos5 echo" $os _release "elif echo" $os _release "|grep" Releas E 6 ">/dev/null 2>&1 then os_release=centos6 echo" $os _release "Else os_release=" "echo" $ Os_release "Fi break fi os_release=$ (grep-i" ubuntu "/etc/issue 2>/dev/null) os_release_2=$ (grep-i" Ubunt ") U "/etc/lsb-release 2>/dev/null) If ["$os _release"] && ["$os _release_2"] then if echo "$os _release" |grep "Ubuntu" >/de V/null 2>&1 then Os_release=ubuntu10 echo "$os _release" elif echo "$os _release" |grep "Ubuntu 12.04" & Gt;/dev/null 2>&1 then os_release=ubuntu1204 echo "$os _release" elif echo "$os _release" |grep "Ubuntu 12.10 ">/dev/null 2>&1 then os_release=ubuntu1210 echo" $os _release "Else os_release=" EC Ho "$os _release" fi break fi os_release=$ (grep-i "Debian"/etc/issue 2>/dev/null) os_release_2=$ (grep-i " Debian "/proc/version 2>/dev/null" if ["$os _release"] && ["$os _release_2"] then if echo "$os _release 
    "|grep" Linux 6 ">/dev/null 2>&1 then os_release=debian6 echo" $os _release "Else os_release=" " echo "$os _release" fi break fi Break Done} Modify_rhel5_yum () {Wget-o/ETC/YUM.REPOS.D/CENTOS-BASE.R EPO Http://mirrors.aliyuNcs.com/repo/centos-5.repo sed-i ' s/aliyun/aliyuncs/g '/etc/yum.repos.d/centos-base.repo sed-i ' s/\ $releasever/5/'/ Etc/yum.repos.d/centos-base.repo Yum Clean metadata yum Makecache CD ~} Modify_rhel6_yum () {Wget-o/etc/yum.repos. D/centos-base.repo http://mirrors.aliyuncs.com/repo/Centos-6.repo sed-i ' s/aliyun/aliyuncs/g '/etc/yum.repos.d/

Centos-base.repo sed-i ' s/\ $releasever/6/'/etc/yum.repos.d/centos-base.repo yum clean metadata yum Makecache CD ~} Update_ubuntu10_apt_source () {ECHO-E "\033[40;32mbackup" Original configuration file,new name and path is/etc/apt/s ources.list.back.\n\033[40;37m "Cp-fp/etc/apt/sources.list/etc/apt/sources.list.back cat >/etc/apt/
Sources.list <<eof #ubuntu deb Http://cn.archive.ubuntu.com/ubuntu/maverick main restricted universe multiverse DEB-SRC Http://cn.archive.ubuntu.com/ubuntu/maverick main restricted universe Multiverse #163 Deb http:// Mirrors.163.com/ubuntu/maverick main Universe restricted Multiverse DEB-SRC Http://mirrors.163.com/ubuntu/maverick main Universe restricted multiverse Deb http://mirrors.163.com/ubuntu/ Maverick-updates Universe main Multiverse restricted DEB-SRC http://mirrors.163.com/ubuntu/maverick-updates Main multiverse restricted #lupaworld Deb Http://mirror.lupaworld.com/ubuntu/maverick main universe restricted Multiverse DEB-SRC Http://mirror.lupaworld.com/ubuntu/maverick main universe restricted multiverse Deb http:// Mirror.lupaworld.com/ubuntu/maverick-security Universe main Multiverse restricted deb-src http:// Mirror.lupaworld.com/ubuntu/maverick-security Universe main Multiverse restricted Deb http://mirror.lupaworld.com/ Ubuntu/maverick-updates Universe main Multiverse restricted Deb http://mirror.lupaworld.com/ubuntu/maverick-proposed Universe main Multiverse restricted DEB-SRC http://mirror.lupaworld.com/ubuntu/maverick-proposed universe main Multiverse restricted Deb Http://mirror.lupaworld.com/ubuntu/maverick-backports universe main muLtiverse restricted deb-src http://mirror.lupaworld.com/ubuntu/maverick-backports universe main Multiverse restricted DEB-SRC Http://mirror.lupaworld.com/ubuntu/maverick-updates Universe main Multiverse restricted EOF apt-get update} upd Ate_ubuntu1204_apt_source () {ECHO-E "\033[40;32mbackup" Original configuration file,new name and path Is/etc/apt/sou rces.list.back.\n\033[40;37m "Cp-fp/etc/apt/sources.list/etc/apt/sources.list.back cat >/etc/apt/sources.list <<eof #12. deb http://mirrors.aliyuncs.com/ubuntu/precise main restricted universe multiverse Deb http:// Mirrors.aliyuncs.com/ubuntu/precise-security main restricted universe multiverse Deb http://mirrors.aliyuncs.com/ Ubuntu/precise-updates main restricted universe multiverse Deb http://mirrors.aliyuncs.com/ubuntu/precise-proposed Main restricted Universe Multiverse Deb Http://mirrors.aliyuncs.com/ubuntu/precise-backports main restricted universe Multiverse DEB-SRC http://mirrors.aliyuncs.com/ubuntu/pRecise main restricted universe Multiverse deb-src http://mirrors.aliyuncs.com/ubuntu/precise-security main restricted
Universe Multiverse deb-src http://mirrors.aliyuncs.com/ubuntu/precise-updates main restricted universe multiverse DEB-SRC http://mirrors.aliyuncs.com/ubuntu/precise-proposed main restricted universe multiverse DEB-SRC Mirrors.aliyuncs.com/ubuntu/precise-backports main restricted universe Multiverse EOF apt-get Update} update_ubuntu121 0_apt_source () {ECHO-E "\033[40;32mbackup" Original configuration file,new name and path Is/etc/apt/sources.list.bac k.\n\033[40;37m "Cp-fp/etc/apt/sources.list/etc/apt/sources.list.back cat >/etc/apt/sources.list <<EOF # 12.10 Deb Http://mirrors.aliyuncs.com/ubuntu/quantal main restricted universe multiverse Deb http:// Mirrors.aliyuncs.com/ubuntu/quantal-security main restricted universe multiverse Deb http://mirrors.aliyuncs.com/ Ubuntu/quantal-updates main restricted universe multiverse Deb Http://mirrors.aliyuncs.com/ubuntu/quantal-proposed main restricted universe multiverse Deb http://mirrors.aliyuncs.com/ubuntu/ Quantal-backports main restricted universe Multiverse deb-src Http://mirrors.aliyuncs.com/ubuntu/quantal main Restricted Universe Multiverse deb-src http://mirrors.aliyuncs.com/ubuntu/quantal-security main restricted universe Multiverse deb-src http://mirrors.aliyuncs.com/ubuntu/quantal-updates main restricted universe Multiverse deb-src http ://mirrors.aliyuncs.com/ubuntu/quantal-proposed main restricted universe multiverse deb-src http:// Mirrors.aliyuncs.com/ubuntu/quantal-backports main restricted universe Multiverse EOF apt-get Update} UPDATE_DEBIAN_AP T_source () {ECHO-E "\033[40;32mbackup" Original configuration file,new name and path is/etc/apt/sources.list.back.\n \033[40;37m "Cp-fp/etc/apt/sources.list/etc/apt/sources.list.back cat >/etc/apt/sources.list <<EOF # Debian6 Deb Http://mirrors.aliyuncs.com/debian/squeeze main Non-free contrib Deb Http://mirrors.aliyuncs.com/debian/squeeze-proposed-updates main Non-free contrib deb-src http:// Mirrors.aliyuncs.com/debian/squeeze main Non-free Contrib deb-src http://mirrors.aliyuncs.com/debian/ Squeeze-proposed-updates main Non-free contrib EOF apt-get Update} ################### #Start ################### #check Lock file, one time is let the script run one time lockfile=/tmp/.$ (basename $) If [-F "$LOCKfile"] then echo-e "\ 033[1;40;31mthe script is already exist,please next time to run this script.\n\033[0m "exit else Echo-e" \033[40;32mste P 1.No Lock File,begin to create lock file and continue.\n\033[40;37m "Touch $LOCKfile fi #check user if [$ (id-u)!=" 0 "] then ECHO-E" \033[1;40;31merror:you must is root to run this script, please use the root to install this script.\n\033 [0m] rm-rf $LOCKfile exit 1 fi echo-e "\033[40;32mstep 2.Begen to check the OS issue.\n\033[40;37m" os_release=$ (check _os_release) If ["X$os_release" = "X"] then echo-e "\033[1;40;31mThe OS does not identify,so the not executede.\n\033[0m "Rm-rf $LOCKfile exit 0 Else Echo-e" \033[40;32 Mthis OS is $os _release.\n\033[40;37m "fi echo-e" \033[40;32mstep 3.Begen to modify the source Configration file and upd
ate.\n\033[40;37m "Case" $os _release "in Redhat5|centos5|aliyun5") Modify_rhel5_yum;;
REDHAT6|CENTOS6|ALIYUN6) Modify_rhel6_yum;;
UBUNTU10) Update_ubuntu10_apt_source;;
ubuntu1204) Update_ubuntu1204_apt_source;;
ubuntu1210) Update_ubuntu1210_apt_source;;
DEBIAN6) Update_debian_apt_source;; Esac echo-e "\033[40;32msuccess,exit now!\n\033[40;37m" Rm-rf $LOCKfile
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.