From 17d8e71664094c105071841d50cd3284b1231602 Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Wed, 8 Mar 2023 14:58:55 -0800 Subject: [PATCH] Avoid reinstall of golang --- main-cookbook | 5 ++++- recipes/default/golang | 25 +++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/main-cookbook b/main-cookbook index b755049..cb4c2bb 100755 --- a/main-cookbook +++ b/main-cookbook @@ -75,7 +75,10 @@ if [ "$(uname)" == 'Darwin' ]; then fi recipe 'git' recipe 'vim-settings' -recipe 'golang' +if ! is_installed 'golang'; then + recipe 'golang' + set_installed 'golang' +fi recipe 'fish' if $install_ui_terms ; then recipe 'alacritty' diff --git a/recipes/default/golang b/recipes/default/golang index 286d9f3..a2da534 100755 --- a/recipes/default/golang +++ b/recipes/default/golang @@ -2,16 +2,25 @@ # Installs golang from the web -version="1.19" ARCH=$(uname -m) if [ "$ARCH" = "x86_64" ]; then ARCH=amd64 fi -if [[ "$UNAME_STR" == "Darwin" ]]; then - wget -P "$TMP_DIR/" "https://go.dev/dl/go${version}.darwin-$ARCH.pkg" - sudo installer -target / -pkg "$TMP_DIR/go${version}.darwin-$ARCH.pkg" -elif [[ "$UNAME_STR" == "Linux" ]]; then - wget -P "$TMP_DIR/" "https://go.dev/dl/go${version}.linux-$ARCH.tar.gz" - sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf "$TMP_DIR/go${version}.linux-$ARCH.tar.gz" -fi +function install_go() { + local version="1.20.2" + if command -v "go" > /dev/null 2>&1 && go version | grep "$version"; then + echo "Go version $version is already installed" + return 0 + fi + + if [[ "$UNAME_STR" == "Darwin" ]]; then + wget -P "$TMP_DIR/" "https://go.dev/dl/go${version}.darwin-$ARCH.pkg" + sudo installer -target / -pkg "$TMP_DIR/go${version}.darwin-$ARCH.pkg" + elif [[ "$UNAME_STR" == "Linux" ]]; then + wget -P "$TMP_DIR/" "https://go.dev/dl/go${version}.linux-$ARCH.tar.gz" + sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf "$TMP_DIR/go${version}.linux-$ARCH.tar.gz" + fi +} + +install_go