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