您当前所在位置:首页脚本Ubuntu自动修改为本地源脚本

Ubuntu自动修改为本地源脚本

更新:2022-05-21 09:32:08编辑:Story归类:脚本人气:293

搭建好本地源后,如果要一台台去修改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

成长的对话版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

Centos自动修改为本地源脚本 Linux退出时限制ip登陆脚本