Skip to content

Commit 48dec8b

Browse files
committed
Use direct web pages instead of GitHub API
The API is rate-restricted which might leave people frustrated.
1 parent daed243 commit 48dec8b

File tree

2 files changed

+72
-10
lines changed

2 files changed

+72
-10
lines changed

scripts/start_ursim.sh

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# POSSIBILITY OF SUCH DAMAGE.
3030

3131
PERSISTENT_BASE="${HOME}/.ursim"
32-
URCAP_VERSION="" # If not set, the latest version will be downloaded
32+
URCAP_VERSION="latest"
3333
IP_ADDRESS="192.168.56.101"
3434
PORT_FORWARDING_WITH_DASHBOARD="-p 30001-30004:30001-30004 -p 29999:29999"
3535
PORT_FORWARDING_WITHOUT_DASHBOARD="-p 30001-30004:30001-30004"
@@ -212,15 +212,58 @@ post_setup_e-series()
212212
post_setup_cb3
213213
}
214214

215+
get_effective_url()
216+
{
217+
curl -Ls -o /dev/null -w %\{url_effective\} "$1"
218+
}
219+
220+
get_version_from_release_url()
221+
{
222+
echo "$effective_url" | grep -oP '\d+\.\d+\.\d+' | head -n 1
223+
}
224+
225+
# Get the latest tag from a GitHub release page. Provide a link to its latest release e.g.
226+
# https://github.com/UniversalRobots/Universal_Robots_ExternalControl_URCapX/releases/latest
227+
get_latest_release_tag()
228+
{
229+
effective_url=$(get_effective_url "$1")
230+
get_version_from_release_url "$effective_url"
231+
}
232+
233+
# Get the URCAPX download URL for a given version
234+
#
235+
# Specify the desired version or "latest" as the first argument
236+
#
237+
# sets URCAPX_VERSION
238+
# sets URCAPX_DOWNLOAD_URL
239+
get_download_url_urcapx()
240+
{
241+
release_url="https://github.com/UniversalRobots/Universal_Robots_ExternalControl_URCapX/releases/$1"
242+
URCAPX_VERSION=$(get_latest_release_tag "$release_url")
243+
URCAPX_DOWNLOAD_URL="https://github.com/UniversalRobots/Universal_Robots_ExternalControl_URCapX/releases/download/$URCAPX_VERSION/external-control-$URCAPX_VERSION.urcapx"
244+
}
245+
246+
# Get the URCAPX download URL for a given version
247+
#
248+
# Specify the desired version or "latest" as the first argument
249+
#
250+
# sets URCAPX_VERSION
251+
# sets URCAPX_DOWNLOAD_URL
252+
get_download_url_urcap()
253+
{
254+
release_url="https://github.com/UniversalRobots/Universal_Robots_ExternalControl_URCap/releases/$1"
255+
URCAP_VERSION=$(get_latest_release_tag "$release_url")
256+
URCAP_DOWNLOAD_URL="https://github.com/UniversalRobots/Universal_Robots_ExternalControl_URCap/releases/download/v$URCAP_VERSION/externalcontrol-$URCAP_VERSION.jar"
257+
}
258+
215259
post_setup_polyscopex()
216260
{
217-
urcapx_download_url=$(curl -s https://api.github.com/repos/UniversalRobots/Universal_Robots_ExternalControl_URCapX/releases/latest | grep "browser_download_url.*urcapx" | cut -d ":" -f 2,3 | tr -d "\"[:space:]")
218-
URCAPX_VERSION=$(echo "$urcapx_download_url" | grep -oP '\d+\.\d+\.\d+' | head -n 1)
261+
get_download_url_urcapx latest
219262
mkdir -p "${URCAP_STORAGE}"
220-
urcapx_file="${URCAP_STORAGE}/external_control-$URCAPX_VERSION.urcapx"
263+
urcapx_file="${URCAP_STORAGE}/external-control-$URCAPX_VERSION.urcapx"
221264
if [[ ! -f "$urcapx_file" ]]; then
222265
echo "Downloading External Control URCapX version ${URCAPX_VERSION}"
223-
curl -L -o "$urcapx_file" "$urcapx_download_url"
266+
curl -L -o "$urcapx_file" "$URCAPX_DOWNLOAD_URL"
224267
fi
225268

226269
echo -ne "Starting URSim. Waiting for UrService to be up..."
@@ -383,13 +426,10 @@ main() {
383426
PROGRAM_STORAGE=$(realpath "$PROGRAM_STORAGE")
384427

385428
# Download external_control URCap
386-
if [[ -z "$URCAP_VERSION" ]]; then
387-
urcap_download_url=$(curl -s https://api.github.com/repos/UniversalRobots/Universal_Robots_ExternalControl_URCap/releases/latest | grep "browser_download_url.*jar" | cut -d ":" -f 2,3 | tr -d "\"[:space:]")
388-
URCAP_VERSION=$(echo "$urcap_download_url" | grep -oP '\d+\.\d+\.\d+' | head -n 1)
389-
fi
429+
get_download_url_urcap $URCAP_VERSION
390430
if [[ ! -f "${URCAP_STORAGE}/externalcontrol-${URCAP_VERSION}.jar" ]]; then
391431
echo "Downloading and installing External Control URCap version ${URCAP_VERSION}"
392-
curl -L -o "${URCAP_STORAGE}/externalcontrol-${URCAP_VERSION}.jar" "$urcap_download_url"
432+
curl -L -o "${URCAP_STORAGE}/externalcontrol-${URCAP_VERSION}.jar" "$URCAP_DOWNLOAD_URL"
393433
fi
394434
docker_cmd="docker run --rm -d --net ursim_net --ip $IP_ADDRESS\
395435
-v ${URCAP_STORAGE}:/urcaps \

tests/test_start_ursim.bats

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ setup() {
77
source $DIR/../scripts/start_ursim.sh
88
}
99

10+
@test "test_get_version_from_release_url" {
11+
effective_url="https://github.com/UniversalRobots/Universal_Robots_ExternalControl_URCapX/releases/0.1.0"
12+
13+
VERSION=$(get_version_from_release_url "$effective_url")
14+
15+
[ "$VERSION" = "0.1.0" ]
16+
}
17+
18+
@test "test_get_download_url_urcapx" {
19+
get_download_url_urcapx "0.1.0"
20+
echo "Download URL: $URCAPX_DOWNLOAD_URL"
21+
echo "URCAPX_VERSION: $URCAPX_VERSION"
22+
[ "$URCAPX_DOWNLOAD_URL" = "https://github.com/UniversalRobots/Universal_Robots_ExternalControl_URCapX/releases/download/0.1.0/external-control-0.1.0.urcapx" ]
23+
}
24+
25+
@test "test_get_download_url_urcap" {
26+
get_download_url_urcap "1.0.5"
27+
echo "Download URL: $URCAP_DOWNLOAD_URL"
28+
echo "URCAP_VERSION: $URCAP_VERSION"
29+
[ "$URCAP_DOWNLOAD_URL" = "https://github.com/UniversalRobots/Universal_Robots_ExternalControl_URCap/releases/download/v1.0.5/externalcontrol-1.0.5.jar" ]
30+
}
31+
1032
@test "test get_series_from_model" {
1133
get_series_from_model "ur10e"
1234
echo "ROBOT_SERIES: $ROBOT_SERIES"

0 commit comments

Comments
 (0)