Skip to content

Instantly share code, notes, and snippets.

@HUGHNew
Created February 21, 2022 09:41
Show Gist options
  • Save HUGHNew/e26857afed54a824cf8fd3517728a7bb to your computer and use it in GitHub Desktop.
Save HUGHNew/e26857afed54a824cf8fd3517728a7bb to your computer and use it in GitHub Desktop.
Maybe works for Debian and its derivative versions which use apt/dpkg as package manager
#!/bin/bash
set -e
fn=sources.list
sfn=/etc/apt/$fn
ali="mirrors.aliyun.com"
ustc="mirrors.ustc.edu.cn"
ts="mirrors.tuna.tsinghua.edu.cn"
raw="$(awk -F / '{print $3}' /etc/apt/sources.list.raw |grep -v "^$"|head -n 1)"
cp $sfn ./$fn
sudo mv $sfn $sfn.raw
sed -e "1c # USTC Source" -e "s/$raw/$ustc/g" $fn |sudo tee $sfn > /dev/null
sed -e "1c # Aliyun Source" -e "s/$raw/$ali/g" $fn |sudo tee -a $sfn > /dev/null
rm ./$fn
echo "change source successfully!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment