xref: /DragonOS/tools/change_rust_src.sh (revision 415e46ea470ba1dd33e4368c3684c700a75f3be8)
1echo "正在为rust换源"
2
3sparse="false"
4
5CONFIG_FILE=~/.cargo/config.toml
6# 创建父目录
7if [ ! -d ~/.cargo ]; then
8    mkdir -p ~/.cargo
9fi
10
11while true; do
12    if [ -z "$1" ]; then
13	break;
14    fi
15    case "$1" in
16	"--sparse")
17	    echo "使用稀疏索引"
18	    sparse=""
19	    ;;
20    esac
21    shift 1
22    done
23
24
25if [ -z ${sparse} ]; then
26echo -e "[source.crates-io]                             \n \
27replace-with = 'rsproxy-sparse'                         \n \
28[source.rsproxy]                                        \n \
29registry = \"https://rsproxy.cn/crates.io-index\"       \n \
30[source.rsproxy-sparse]                                 \n \
31registry = \"sparse+https://rsproxy.cn/index/\"         \n \
32[registries.rsproxy]                                    \n \
33index = \"https://rsproxy.cn/crates.io-index\"          \n \
34[net]                                                   \n \
35git-fetch-with-cli = true                               \n \
36" > $CONFIG_FILE
37else
38echo "TIPS: bash change_rust_src.sh --sparse以使用稀疏索引"
39
40echo -e "[source.crates-io]                             \n \
41replace-with = 'rsproxy'                                \n \
42[source.rsproxy]                                        \n \
43registry = \"https://rsproxy.cn/crates.io-index\"       \n \
44[source.rsproxy-sparse]                                 \n \
45registry = \"sparse+https://rsproxy.cn/index/\"         \n \
46[registries.rsproxy]                                    \n \
47index = \"https://rsproxy.cn/crates.io-index\"          \n \
48[net]                                                   \n \
49git-fetch-with-cli = true                               \n \
50" > $CONFIG_FILE
51fi
52