ubuntu默认源下载速度偏慢,国内环境需要修改源.

脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash
##
## 快速修改源为aliyun
##

if [[ "$(grep 'aliyun' /etc/apt/sources.list)" != "" ]]; then
echo "[ERROR]已经修改!!!"
exit 0
fi

sudo mv /etc/apt/sources.list /etc/apt/sources.list.old
grep -v '^#' /etc/apt/sources.list.old \
| grep -v '^$' \
| sed -e 's/archive.ubuntu.com/mirrors.aliyun.com/' -e 's/security.ubuntu.com/mirrors.aliyun.com/' \
> ~/sources.list
sudo mv ~/sources.list /etc/apt/sources.list
echo "[INFO]修改完成!!!"

## 一行代码
## sudo mv /etc/apt/sources.list /etc/apt/sources.list.old && grep -v '^#' /etc/apt/sources.list.old | grep -v '^$' | sed -e 's/archive.ubuntu.com/mirrors.aliyun.com/' -e 's/security.ubuntu.com/mirrors.aliyun.com/' > ~/sources.list && sudo mv ~/sources.list /etc/apt/sources.list && echo "[INFO]修改完成!!!"