#!/bin/bash

case $(uname -s) in
    Linux)
        # The Debian 12 golang isn't recent enough for gopls, so we install from a tarball.
        if ! [ -d /usr/local/go ]
        then
            sudo tar xfpC go1.23.5.linux-amd64.tar.gz /usr/local
        fi

        # shellcheck disable=SC2016
        if ! grep -F -x -q 'export PATH="$PATH":/usr/local/go/bin' ~/drs-additional
        then
            echo 'export PATH="$PATH":/usr/local/go/bin' >> ~/drs-additional
        fi

        # shellcheck disable=SC2016
        if ! grep -F -x -q 'export GOPATH="$HOME"/go' ~/drs-additional
        then
            echo 'export GOPATH="$HOME"/go' >> ~/drs-additional
        fi

        # shellcheck disable=SC2016
        if ! grep -F -x -q 'export PATH="$PATH:$GOPATH"/bin' ~/drs-additional
        then
            echo 'export PATH="$PATH:$GOPATH"/bin' >> ~/drs-additional
        fi
        ;;
    Darwin)
        brew install golang
        ;;
    *)
        echo "$0: unrecognized OS" 1>&2
        exit 1
        ;;
esac