change_rust_src.sh 1.7 KB

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