2022-07-14 19:58:02 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-10-07 17:49:44 +08:00
|
|
|
codename=$(lsb_release -cs)
|
|
|
|
archname=$(arch)
|
|
|
|
|
|
|
|
if [ "$codename" == "" ]; then
|
|
|
|
codename=bookworm
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$archname" == "x86_64" ]; then
|
|
|
|
archname=amd64
|
|
|
|
else
|
|
|
|
archname=arm64
|
|
|
|
fi
|
2022-07-14 19:58:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
function print_help () {
|
|
|
|
echo ' list - 列出支持订阅的软件源'
|
|
|
|
echo ' add {name} - 添加指定的软件源'
|
|
|
|
echo ' remove {name} - 移除指定的软件源'
|
|
|
|
echo ' -h, --help - 打印帮助信息'
|
|
|
|
echo ' -v - 打印版本号'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function print_list () {
|
|
|
|
echo ' - chrome - 谷歌浏览器源,包括stable, beta, dev'
|
|
|
|
echo ' - edge - 微软Edge浏览器源'
|
|
|
|
echo ' - vscode - 微软VsCode编辑器源'
|
|
|
|
echo ' - mysql8 - Mysql 8.0源,包括server, client, tools等'
|
|
|
|
echo ' - docker - docker源'
|
|
|
|
echo ''
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function add_repo () {
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
chrome)
|
|
|
|
echo '正在添加chrome源...'
|
2023-10-07 17:49:44 +08:00
|
|
|
echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" | sudo tee /etc/apt/sources.list.d/chrome.list > /dev/null
|
2024-11-08 15:09:11 +08:00
|
|
|
sudo cp /usr/share/extra-repo-book/trusted.gpg.d/google-chrome.gpg /etc/apt/trusted.gpg.d/
|
2022-07-14 19:58:02 +08:00
|
|
|
read -p "添加完成, 是否更新索引? y/n: " action
|
|
|
|
if [[ "$action" == "" || "$action" == "y" ]]; then
|
|
|
|
sudo apt update
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
edge)
|
|
|
|
echo '正在添加edge源...'
|
2023-10-07 17:49:44 +08:00
|
|
|
echo "deb [arch=amd64] https://packages.microsoft.com/repos/edge/ stable main" | sudo tee /etc/apt/sources.list.d/edge.list > /dev/null
|
2024-11-08 15:09:11 +08:00
|
|
|
sudo cp /usr/share/extra-repo-book/trusted.gpg.d/microsoft.gpg /etc/apt/trusted.gpg.d/
|
2022-07-14 19:58:02 +08:00
|
|
|
read -p "添加完成, 是否更新索引? y/n: " action
|
|
|
|
if [[ "$action" == "" || "$action" == "y" ]]; then
|
|
|
|
sudo apt update
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
vscode)
|
|
|
|
echo '正在添加vscode源...'
|
2023-10-07 17:49:44 +08:00
|
|
|
echo "deb [arch=amd64] http://packages.microsoft.com/repos/code stable main" | sudo tee /etc/apt/sources.list.d/vscode.list > /dev/null
|
2024-11-08 15:09:11 +08:00
|
|
|
sudo cp /usr/share/extra-repo-book/trusted.gpg.d/microsoft.gpg /etc/apt/trusted.gpg.d/
|
2022-07-14 19:58:02 +08:00
|
|
|
read -p "添加完成, 是否更新索引? y/n: " action
|
|
|
|
if [[ "$action" == "" || "$action" == "y" ]]; then
|
|
|
|
sudo apt update
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
mysql8)
|
|
|
|
echo '正在添加mysql8源...'
|
2024-05-17 09:21:30 +08:00
|
|
|
echo "deb [arch=amd64] http://repo.mysql.com/apt/debian/ ${codename} mysql-8.0" | sudo tee /etc/apt/sources.list.d/mysql.list > /dev/null
|
2023-10-07 17:49:44 +08:00
|
|
|
echo "deb [arch=amd64] http://repo.mysql.com/apt/debian/ ${codename} mysql-tools" | sudo tee -a /etc/apt/sources.list.d/mysql.list > /dev/null
|
|
|
|
|
2024-11-08 15:09:11 +08:00
|
|
|
sudo cp /usr/share/extra-repo-book/trusted.gpg.d/mysql.gpg /etc/apt/trusted.gpg.d/
|
2023-10-07 17:49:44 +08:00
|
|
|
|
2022-07-14 19:58:02 +08:00
|
|
|
read -p "添加完成, 是否更新索引? y/n: " action
|
|
|
|
if [[ "$action" == "" || "$action" == "y" ]]; then
|
|
|
|
sudo apt update
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
docker)
|
|
|
|
echo '正在添加docker源...'
|
2023-10-07 17:49:44 +08:00
|
|
|
echo "deb [arch=${archname}] https://download.docker.com/linux/debian ${codename} stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
|
|
|
2024-11-08 15:09:11 +08:00
|
|
|
sudo cp /usr/share/extra-repo-book/trusted.gpg.d/docker.gpg /etc/apt/trusted.gpg.d/
|
2022-07-14 19:58:02 +08:00
|
|
|
read -p "添加完成, 是否更新索引? y/n: " action
|
|
|
|
if [[ "$action" == "" || "$action" == "y" ]]; then
|
|
|
|
sudo apt update
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo '未知的源, 无法添加!!!'
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove_repo () {
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
chrome)
|
|
|
|
echo '正在删除chrome源...'
|
|
|
|
sudo rm /etc/apt/sources.list.d/chrome.list
|
2024-11-08 15:09:11 +08:00
|
|
|
sudo rm /etc/apt/trusted.gpg.d/google-chrome.gpg
|
2022-07-14 19:58:02 +08:00
|
|
|
read -p "删除完成, 是否更新索引? y/n: " action
|
|
|
|
if [[ "$action" == "" || "$action" == "y" ]]; then
|
|
|
|
sudo apt update
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
edge)
|
|
|
|
echo '正在删除edge源...'
|
|
|
|
sudo rm /etc/apt/sources.list.d/edge.list
|
|
|
|
if [ ! -f /etc/apt/sources.list.d/vscode.list ]; then
|
|
|
|
sudo rm /etc/apt/trusted.gpg.d/microsoft.gpg
|
|
|
|
fi
|
|
|
|
read -p "删除完成, 是否更新索引? y/n: " action
|
|
|
|
if [[ "$action" == "" || "$action" == "y" ]]; then
|
|
|
|
sudo apt update
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
vscode)
|
|
|
|
echo '正在删除vscode源...'
|
|
|
|
sudo rm /etc/apt/sources.list.d/vscode.list
|
|
|
|
if [ ! -f /etc/apt/sources.list.d/edge.list ]; then
|
|
|
|
sudo rm /etc/apt/trusted.gpg.d/microsoft.gpg
|
|
|
|
fi
|
|
|
|
read -p "删除完成, 是否更新索引? y/n: " action
|
|
|
|
if [[ "$action" == "" || "$action" == "y" ]]; then
|
|
|
|
sudo apt update
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
mysql8)
|
|
|
|
echo '正在删除mysql8源...'
|
|
|
|
sudo rm /etc/apt/sources.list.d/mysql.list
|
|
|
|
sudo rm /etc/apt/trusted.gpg.d/mysql.gpg
|
|
|
|
read -p "删除完成, 是否更新索引? y/n: " action
|
|
|
|
if [[ "$action" == "" || "$action" == "y" ]]; then
|
|
|
|
sudo apt update
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
docker)
|
|
|
|
echo '正在删除docker源...'
|
|
|
|
sudo rm /etc/apt/sources.list.d/docker.list
|
|
|
|
sudo rm /etc/apt/trusted.gpg.d/docker.gpg
|
|
|
|
read -p "删除完成, 是否更新索引? y/n: " action
|
|
|
|
if [[ "$action" == "" || "$action" == "y" ]]; then
|
|
|
|
sudo apt update
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo '未知的源, 无法添加!!!'
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
list)
|
|
|
|
print_list
|
|
|
|
;;
|
|
|
|
|
|
|
|
-v)
|
2023-10-07 17:58:23 +08:00
|
|
|
echo '1.0.3'
|
2022-07-14 19:58:02 +08:00
|
|
|
;;
|
|
|
|
|
|
|
|
add)
|
|
|
|
add_repo $2
|
|
|
|
;;
|
|
|
|
|
|
|
|
remove)
|
|
|
|
remove_repo $2
|
|
|
|
;;
|
|
|
|
|
|
|
|
-h|--help)
|
|
|
|
print_help
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
print_help
|
|
|
|
|
|
|
|
esac
|