setup.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/bash
  2. # Copyright Epic Games, Inc. All Rights Reserved.
  3. BASH_LOCATION=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
  4. pushd "${BASH_LOCATION}" > /dev/null
  5. source common_utils.sh
  6. use_args $@
  7. # Azure specific fix to allow installing NodeJS from NodeSource
  8. if test -f "/etc/apt/sources.list.d/azure-cli.list"; then
  9. sudo touch /etc/apt/sources.list.d/nodesource.list
  10. sudo touch /usr/share/keyrings/nodesource.gpg
  11. sudo chmod 644 /etc/apt/sources.list.d/nodesource.list
  12. sudo chmod 644 /usr/share/keyrings/nodesource.gpg
  13. sudo chmod 644 /etc/apt/sources.list.d/azure-cli.list
  14. fi
  15. function check_version() { #current_version #min_version
  16. #check if same string
  17. if [ -z "$2" ] || [ "$1" = "$2" ]; then
  18. return 0
  19. fi
  20. local i current minimum
  21. IFS="." read -r -a current <<< $1
  22. IFS="." read -r -a minimum <<< $2
  23. # fill empty fields in current with zeros
  24. for ((i=${#current[@]}; i<${#minimum[@]}; i++))
  25. do
  26. current[i]=0
  27. done
  28. for ((i=0; i<${#current[@]}; i++))
  29. do
  30. if [[ -z ${minimum[i]} ]]; then
  31. # fill empty fields in minimum with zeros
  32. minimum[i]=0
  33. fi
  34. if ((10#${current[i]} > 10#${minimum[i]})); then
  35. return 1
  36. fi
  37. if ((10#${current[i]} < 10#${minimum[i]})); then
  38. return 2
  39. fi
  40. done
  41. # if got this far string is the same once we added missing 0
  42. return 0
  43. }
  44. function check_and_install() { #dep_name #get_version_string #version_min #install_command
  45. local is_installed=0
  46. log_msg "Checking for required $1 install"
  47. local current=$(echo $2 | sed -E 's/[^0-9.]//g')
  48. local minimum=$(echo $3 | sed -E 's/[^0-9.]//g')
  49. if [ $# -ne 4 ]; then
  50. log_msg "check_and_install expects 4 args (dep_name get_version_string version_min install_command) got $#"
  51. return -1
  52. fi
  53. if [ ! -z $current ]; then
  54. log_msg "Current version: $current checking >= $minimum"
  55. check_version "$current" "$minimum"
  56. if [ "$?" -lt 2 ]; then
  57. log_msg "$1 is installed."
  58. return 0
  59. else
  60. log_msg "Required install of $1 not found installing"
  61. fi
  62. fi
  63. if [ $is_installed -ne 1 ]; then
  64. echo "$1 installation not found installing..."
  65. start_process $4
  66. if [ $? -ge 1 ]; then
  67. echo "Installation of $1 failed try running `export VERBOSE=1` then run this script again for more details"
  68. exit 1
  69. fi
  70. fi
  71. }
  72. echo "Checking Matchmaker dependencies..."
  73. # navigate to Matchmaker root
  74. pushd ../.. > /dev/null
  75. node_version=""
  76. if [[ -f "${BASH_LOCATION}/node/bin/node" ]]; then
  77. node_version=$("${BASH_LOCATION}/node/bin/node" --version)
  78. fi
  79. check_and_install "node" "$node_version" "v16.4.2" "curl https://nodejs.org/dist/v16.14.2/node-v16.14.2-linux-x64.tar.gz --output node.tar.xz
  80. && tar -xf node.tar.xz
  81. && rm node.tar.xz
  82. && mv node-v*-linux-x64 \"${BASH_LOCATION}/node\""
  83. PATH="${BASH_LOCATION}/node/bin:$PATH"
  84. "${BASH_LOCATION}/node/lib/node_modules/npm/bin/npm-cli.js" install
  85. popd > /dev/null # Matchmaker
  86. popd > /dev/null # BASH_SOURCE
  87. echo "All Matchmaker dependencies up to date."