|
| 1 | +#! /usr/bin/env bash |
| 2 | + |
| 3 | +if [[ -f /etc/apt/sources.list.d/ros2.list ]] |
| 4 | +then |
| 5 | + tue-install-echo "Removing the old ROS2 apt sources" |
| 6 | + tue-install-pipe sudo rm -f /etc/apt/sources.list.d/ros2.list* || tue-install-error "Failed to remove old ROS2 apt sources" |
| 7 | +else |
| 8 | + tue-install-debug "Old ROS2 apt sources do not exist" |
| 9 | +fi |
| 10 | + |
| 11 | +ubuntu_name=$(lsb_release -cs) |
| 12 | + |
| 13 | +# Check whether universe is enabled |
| 14 | +if ! grep -h ^deb /etc/apt/sources.list 2>/dev/null | grep "${ubuntu_name} universe" -q |
| 15 | +then |
| 16 | + tue-install-echo "Enabling universe repository" |
| 17 | + tue-install-pipe sudo add-apt-repository universe || tue-install-error "Failed to enable universe repository" |
| 18 | + tue-install-apt-get-update |
| 19 | +else |
| 20 | + tue-install-debug "Universe repository is already enabled" |
| 21 | +fi |
| 22 | + |
| 23 | +ros_apt_source_pkg_name="ros2-apt-source" |
| 24 | + |
| 25 | +installed_version=$(dpkg -s ${ros_apt_source_pkg_name} 2>/dev/null | grep -F "Version" | awk '{print $2}') |
| 26 | +newest_version=$(curl -s https://api.github.com/repos/ros-infrastructure/ros-apt-source/releases/latest | grep -F "tag_name" | awk -F\" '{print $4}') |
| 27 | +needs_install=true |
| 28 | +if [[ -n ${installed_version} ]] |
| 29 | +then |
| 30 | + if [[ ${installed_version} == "${newest_version}~${ubuntu_name}" ]] |
| 31 | + then |
| 32 | + tue-install-debug "The most recent version of '${ros_apt_source_pkg_name}' is already installed '${installed_version}'" |
| 33 | + needs_install=false |
| 34 | + else |
| 35 | + tue-install-debug "Newer version, '${newest_version}', of '${ros_apt_source_pkg_name}' available, currently installed: '${installed_version}'" |
| 36 | + fi |
| 37 | +else |
| 38 | + tue-install-debug "No version of '${ros_apt_source_pkg_name}' installed" |
| 39 | +fi |
| 40 | + |
| 41 | +if [[ ${needs_install} == true ]] |
| 42 | +then |
| 43 | + tue-install-debug "Going to install ${ros_apt_source_pkg_name}" |
| 44 | + tue-install-pipe curl -L -o /tmp/${ros_apt_source_pkg_name}.deb "https://github.com/ros-infrastructure/ros-apt-source/releases/download/${newest_version}/${ros_apt_source_pkg_name}_${newest_version}.${ubuntu_name}_all.deb" || tue-install-error "Failed to download ROS2 apt source debian" |
| 45 | + tue-install-dpkg /tmp/${ros_apt_source_pkg_name}.deb |
| 46 | +fi |
| 47 | + |
0 commit comments