11#! /usr/bin/env bash
22
3+ # local variables need to be declared before they are used and need to be lowercase
4+ # global variables which needs to be defined outside this script are in uppercase
5+
36function conditional_apt_update
47{
5- TUE_APT_GET_UPDATED_FILE=/tmp/tue_get_apt_get_updated
6- if [[ ! -f ${TUE_APT_GET_UPDATED_FILE} ]]
8+ local tue_get_apt_get_updated_file
9+ tue_get_apt_get_updated_file=/tmp/tue_get_apt_get_updated
10+ if [[ ! -f ${tue_get_apt_get_updated_file} ]]
711 then
812 echo " [tue-env](bootstrap) sudo apt-get update -qq"
913 sudo apt-get update -qq || return 1
10- touch ${TUE_APT_GET_UPDATED_FILE }
14+ touch ${tue_get_apt_get_updated_file }
1115 fi
1216 return 0
1317}
@@ -45,18 +49,21 @@ function main
4549 installed_or_install virtualenv python3-virtualenv
4650
4751 # Check if OS is Ubuntu
48- DISTRIB_ID=" $( lsb_release -si) "
49- DISTRIB_RELEASE=" $( lsb_release -sr) "
52+ local distrib_id distrib_release
53+ distrib_id=" $( lsb_release -si) "
54+ distrib_release=" $( lsb_release -sr) "
5055
51- if [[ " ${DISTRIB_ID } " != " Ubuntu" ]]
56+ if [[ " ${distrib_id } " != " Ubuntu" ]]
5257 then
53- echo " [tue-env](bootstrap) Unsupported OS ${DISTRIB_ID } . Use Ubuntu."
58+ echo " [tue-env](bootstrap) Unsupported OS ${distrib_id } . Use Ubuntu."
5459 return 1
5560 fi
5661
57- # Set ROS version
58- TUE_ROS_DISTRO=
59- TUE_ROS_VERSION=
62+ # Initialize variables
63+ local create_virtualenv targets_repo tue_ros_distro tue_ros_version
64+
65+ # Default values
66+ create_virtualenv=" true"
6067
6168 for i in " $@ "
6269 do
@@ -80,40 +87,40 @@ function main
8087 esac
8188 done
8289
83- case ${DISTRIB_RELEASE } in
90+ case ${distrib_release } in
8491 " 20.04" )
8592 if [[ " ${ros_version} " -eq 2 ]]
8693 then
87- TUE_ROS_VERSION =2
94+ tue_ros_version =2
8895 if [[ " ${ros_distro} " == " foxy" ]]
8996 then
90- TUE_ROS_DISTRO =" foxy"
97+ tue_ros_distro =" foxy"
9198 elif [[ " ${ros_distro} " == " galactic" ]]
9299 then
93- TUE_ROS_DISTRO =" galactic"
100+ tue_ros_distro =" galactic"
94101 elif [[ " ${ros_distro} " == " rolling" ]]
95102 then
96- TUE_ROS_DISTRO =" rolling"
103+ tue_ros_distro =" rolling"
97104 elif [[ -n " ${ros_distro} " ]]
98105 then
99106 echo " [tue-env](bootstrap) Error! ROS ${ros_distro} is unsupported with tue-env."
100107 return 1
101108 else
102- TUE_ROS_DISTRO =" galactic"
103- echo " [tue-env](bootstrap) Using default ROS_DISTRO '${TUE_ROS_DISTRO } ' with ROS_VERSION '${TUE_ROS_VERSION } '"
109+ tue_ros_distro =" galactic"
110+ echo " [tue-env](bootstrap) Using default ROS_DISTRO '${tue_ros_distro } ' with ROS_VERSION '${tue_ros_version } '"
104111 fi
105112 elif [[ " ${ros_version} " -eq 1 ]]
106113 then
107- TUE_ROS_DISTRO =" noetic"
108- TUE_ROS_VERSION =1
114+ tue_ros_distro =" noetic"
115+ tue_ros_version =1
109116 elif [[ -n " ${ros_version} " ]]
110117 then
111118 echo " [tue-env](bootstrap) Error! ROS ${ros_version} is unsupported with tue-env."
112119 return 1
113120 else
114- TUE_ROS_DISTRO =" noetic"
115- TUE_ROS_VERSION =1
116- echo " [tue-env](bootstrap) Using default ROS_DISTRO '${TUE_ROS_DISTRO } ' with ROS_VERSION '${TUE_ROS_VERSION } '"
121+ tue_ros_distro =" noetic"
122+ tue_ros_version =1
123+ echo " [tue-env](bootstrap) Using default ROS_DISTRO '${tue_ros_distro } ' with ROS_VERSION '${tue_ros_version } '"
117124 fi
118125 ;;
119126 " 22.04" )
@@ -122,43 +129,45 @@ function main
122129 echo " [tue-env](bootstrap) Error! Only ROS version 2 is supported with ubuntu 22.04 and newer"
123130 return 1
124131 fi
125- TUE_ROS_VERSION =2
132+ tue_ros_version =2
126133
127134 if [[ " ${ros_distro} " == " humble" ]]
128135 then
129- TUE_ROS_DISTRO =" humble"
136+ tue_ros_distro =" humble"
130137 elif [[ " ${ros_distro} " == " rolling" ]]
131138 then
132- TUE_ROS_DISTRO =" rolling"
139+ tue_ros_distro =" rolling"
133140 elif [[ -n " ${ros_distro} " ]]
134141 then
135142 echo " [tue-env](bootstrap) Error! ROS ${ros_distro} is unsupported with tue-env."
136143 return 1
137144 else
138- TUE_ROS_DISTRO =" humble"
139- echo " [tue-env](bootstrap) Using default ROS_DISTRO '${TUE_ROS_DISTRO } ' with ROS_VERSION '${TUE_ROS_VERSION } '"
145+ tue_ros_distro =" humble"
146+ echo " [tue-env](bootstrap) Using default ROS_DISTRO '${tue_ros_distro } ' with ROS_VERSION '${tue_ros_version } '"
140147 fi
141148 ;;
142149 * )
143- echo " [tue-env](bootstrap) Ubuntu ${DISTRIB_RELEASE } is unsupported. Please use one of Ubuntu 20.04 or 22.04."
150+ echo " [tue-env](bootstrap) Ubuntu ${distrib_release } is unsupported. Please use one of Ubuntu 20.04 or 22.04."
144151 return 1
145152 ;;
146153 esac
147154
148155 # Script variables
156+ local env_url env_targets_url env_dir workspace workspace_dir
149157 env_url=" https://github.com/tue-robotics/tue-env.git"
150158 { [[ -n " ${targets_repo} " ]] && env_targets_url=" ${targets_repo} " ; } || env_targets_url=" https://github.com/tue-robotics/tue-env-targets.git"
151159 [[ -n " ${create_virtualenv} " ]] || create_virtualenv=" true"
152160 env_dir=" ${HOME} /.tue"
153- workspace=" ros-${TUE_ROS_DISTRO } "
154- workspace_dir=" ${HOME} /ros/${TUE_ROS_DISTRO } "
161+ workspace=" ros-${tue_ros_distro } "
162+ workspace_dir=" ${HOME} /ros/${tue_ros_distro } "
155163
156164 # Move old environments and installer
157165 if [[ -d " ${env_dir} " ]] && [[ -z " ${CI} " ]]
158166 then
159- FILES=$( find " ${env_dir} " /user/envs -maxdepth 1 -type f)
167+ local files date_now
168+ files=$( find " ${env_dir} " /user/envs -maxdepth 1 -type f)
160169 date_now=$( date +%F_%R)
161- for env in ${FILES }
170+ for env in ${files }
162171 do
163172 mv -f " $( cat " ${env} " ) " " $( cat " ${env} " ) " ." ${date_now} "
164173 done
@@ -212,8 +221,8 @@ function main
212221 tue-env init " ${workspace} " " ${workspace_dir} " " --create-virtualenv=${create_virtualenv} " " --targets-url=${env_targets_url} "
213222
214223 # Configure environment
215- tue-env config " ${workspace} " set " TUE_ROS_DISTRO" " ${TUE_ROS_DISTRO } "
216- tue-env config " ${workspace} " set " TUE_ROS_VERSION" " ${TUE_ROS_VERSION } "
224+ tue-env config " ${workspace} " set " TUE_ROS_DISTRO" " ${tue_ros_distro } "
225+ tue-env config " ${workspace} " set " TUE_ROS_VERSION" " ${tue_ros_version } "
217226
218227 # Add loading of TU/e tools (tue-env, tue-get, etc) to bashrc
219228 # shellcheck disable=SC2088
0 commit comments