~whereswaldon/gover

8684e6476e6027d63e8e085041f2b8330be9a8e0 — Chris Waldon 8 months ago 9c9da37
feat: support macOS and FreeBSD
2 files changed, 16 insertions(+), 5 deletions(-)

M README.md
M gover
M README.md => README.md +4 -3
@@ 1,9 1,10 @@
# gover

A simple shell script for installing and switching between go versions
on Linux. Minor tweaks required for macOS and *BSD support.
on Linux, FreeBSD, and macOS.

Currently only supports x86_64.
Currently only supports x86_64, but contributions to improve this are
welcome.

## Prerequisites



@@ 20,7 21,7 @@ Download the script and put it into any `bin` directory that is in your `$PATH`.
If you're using the default installation prefix, `~/.local/bin` will do.

```
curl -o ~/.local/bin/gover https://git.sr.ht/~whereswaldon/gover/blob/main/gover
curl --tlsv1.2 -o ~/.local/bin/gover https://git.sr.ht/~whereswaldon/gover/blob/main/gover
chmod +x ~/.local/bin/gover
```


M gover => gover +12 -2
@@ 3,9 3,15 @@

set -eu

current_os() {
    uname | tr '[:upper:]' '[:lower:]'
}

MINOR=${1:-14}
PATCH=${2:-6}
PREFIX=${PREFIX:-$HOME/.local}
GOOS=$(current_os)
GOARCH=amd64 # TODO: find a portable way to determine this without go installed

# version_dir emits the directory into which a particular go
# version should be installed


@@ 28,8 34,12 @@ install_version() {
    PATCH=$2
    LIB_DIR=$(version_dir "$MINOR" "$PATCH")
    mkdir -p "$LIB_DIR"
    curl -L "https://golang.org/dl/go1.$MINOR.$PATCH.linux-amd64.tar.gz"\
        | tar --strip-components=1 -xzC "$LIB_DIR"
    if ! curl -L "https://golang.org/dl/go1.$MINOR.$PATCH.$GOOS-$GOARCH.tar.gz"\
        | tar --strip-components=1 -xzC "$LIB_DIR"; then
            echo "Couldn't download Go 1.$MINOR.$PATCH. Are you sure it exists?"
            rm -rf "$LIB_DIR"
            return 1
    fi
}

# activate_version symlinks a particular version of go to be the active