setup.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. fi
  69. fi
  70. }
  71. echo "Checking Pixel Streaming Server dependencies."
  72. # navigate to SignallingWebServer root
  73. pushd ../.. > /dev/null
  74. node_version=""
  75. if [[ -f "${BASH_LOCATION}/node/bin/node" ]]; then
  76. node_version=$("${BASH_LOCATION}/node/bin/node" --version)
  77. fi
  78. 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
  79. && tar -xf node.tar.xz
  80. && rm node.tar.xz
  81. && mv node-v*-linux-x64 \"${BASH_LOCATION}/node\""
  82. PATH="${BASH_LOCATION}/node/bin:$PATH"
  83. "${BASH_LOCATION}/node/lib/node_modules/npm/bin/npm-cli.js" install
  84. popd > /dev/null # SignallingWebServer
  85. popd > /dev/null # BASH_SOURCE
  86. #command #dep_name #get_version_string #version_min #install command
  87. coturn_version=$(if command -v turnserver &> /dev/null; then echo 1; else echo 0; fi)
  88. if [ $coturn_version -eq 0 ]; then
  89. if ! command -v apt-get &> /dev/null; then
  90. echo "Setup for the scripts is designed for use with distros that use the apt-get package manager" \
  91. "if you are seeing this message you will have to update \"${BASH_LOCATION}/setup.sh\" with\n" \
  92. "a package manger and the equivalent packages for your distribution. Please follow the\n" \
  93. "instructions found at https://pkgs.org/search/?q=coturn to install Coturn for your specific distribution"
  94. exit 1
  95. else
  96. if [ `id -u` -eq 0 ]; then
  97. check_and_install "coturn" "$coturn_version" "1" "apt-get install -y coturn"
  98. else
  99. check_and_install "coturn" "$coturn_version" "1" "sudo apt-get install -y coturn"
  100. fi
  101. fi
  102. fi