Last active
May 31, 2022 18:36
-
-
Save muihlinn/23bb6fdcb0100810bc3f2b60f9fd6d8d to your computer and use it in GitHub Desktop.
Install golang from a makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------------------------------------------ | |
# golang | |
# Install / update latest release | |
# ------------------------------------------------------------------------ | |
# https://github.com/canha/golang-tools-install-script/blob/master/goinstall.sh | |
# TODO: assumes it uses /bin/bash | |
# TODO: Make all downloads happens into a place for easy cleans | |
go-path = /usr/local/go | |
go-libs = /usr/local/share/go/ | |
go-arch = linux-amd64 | |
go-url = dl/.+$(go-arch)\.tar\.gz | |
# URL to the latest go version | |
go-dl = $(shell curl -s -N https://go.dev/dl/ | grep -oE '$(go-url)' | head -n1) | |
go-latest= $(shell grep -ioE 'go[0-9.]+' <<< '$(go-dl)' | sed 's/\.$$//' ) | |
go-local = $(shell go version | awk '{ print $$3; }') | |
go-file = $(go-latest).$(go-arch).tar.gz | |
golang: | |
@echo "Looking for latest go version..." | |
@echo "path $(go-path) " | |
@echo "libs $(go-libs) " | |
@echo "arch $(go-arch) " | |
@echo "url $(go-url) " | |
@echo "dl $(go-dl) " | |
@echo "latest $(go-latest) " | |
@echo "local $(go-local) " | |
@echo "file $(go-file) " | |
@if [ $(go-latest) == $(go-local) ] ; then \ | |
echo "You already have installed the latest version."; \ | |
elif [ "$(go-latest)" > "$(go-local)" ]; then \ | |
wget -c https://golang.org/$(go-dl); \ | |
echo "Remove go directory if exists"; \ | |
if [ -d $(go-path) ]; then \ | |
sudo rm -rf $(go-path); \ | |
fi; \ | |
echo "Proceed to install"; \ | |
if [ ! -d $(go-path) ]; then \ | |
sudo mkdir -p $(go-path); \ | |
fi; \ | |
if [ ! -d $(go-libs) ]; then \ | |
sudo mkdir -p $(go-libs); \ | |
fi; \ | |
sudo tar -C $(go-path) --strip-components=1 -xzf $(go-file); \ | |
fi | |
all: golang | |
# // TODO: clean downloads | |
clean: | |
.PHONY: all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment