Skip to content

Commit db2546d

Browse files
build: refactor error handling on linux
Add yq as well
1 parent bcdddcf commit db2546d

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

Makefile

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
# ENV VARS
88
export SHELL := $(shell which sh)
9-
export ARCH := $(shell arch)
109
export UNAME := $(shell uname -s)
11-
export ASDF_VERSION := v0.14.1
10+
export ASDF_VERSION := v0.13.1
1211

1312
# check commands and OS
1413
ifeq ($(UNAME), Darwin)
@@ -26,8 +25,9 @@ CYAN := $(shell tput -Txterm setaf 6)
2625
RESET := $(shell tput -Txterm sgr0)
2726

2827
# Usage: $(call check_bin,command_name)
28+
# Returns empty string if command not found, command path if found
2929
define check_bin
30-
! command -v $(1) >/dev/null 2>&1
30+
$(shell which $(1) 2>/dev/null)
3131
endef
3232

3333
# Usage: $(call brew_install,package_name)
@@ -39,7 +39,7 @@ define brew_install
3939
"go-task") binary_name="task" ;; \
4040
*) binary_name="$(1)" ;; \
4141
esac; \
42-
if [ -z "$(call check_bin,$$binary_name)" ]; then \
42+
if ! command -v $$binary_name >/dev/null 2>&1; then \
4343
echo "Installing $(1)..."; \
4444
brew install $(1); \
4545
else \
@@ -52,9 +52,7 @@ endef
5252

5353
# targets
5454
.PHONY: all
55-
all: help install ## run all targets
56-
57-
install: xcode asdf brew devbox jq pre-commit sccache task ## install dependencies
55+
all: help asdf xcode brew jq pre-commit sccache task yq ## run all targets
5856

5957
xcode: ## install xcode command line tools
6058
ifeq ($(UNAME), Darwin)
@@ -70,27 +68,34 @@ endif
7068

7169
brew: xcode ## install homebrew
7270
ifeq ($(UNAME), Darwin)
73-
@if $(call check_bin,brew); then \
71+
@if ! command -v brew >/dev/null 2>&1; then \
7472
echo "Installing Homebrew..."; \
7573
/bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; \
7674
else \
7775
echo "brew already installed."; \
7876
fi
7977
else ifeq ($(UNAME), Linux)
80-
@if [ "$(ARCH)" = "aarch64" ]; then \
81-
echo "Homebrew on Linux is not supported on ARM processors."; \
82-
elif $(call check_bin,brew) && [ "$(ID_LIKE)" = "debian" ]; then \
83-
echo "Installing Homebrew..."; \
84-
/bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; \
78+
@if [ "${ID_LIKE}" = "debian" ]; then \
79+
if ! command -v brew >/dev/null 2>&1; then \
80+
echo "Installing Homebrew..."; \
81+
/bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; \
82+
echo ""; \
83+
echo "To add Homebrew to your PATH, run these commands:"; \
84+
echo 'eval "$$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"'; \
85+
echo 'Add to ~/.profile or ~/.bashrc:'; \
86+
echo 'eval "$$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"'; \
87+
else \
88+
echo "brew already installed."; \
89+
fi \
8590
else \
86-
echo "brew already installed."; \
91+
echo "brew not supported on this Linux distribution."; \
8792
fi
8893
else
8994
@echo "brew not supported."
9095
endif
9196

9297
asdf: xcode ## install asdf
93-
@if $(call check_bin,asdf); then \
98+
@if ! command -v asdf >/dev/null 2>&1; then \
9499
echo "Installing asdf..."; \
95100
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch ${ASDF_VERSION}; \
96101
echo "To use asdf, add the following to your shell rc (.bashrc/.zshrc):"; \
@@ -101,14 +106,6 @@ asdf: xcode ## install asdf
101106
echo "asdf already installed."; \
102107
fi
103108

104-
devbox: ## install devbox
105-
@if $(call check_bin,devbox); then \
106-
echo "Installing devbox..."; \
107-
curl -fsSL https://get.jetpack.io/devbox | bash; \
108-
else \
109-
echo "devbox already installed."; \
110-
fi
111-
112109
jq: brew ## install jq
113110
$(call brew_install,jq)
114111

@@ -118,19 +115,13 @@ pre-commit: brew ## install pre-commit
118115
sccache: brew ## install sccache
119116
$(call brew_install,sccache)
120117

121-
task: ## install taskfile
122-
ifeq ($(UNAME), Darwin)
118+
task: brew ## install taskfile
123119
$(call brew_install,go-task)
124-
else ifeq ($(UNAME), Linux)
125-
@if $(call check_bin,task); then \
126-
echo "Installing task..."; \
127-
sh -c "$$(curl -sl https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin; \
128-
else \
129-
echo "task already installed."; \
130-
fi
131-
else
132-
@echo "task installation not supported on this OS."
133-
endif
120+
121+
yq: brew ## install yq
122+
$(call brew_install,yq)
123+
124+
install: xcode asdf brew jq pre-commit sccache task yq ## install dependencies
134125

135126
help: ## show this help
136127
@echo ''

0 commit comments

Comments
 (0)