Skip to content

Commit 02e50a6

Browse files
committed
(bootstrap) update apt once
1 parent 5c2e670 commit 02e50a6

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

installer/bootstrap.bash

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
#! /usr/bin/env bash
22

3+
function conditional_apt_update
4+
{
5+
TUE_APT_GET_UPDATED_FILE=/tmp/tue_get_apt_get_updated
6+
if [[ ! -f ${TUE_APT_GET_UPDATED_FILE} ]]
7+
then
8+
echo -e "[tue-env](bootstrap) sudo apt-get update -qq"
9+
sudo apt-get update -qq || return 1
10+
touch ${TUE_APT_GET_UPDATED_FILE}
11+
fi
12+
return 0
13+
}
14+
315
function installed_or_install
416
{
517
# installed_or_install executable [package]
618
# Provide package name if it differs from executable name
7-
if [ -z "$1" ]
19+
if [[ -z "$1" ]]
820
then
921
echo "[bootstrap] Error! No package name provided to check for installation."
10-
exit 1
22+
return 1
1123
fi
1224
local executable package
13-
executable="$1"
14-
package="$1"
15-
[ -n "$2" ] && package="$2"
16-
hash "${executable}" 2> /dev/null || sudo apt-get install --assume-yes -qq "${package}"
25+
executable=$1
26+
package=$1
27+
[[ -n "$2" ]] && package=$2
28+
hash "${executable}" 2> /dev/null && return 0
29+
conditional_apt_update || { echo "[bootstrap] Error! Could not update apt-get."; return 1; }
30+
sudo apt-get install --assume-yes -qq "${package}" || { echo "[bootstrap] Error! Could not install ${package}."; return 1; }
31+
return 0
1732
}
1833

1934
# Make sure curl is installed
@@ -34,7 +49,7 @@ DISTRIB_RELEASE="$(lsb_release -sr)"
3449
if [ "${DISTRIB_ID}" != "Ubuntu" ]
3550
then
3651
echo "[bootstrap] Unsupported OS ${DISTRIB_ID}. Use Ubuntu."
37-
exit 1
52+
return 1
3853
fi
3954

4055
# Set ROS version
@@ -58,7 +73,7 @@ do
5873
;;
5974
* )
6075
echo "[tue-env](bootstrap) Error! Unknown argument '${i}' provided to bootstrap script."
61-
exit 1
76+
return 1
6277
;;
6378
esac
6479
done
@@ -80,7 +95,7 @@ case ${DISTRIB_RELEASE} in
8095
elif [[ -n "${ros_distro}" ]]
8196
then
8297
echo "[tue-env](bootstrap) Error! ROS ${ros_distro} is unsupported with tue-env."
83-
exit 1
98+
return 1
8499
else
85100
TUE_ROS_DISTRO="galactic"
86101
echo "[tue-env](bootstrap) Using default ROS_DISTRO '${TUE_ROS_DISTRO}' with ROS_VERSION '${TUE_ROS_VERSION}'"
@@ -92,7 +107,7 @@ case ${DISTRIB_RELEASE} in
92107
elif [[ -n "${ros_version}" ]]
93108
then
94109
echo "[tue-env](bootstrap) Error! ROS ${ros_version} is unsupported with tue-env."
95-
exit 1
110+
return 1
96111
else
97112
TUE_ROS_DISTRO="noetic"
98113
TUE_ROS_VERSION=1
@@ -103,7 +118,7 @@ case ${DISTRIB_RELEASE} in
103118
if [[ -n "${ros_version}" ]] && [[ "${ros_version}" -ne 2 ]]
104119
then
105120
echo "[tue-env](bootstrap) Error! Only ROS version 2 is supported with ubuntu 22.04 and newer"
106-
exit 1
121+
return 1
107122
fi
108123
TUE_ROS_VERSION=2
109124

@@ -116,15 +131,15 @@ case ${DISTRIB_RELEASE} in
116131
elif [[ -n "${ros_distro}" ]]
117132
then
118133
echo "[tue-env](bootstrap) Error! ROS ${ros_distro} is unsupported with tue-env."
119-
exit 1
134+
return 1
120135
else
121136
TUE_ROS_DISTRO="humble"
122137
echo "[tue-env](bootstrap) Using default ROS_DISTRO '${TUE_ROS_DISTRO}' with ROS_VERSION '${TUE_ROS_VERSION}'"
123138
fi
124139
;;
125140
*)
126141
echo "[tue-env](bootstrap) Ubuntu ${DISTRIB_RELEASE} is unsupported. Please use one of Ubuntu 20.04 or 22.04."
127-
exit 1
142+
return 1
128143
;;
129144
esac
130145

@@ -171,10 +186,10 @@ then
171186
fi
172187
else
173188
echo -e "[tue-env](bootstrap) Testing Pull Request"
174-
[ -z "${REF_NAME}" ] && { echo "Error! Environment variable REF_NAME is not set."; exit 1; }
189+
[ -z "${REF_NAME}" ] && { echo "Error! Environment variable REF_NAME is not set."; return 1; }
175190

176191
git clone -q --depth=10 "${env_url}" "${env_dir}"
177-
git -C "${env_dir}" fetch origin "${REF_NAME}"/"${PULL_REQUEST}"/merge:PULLREQUEST || { echo "Error! Could not fetch refs"; exit 1; }
192+
git -C "${env_dir}" fetch origin "${REF_NAME}"/"${PULL_REQUEST}"/merge:PULLREQUEST || { echo "Error! Could not fetch refs"; return 1; }
178193
git -C "${env_dir}" checkout PULLREQUEST
179194
fi
180195
else

0 commit comments

Comments
 (0)