init-tools-native.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/usr/bin/env bash
  2. source="${BASH_SOURCE[0]}"
  3. scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
  4. base_uri='https://netcorenativeassets.blob.core.windows.net/resource-packages/external'
  5. install_directory=''
  6. clean=false
  7. force=false
  8. download_retries=5
  9. retry_wait_time_seconds=30
  10. global_json_file="$(dirname "$(dirname "${scriptroot}")")/global.json"
  11. declare -A native_assets
  12. . $scriptroot/pipeline-logging-functions.sh
  13. . $scriptroot/native/common-library.sh
  14. while (($# > 0)); do
  15. lowerI="$(echo $1 | awk '{print tolower($0)}')"
  16. case $lowerI in
  17. --baseuri)
  18. base_uri=$2
  19. shift 2
  20. ;;
  21. --installdirectory)
  22. install_directory=$2
  23. shift 2
  24. ;;
  25. --clean)
  26. clean=true
  27. shift 1
  28. ;;
  29. --force)
  30. force=true
  31. shift 1
  32. ;;
  33. --downloadretries)
  34. download_retries=$2
  35. shift 2
  36. ;;
  37. --retrywaittimeseconds)
  38. retry_wait_time_seconds=$2
  39. shift 2
  40. ;;
  41. --help)
  42. echo "Common settings:"
  43. echo " --installdirectory Directory to install native toolset."
  44. echo " This is a command-line override for the default"
  45. echo " Install directory precedence order:"
  46. echo " - InstallDirectory command-line override"
  47. echo " - NETCOREENG_INSTALL_DIRECTORY environment variable"
  48. echo " - (default) %USERPROFILE%/.netcoreeng/native"
  49. echo ""
  50. echo " --clean Switch specifying not to install anything, but cleanup native asset folders"
  51. echo " --force Clean and then install tools"
  52. echo " --help Print help and exit"
  53. echo ""
  54. echo "Advanced settings:"
  55. echo " --baseuri <value> Base URI for where to download native tools from"
  56. echo " --downloadretries <value> Number of times a download should be attempted"
  57. echo " --retrywaittimeseconds <value> Wait time between download attempts"
  58. echo ""
  59. exit 0
  60. ;;
  61. esac
  62. done
  63. function ReadGlobalJsonNativeTools {
  64. # Get the native-tools section from the global.json.
  65. local native_tools_section=$(cat $global_json_file | awk '/"native-tools"/,/}/')
  66. # Only extract the contents of the object.
  67. local native_tools_list=$(echo $native_tools_section | awk -F"[{}]" '{print $2}')
  68. native_tools_list=${native_tools_list//[\" ]/}
  69. native_tools_list=$( echo "$native_tools_list" | sed 's/\s//g' | sed 's/,/\n/g' )
  70. local old_IFS=$IFS
  71. while read -r line; do
  72. # Lines are of the form: 'tool:version'
  73. IFS=:
  74. while read -r key value; do
  75. native_assets[$key]=$value
  76. done <<< "$line"
  77. done <<< "$native_tools_list"
  78. IFS=$old_IFS
  79. return 0;
  80. }
  81. native_base_dir=$install_directory
  82. if [[ -z $install_directory ]]; then
  83. native_base_dir=$(GetNativeInstallDirectory)
  84. fi
  85. install_bin="${native_base_dir}/bin"
  86. ReadGlobalJsonNativeTools
  87. if [[ ${#native_assets[@]} -eq 0 ]]; then
  88. echo "No native tools defined in global.json"
  89. exit 0;
  90. else
  91. native_installer_dir="$scriptroot/native"
  92. for tool in "${!native_assets[@]}"
  93. do
  94. tool_version=${native_assets[$tool]}
  95. installer_name="install-$tool.sh"
  96. installer_command="$native_installer_dir/$installer_name"
  97. installer_command+=" --baseuri $base_uri"
  98. installer_command+=" --installpath $install_bin"
  99. installer_command+=" --version $tool_version"
  100. echo $installer_command
  101. if [[ $force = true ]]; then
  102. installer_command+=" --force"
  103. fi
  104. if [[ $clean = true ]]; then
  105. installer_command+=" --clean"
  106. fi
  107. $installer_command
  108. if [[ $? != 0 ]]; then
  109. Write-PipelineTelemetryError -category 'NativeToolsBootstrap' "Execution Failed"
  110. exit 1
  111. fi
  112. done
  113. fi
  114. if [[ $clean = true ]]; then
  115. exit 0
  116. fi
  117. if [[ -d $install_bin ]]; then
  118. echo "Native tools are available from $install_bin"
  119. echo "##vso[task.prependpath]$install_bin"
  120. else
  121. Write-PipelineTelemetryError -category 'NativeToolsBootstrap' "Native tools install directory does not exist, installation failed"
  122. exit 1
  123. fi
  124. exit 0