177 lines
5.2 KiB
Bash
Executable File
177 lines
5.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
codename=$(lsb_release -cs)
|
|
archname=$(arch)
|
|
|
|
if [ "$codename" == "" ]; then
|
|
codename=bookworm
|
|
fi
|
|
|
|
if [ "$archname" == "x86_64" ]; then
|
|
archname=amd64
|
|
else
|
|
archname=arm64
|
|
fi
|
|
|
|
|
|
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源...'
|
|
echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" | sudo tee /etc/apt/sources.list.d/chrome.list > /dev/null
|
|
sudo cp /usr/share/extra-repo-book/trusted.gpg.d/google-chrome.gpg /etc/apt/trusted.gpg.d/
|
|
read -p "添加完成, 是否更新索引? y/n: " action
|
|
if [[ "$action" == "" || "$action" == "y" ]]; then
|
|
sudo apt update
|
|
fi
|
|
;;
|
|
edge)
|
|
echo '正在添加edge源...'
|
|
echo "deb [arch=amd64] https://packages.microsoft.com/repos/edge/ stable main" | sudo tee /etc/apt/sources.list.d/edge.list > /dev/null
|
|
sudo cp /usr/share/extra-repo-book/trusted.gpg.d/microsoft.gpg /etc/apt/trusted.gpg.d/
|
|
read -p "添加完成, 是否更新索引? y/n: " action
|
|
if [[ "$action" == "" || "$action" == "y" ]]; then
|
|
sudo apt update
|
|
fi
|
|
;;
|
|
vscode)
|
|
echo '正在添加vscode源...'
|
|
echo "deb [arch=amd64] http://packages.microsoft.com/repos/code stable main" | sudo tee /etc/apt/sources.list.d/vscode.list > /dev/null
|
|
sudo cp /usr/share/extra-repo-book/trusted.gpg.d/microsoft.gpg /etc/apt/trusted.gpg.d/
|
|
read -p "添加完成, 是否更新索引? y/n: " action
|
|
if [[ "$action" == "" || "$action" == "y" ]]; then
|
|
sudo apt update
|
|
fi
|
|
;;
|
|
mysql8)
|
|
echo '正在添加mysql8源...'
|
|
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
|
|
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
|
|
|
|
sudo cp /usr/share/extra-repo-book/trusted.gpg.d/mysql.gpg /etc/apt/trusted.gpg.d/
|
|
|
|
read -p "添加完成, 是否更新索引? y/n: " action
|
|
if [[ "$action" == "" || "$action" == "y" ]]; then
|
|
sudo apt update
|
|
fi
|
|
;;
|
|
docker)
|
|
echo '正在添加docker源...'
|
|
echo "deb [arch=${archname}] https://download.docker.com/linux/debian ${codename} stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
|
|
sudo cp /usr/share/extra-repo-book/trusted.gpg.d/docker.gpg /etc/apt/trusted.gpg.d/
|
|
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
|
|
sudo rm /etc/apt/trusted.gpg.d/google-chrome.gpg
|
|
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)
|
|
echo '1.0.3'
|
|
;;
|
|
|
|
add)
|
|
add_repo $2
|
|
;;
|
|
|
|
remove)
|
|
remove_repo $2
|
|
;;
|
|
|
|
-h|--help)
|
|
print_help
|
|
;;
|
|
*)
|
|
print_help
|
|
|
|
esac
|