@@ -142,7 +142,8 @@ if ! cat /etc/group | grep -e "^golang:" > /dev/null 2>&1; then
142142fi
143143usermod -a -G golang " ${USERNAME} "
144144mkdir -p " ${TARGET_GOROOT} " " ${TARGET_GOPATH} "
145- if [ " ${TARGET_GO_VERSION} " != " none" ] && ! type go > /dev/null 2>&1 ; then
145+
146+ if [[ " ${TARGET_GO_VERSION} " != " none" ]] && [[ " $( go version) " != * " ${TARGET_GO_VERSION} " * ]]; then
146147 # Use a temporary locaiton for gpg keys to avoid polluting image
147148 export GNUPGHOME=" /tmp/tmp-gnupg"
148149 mkdir -p ${GNUPGHOME}
@@ -186,7 +187,7 @@ if [ "${TARGET_GO_VERSION}" != "none" ] && ! type go > /dev/null 2>&1; then
186187 tar -xzf /tmp/go.tar.gz -C " ${TARGET_GOROOT} " --strip-components=1
187188 rm -rf /tmp/go.tar.gz /tmp/go.tar.gz.asc /tmp/tmp-gnupg
188189else
189- echo " Go already installed. Skipping."
190+ echo " (!) Go is already installed with version ${TARGET_GO_VERSION} . Skipping."
190191fi
191192
192193# Install Go tools that are isImportant && !replacedByGopls based on
@@ -218,8 +219,10 @@ if [ "${INSTALL_GO_TOOLS}" = "true" ]; then
218219 (echo " ${GO_TOOLS} " | xargs -n 1 go ${go_install_command} -v )2>&1 | tee -a /usr/local/etc/vscode-dev-containers/go.log
219220
220221 # Move Go tools into path and clean up
221- mv /tmp/gotools/bin/* ${TARGET_GOPATH} /bin/
222- rm -rf /tmp/gotools
222+ if [ -d /tmp/gotools/bin ]; then
223+ mv /tmp/gotools/bin/* ${TARGET_GOPATH} /bin/
224+ rm -rf /tmp/gotools
225+ fi
223226
224227 # Install golangci-lint from precompiled binares
225228 if [ " $GOLANGCILINT_VERSION " = " latest" ] || [ " $GOLANGCILINT_VERSION " = " " ]; then
0 commit comments