change_rust_src.sh 1.6 KB

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