ubuntu源快速更新脚本 – 1秒钟替换为国内ubuntu镜像

十月 13th, 2009 Posted in Shell, Ubuntu | 阅读次数: 735 次

制作:高进波
时间:2009-10-13

制作此脚本是方便ubuntu用户更换国内快速的ubuntu源,支持4个发行版hardy,intrepid,jaunty,karmic

 

1.编写更新脚本

vi hugwww-apt.sh

#!/bin/bash
#power by hugwww 2009-10
#change apt source

#只需要更改SOURCE变量即可使用自己想用的源
#ylmf ubuntu source
SOURCE="http://archive.ylmf.net/ubuntu/"
#163 ubuntu source
#SOURCE="http://mirrors.163.com/ubuntu/"
#sohu ubuntu source
#SOURCE="http://mirrors.sohu.com/ubuntu/"

#ubuntu 8.04
if [ $(cat /etc/lsb-release |grep "\<hardy\>"  |wc -l ) -ge  1 ];
then
CODENAME="hardy"
fi

#ubuntu 8.10
if [ $(cat /etc/lsb-release |grep "\<intrepid\>"  |wc -l ) -ge  1 ];
then
CODENAME="intrepid"
fi

#ubuntu 9.04
if [ $(cat /etc/lsb-release |grep "\<jaunty\>"  |wc -l ) -ge  1 ];
then
CODENAME="jaunty"
fi

#ubuntu 9.10
if [ $(cat /etc/lsb-release |grep "\<karmic\>"  |wc -l ) -ge  1 ];
then
CODENAME="karmic"
fi

#back old source,update to ylmf ubuntu source
if [ $CODENAME ]
then

msg="#ylmf ubuntu apt source    2009-09-09 update:`date`                        \n\n\
deb $SOURCE $CODENAME main restricted                   \n\
deb-src $SOURCE $CODENAME main restricted               \n\
                                                                                \n\
deb $SOURCE $CODENAME-updates main restricted           \n\
deb-src $SOURCE $CODENAME-updates main restricted       \n\
                                                                                \n\
deb $SOURCE $CODENAME universe                          \n\
deb-src $SOURCE $CODENAME universe                      \n\
deb $SOURCE $CODENAME-updates universe                  \n\
deb-src $SOURCE $CODENAME-updates universe              \n\
                                                                                \n\
deb $SOURCE $CODENAME multiverse                        \n\
deb-src $SOURCE $CODENAME multiverse                    \n\
deb $SOURCE $CODENAME-updates multiverse                \n\
deb-src $SOURCE $CODENAME-updates multiverse            \n\
                                                                                \n\
deb http://security.ubuntu.com/ubuntu $CODENAME-security main restricted        \n\
deb-src http://security.ubuntu.com/ubuntu $CODENAME-security main restricted    \n\
deb http://security.ubuntu.com/ubuntu $CODENAME-security universe               \n\
deb-src http://security.ubuntu.com/ubuntu $CODENAME-security universe           \n\
deb http://security.ubuntu.com/ubuntu $CODENAME-security multiverse             \n\
deb-src http://security.ubuntu.com/ubuntu $CODENAME-security multiverse         \n"

#echo -e $msg
#如果存在sources.list则备份
if [ -f /etc/apt/sources.list ];then
cp /etc/apt/sources.list /etc/apt/sources.list-bak
fi

#生成新的源列表
echo  $msg >/etc/apt/sources.list
echo "已成功更改ubuntu源!"

fi

 

2.执行

sh hugwww-apt.sh

 

完成!

相关日志:

Tags: ,

2 Responses to “ubuntu源快速更新脚本 – 1秒钟替换为国内ubuntu镜像”

  1. Panic Attack Treatment Says:

    Some Other Websites I Like…

    [...]http://www.panicattackstreatmentcure.net/links/ Below are some totally unrelated websites to mine, however, they are really worth checking out[...]…


  2. Drinking Games Says:

    You should check this out……

    [...] Wonderful story, reckoned we could combine a few unrelated data, nevertheless really worth taking a look, whoa did one learn about Mid East has got more problerms as well [...]………


留下您的脚印