Ubuntu自动修改为本地源脚本

搭建好本地源后,如果要一台台去修改sources.list文件比较麻烦,于是就整理了个脚本,只需要在VM上运行脚本即可更改成本地源。

下面脚本可以自动识别Ubuntu是12.04还是14.04版本,添加不同版本的源

#!/bin/bash

ARCH=`/usr/bin/getconf LONG_BIT`
REPOD="/etc/apt"
OSVER=`/usr/bin/lsb_release -a |grep Codename |awk -F " " '{print $2}'`
if [ "$(ls -A $REPOD)" ] ; then
[ -d ${REPOD}/sources.list.old ] || /bin/mkdir ${REPOD}/sources.list.old
/bin/mv ${REPOD}/sources.list ${REPOD}/sources.list.old/ -f
fi

if [ ${ARCH}x == 64x -a ${OSVER} == precise ] ; then
/bin/cat >${REPOD}/sources.list <<EOF
deb http://xx.xx.xx.xx/ubuntu precise main multiverse restricted universe
deb http://xx.xx.xx.xx/ubuntu precise-backports main multiverse restricted universe
deb http://xx.xx.xx.xx/ubuntu precise-proposed main multiverse restricted universe
deb http://xx.xx.xx.xx/ubuntu precise-updates main multiverse restricted universe
deb http://xx.xx.xx.xx/ubuntu precise-security main multiverse restricted universe
EOF
elif [ ${ARCH}x == 64x -a ${OSVER} == trusty ] ; then
/bin/cat >${REPOD}/sources.list <<EOF
deb http://xx.xx.xx.xx/ubuntu trusty main multiverse restricted universe
deb http://xx.xx.xx.xx/ubuntu trusty-backports main multiverse restricted universe
deb http://xx.xx.xx.xx/ubuntu trusty-proposed main multiverse restricted universe
deb http://xx.xx.xx.xx/ubuntu trusty-updates main multiverse restricted universe
deb http://xx.xx.xx.xx/ubuntu trusty-security main multiverse restricted universe
EOF
else
echo "only support Ubuntu-trusty/precise.x86_64"
exit 1
fi

weinxin
聂扬帆博客
一个分享IT运维相关工作经验和实战技巧的个人博客

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: