install-ubuntu-build-tools.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. # This script must be run as root
  8. if [[ $EUID -ne 0 ]]
  9. then
  10. echo "This script must be run as root (sudo)"
  11. exit 1
  12. fi
  13. #
  14. # Make sure we are installing on a supported ubuntu distro
  15. #
  16. lsb_release -c >/dev/null 2>&1
  17. if [ $? -ne 0 ]
  18. then
  19. echo This script is only supported on Ubuntu Distros
  20. exit 1
  21. fi
  22. #
  23. # Get Ubuntu version data
  24. #
  25. UBUNTU_DISTRO="$(lsb_release -sc)"
  26. UBUNTU_VER="$(lsb_release -sr)"
  27. if [ "$UBUNTU_DISTRO" == "bionic" ] || [ "$UBUNTU_DISTRO" == "focal" ] || [ "$UBUNTU_DISTRO" == "jammy" ] || [ "$UBUNTU_DISTRO" == "noble" ]
  28. then
  29. echo "Setup for Ubuntu $UBUNTU_VER LTS ($UBUNTU_DISTRO)"
  30. else
  31. echo "Unsupported OS version - $UBUNTU_DISTRO"
  32. exit 1
  33. fi
  34. #
  35. # Add Ubuntu universe repo
  36. #
  37. apt install software-properties-common
  38. add-apt-repository universe
  39. #
  40. # Install curl if its not installed
  41. #
  42. curl --version >/dev/null 2>&1
  43. if [ $? -ne 0 ]
  44. then
  45. echo "Installing curl"
  46. apt-get install curl -y
  47. fi
  48. #
  49. # Add the kitware repository for cmake if necessary
  50. #
  51. KITWARE_REPO_COUNT=$(cat /etc/apt/sources.list | grep ^deb | grep https://apt.kitware.com/ubuntu/ | wc -l)
  52. MIN_CMAKE_VER=3.22
  53. if [ $KITWARE_REPO_COUNT -eq 0 ]
  54. then
  55. echo Adding Kitware Repository for CMake (Min version $MIN_CMAKE_VER)
  56. wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null
  57. CMAKE_DEB_REPO="'deb https://apt.kitware.com/ubuntu/ $UBUNTU_DISTRO main'"
  58. # Add the appropriate kitware repository to apt
  59. if [ "$UBUNTU_DISTRO" == "bionic" ] || [ "$UBUNTU_DISTRO" == "focal" ]
  60. then
  61. apt-add-repository "deb https://apt.kitware.com/ubuntu/ $UBUNTU_DISTRO main"
  62. elif [ "$UBUNTU_DISTRO" == "jammy" ]
  63. then
  64. # Ubuntu 22.04 already has an acceptable version of cmake 3.22.1 (https://packages.ubuntu.com/jammy/cmake)
  65. echo "Ubuntu 22.04's cmake package already at version 3.22.1 (Which is greater than $MIN_CMAKE_VER)"
  66. elif [ "$UBUNTU_DISTRO" == "noble" ]
  67. then
  68. # Ubuntu 24.04 already has an acceptable version of cmake 3.28.3 (https://packages.ubuntu.com/noble/cmake)
  69. echo "Ubuntu 24.04's cmake package already at version 3.28.3 (Which is greater than $MIN_CMAKE_VER)"
  70. fi
  71. else
  72. echo Kitware Repository repo already set
  73. fi
  74. echo "Installing cmake"
  75. apt-get install cmake -y
  76. #
  77. # Add Amazon Corretto repository to install the necessary JDK for Jenkins and Android
  78. #
  79. CORRETTO_REPO_COUNT=$(cat /etc/apt/sources.list | grep ^dev | grep https://apt.corretto.aws | wc -l)
  80. if [ $CORRETTO_REPO_COUNT -eq 0 ]
  81. then
  82. echo Adding Corretto Repository for JDK
  83. wget -O- https://apt.corretto.aws/corretto.key | apt-key add -
  84. add-apt-repository 'deb https://apt.corretto.aws stable main'
  85. else
  86. echo Corretto repo already set
  87. fi
  88. #
  89. # Add the repository for ROS2
  90. #
  91. ROS2_REPO_COUNT=$(cat /etc/apt/sources.list | grep ^deb | grep http://packages.ros.org/ros2/ubuntu | wc -l)
  92. if [ $ROS2_REPO_COUNT -eq 0 ]
  93. then
  94. echo Adding ROS2 Repository
  95. curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
  96. echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $UBUNTU_DISTRO main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
  97. else
  98. echo ROS2 repo already set
  99. fi
  100. #
  101. # Finally, update the sources repos
  102. #
  103. apt-get update