Skip to content

Commit b785950

Browse files
[ros*-setup] various fixes (#475)
- Fix grepping on sources.list - Allow use of GITHUB_TOKEN to prevent rate limit
2 parents b683b1b + 5ec1dfa commit b785950

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

ros1-setup/install.bash

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fi
1111
ubuntu_name=$(lsb_release -cs)
1212

1313
# Check whether universe is enabled
14-
if ! grep -h ^deb /etc/apt/sources.list 2>/dev/null | grep "${ubuntu_name} universe" -q
14+
if ! grep -h ^deb /etc/apt/sources.list 2>/dev/null | grep -P "${ubuntu_name}[a-z\-]* (?:[a-z ]*(?:[a-z]+(?: [a-z]+)*)) universe" -q
1515
then
1616
tue-install-echo "Enabling universe repository"
1717
tue-install-pipe sudo add-apt-repository universe || tue-install-error "Failed to enable universe repository"
@@ -23,7 +23,19 @@ fi
2323
ros_apt_source_pkg_name="ros-apt-source"
2424

2525
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}')
26+
27+
CURL_ARGS=("-H" "Accept: application/vnd.github+json")
28+
if [[ -n ${GITHUB_TOKEN} ]]
29+
then
30+
CURL_ARGS+=("-H" "Authorization: Bearer ${GITHUB_TOKEN}")
31+
fi
32+
newest_version=$(curl "${CURL_ARGS[@]}" -sL https://api.github.com/repos/ros-infrastructure/ros-apt-source/releases/latest | jq -r '.tag_name')
33+
34+
if [[ ${newest_version} == "null" ]]
35+
then
36+
tue-install-error "Failed to get the newest version of '${ros_apt_source_pkg_name}'"
37+
fi
38+
2739
needs_install=true
2840
if [[ -n ${installed_version} ]]
2941
then

ros2-setup/install.bash

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ then
2525
needs_enabling_universe=false
2626
fi
2727
else
28-
if ! grep -h ^deb /etc/apt/sources.list 2>/dev/null | grep "${ubuntu_name} (?:[a-z ]*(?:[a-z]+(?: [a-z]+)*)) universe" -q
28+
if ! grep -h ^deb /etc/apt/sources.list 2>/dev/null | grep -P "${ubuntu_name}[a-z\-]* (?:[a-z ]*(?:[a-z]+(?: [a-z]+)*)) universe" -q
2929
then
3030
tue-install-debug "No universe found in the sources.list, going to enable the universe repository"
3131
else
3232
tue-install-debug "Universe found in the sources.list, no need to enable it"
33+
needs_enabling_universe=false
3334
fi
3435
fi
3536

@@ -45,7 +46,19 @@ fi
4546
ros_apt_source_pkg_name="ros2-apt-source"
4647

4748
installed_version=$(dpkg -s ${ros_apt_source_pkg_name} 2>/dev/null | grep -F "Version" | awk '{print $2}')
48-
newest_version=$(curl -s https://api.github.com/repos/ros-infrastructure/ros-apt-source/releases/latest | grep -F "tag_name" | awk -F\" '{print $4}')
49+
50+
CURL_ARGS=("-H" "Accept: application/vnd.github+json")
51+
if [[ -n ${GITHUB_TOKEN} ]]
52+
then
53+
CURL_ARGS+=("-H" "Authorization: Bearer ${GITHUB_TOKEN}")
54+
fi
55+
newest_version=$(curl "${CURL_ARGS[@]}" -sL https://api.github.com/repos/ros-infrastructure/ros-apt-source/releases/latest | jq -r '.tag_name')
56+
57+
if [[ ${newest_version} == "null" ]]
58+
then
59+
tue-install-error "Failed to get the newest version of '${ros_apt_source_pkg_name}'"
60+
fi
61+
4962
needs_install=true
5063
if [[ -n ${installed_version} ]]
5164
then

0 commit comments

Comments
 (0)