tools.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # NOTE: Don't execute this script directly. It should be sourced by another script.
  2. # Description: This script contains utility functions.
  3. function get_board_type()
  4. {
  5. local project_path=$1
  6. local supported_board_configs=("CONFIG_BOARD_TYPE_MILKV_DUO" "CONFIG_BOARD_TYPE_MILKV_DUO256M" "CONFIG_BOARD_TYPE_MILKV_DUOS")
  7. local supported_board_types=("duo" "duo256m" "duos")
  8. local board_type="N/A"
  9. for ((i=0; i< ${#supported_board_configs[@]}; i++))
  10. do
  11. config_value=$(grep -w "${supported_board_configs[i]}" ${project_path}/.config | cut -d= -f2)
  12. if [ "$config_value" == "y" ]; then
  13. board_type=${supported_board_types[i]}
  14. break
  15. fi
  16. done
  17. echo ${board_type}
  18. }
  19. function download_rttpkgtool()
  20. {
  21. local project_path=$1
  22. local restult=$(curl -m 10 -s http://www.ip-api.com/json)
  23. local country=$(echo $restult | sed 's/.*"country":"\([^"]*\)".*/\1/')
  24. #echo "Country: $country"
  25. if [ "$country" == "China" ]; then
  26. local url_rttpkgtool="https://gitee.com/unicornx/rttpkgtool.git"
  27. else
  28. local url_rttpkgtool="https://github.com/plctlab/rttpkgtool.git"
  29. fi
  30. #echo "rttpkgtool URL: ${url_rttpkgtool}"
  31. if [ ! -d ${project_path}/rttpkgtool ]; then
  32. echo "rttpkgtool does not exist, clone it from ${url_rttpkgtool}"
  33. git clone ${url_rttpkgtool} ${project_path}/rttpkgtool
  34. if [ $? -ne 0 ]; then
  35. echo "Failed to clone ${url_rttpkgtool} !"
  36. exit 1
  37. fi
  38. else
  39. echo "rttpkgtool already exists"
  40. pushd ${project_path}/rttpkgtool
  41. git checkout main
  42. git pull
  43. popd
  44. fi
  45. }