|
1 | 1 | .DEFAULT_GOAL := help |
2 | | -SHELL := $(shell which bash) |
3 | | -UNAME := $(shell uname -s) |
| 2 | +.ONESHELL: |
| 3 | +export SHELL := $(shell which sh) |
| 4 | +# .SHELLFLAGS := -eu -o pipefail -c |
| 5 | +# MAKEFLAGS += --warn-undefined-variables |
4 | 6 |
|
| 7 | +# ENV VARS |
| 8 | +export UNAME := $(shell uname -s) |
| 9 | + |
| 10 | +ifeq ($(UNAME), Darwin) |
| 11 | + export XCODE := $(shell xcode-select --install >/dev/null 2>&1; echo $$?) |
| 12 | +endif |
| 13 | + |
| 14 | +ifeq ($(UNAME), Darwin) |
| 15 | + export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK := 1 |
| 16 | +endif |
| 17 | + |
| 18 | +ifeq ($(shell command -v brew >/dev/null 2>&1; echo $$?), 0) |
| 19 | + export BREW := $(shell which brew) |
| 20 | +endif |
| 21 | + |
| 22 | +ifeq ($(shell command -v python >/dev/null 2>&1; echo $$?), 0) |
| 23 | + export PYTHON := $(shell which python3) |
| 24 | +endif |
| 25 | + |
| 26 | +ifeq ($(shell command -v pip >/dev/null 2>&1; echo $$?), 0) |
| 27 | + export PIP := $(shell which pip3) |
| 28 | +endif |
| 29 | + |
| 30 | +ifneq (,$(wildcard /etc/os-release)) |
| 31 | + include /etc/os-release |
| 32 | +endif |
| 33 | + |
| 34 | +# colors |
5 | 35 | GREEN := $(shell tput -Txterm setaf 2) |
6 | 36 | YELLOW := $(shell tput -Txterm setaf 3) |
7 | 37 | WHITE := $(shell tput -Txterm setaf 7) |
8 | 38 | CYAN := $(shell tput -Txterm setaf 6) |
9 | 39 | RESET := $(shell tput -Txterm sgr0) |
10 | 40 |
|
| 41 | +# targets |
11 | 42 | .PHONY: all |
| 43 | +all: ansible sanity-check git help homebrew just install xcode |
12 | 44 |
|
13 | | -all: check help homebrew just install xcode |
| 45 | +# TODO: QA Linux (Debian/Ubuntu) |
| 46 | +# * cf. `distrobox create --name i-use-arch-btw --image archlinux:latest && distrobox enter i-use-arch-btw` |
| 47 | +# * || `distrobox create --name debby --image debian:stable && distrobox enter debby` |
14 | 48 |
|
15 | | -check: ## verify running on macOS |
16 | | - @echo "Verifying macOS..." |
17 | | - $(shell [[ "${UNAME}" != "Darwin" ]] && echo "Not running on macOS"; exit 1) |
18 | | - @echo "Success!" |
| 49 | +sanity-check: ## output environment variables |
| 50 | + @echo "Checking environment..." |
| 51 | + @echo "UNAME: ${UNAME}" |
| 52 | + @echo "SHELL: ${SHELL}" |
| 53 | + @echo "ID: ${ID}" |
| 54 | + @echo "XCODE: ${XCODE}" |
| 55 | + @echo "BREW: ${BREW}" |
| 56 | + @echo "HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: ${HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK}" |
| 57 | + @echo "PYTHON: ${PYTHON}" |
| 58 | + @echo "PIP: ${PIP}" |
19 | 59 |
|
20 | | -xcode: check ## install xcode command line tools |
| 60 | +xcode: ## install xcode command line tools |
21 | 61 | @echo "Installing Xcode command line tools..." |
22 | | - $(shell xcode-select --install) |
| 62 | + if [ "${UNAME}" == "Darwin" ] && [ "${XCODE}" -ne 1 ]; then \ |
| 63 | + xcode-select --install; \ |
| 64 | + fi |
23 | 65 |
|
24 | | -homebrew: check ## install homebrew |
| 66 | +homebrew: ## install homebrew |
25 | 67 | @echo "Installing Homebrew..." |
26 | | - $(shell /bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)") |
| 68 | + if [ "${UNAME}" == "Darwin" ] && [ -z "${BREW}" ]; then \ |
| 69 | + /bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; \ |
| 70 | + fi |
| 71 | + |
| 72 | +git: ## install git |
| 73 | + @echo "Installing Git..." |
| 74 | + if [ "${UNAME}" == "Darwin" ] && [ "$(command -v brew >/dev/null 2>&1; echo $?)" -eq 0 ]; then \ |
| 75 | + brew install git; \ |
| 76 | + elif [ "${ID}" == "ubuntu" ]; then \ |
| 77 | + sudo apt install -y git; \ |
| 78 | + elif [ "${ID}" == "fedora" ]; then \ |
| 79 | + sudo dnf install -y git; \ |
| 80 | + elif [ "${ID}" == "arch" ]; then \ |
| 81 | + yes | sudo pacman -S git; \ |
| 82 | + fi |
| 83 | + |
| 84 | +python: ## install python |
| 85 | + @echo "Installing Python..." |
| 86 | + if [ "${UNAME}" == "Darwin" ] && [ -z "${PYTHON}" ]; then \ |
| 87 | + brew install python; \ |
| 88 | + elif [ "${ID}" == "ubuntu" ]; then \ |
| 89 | + sudo apt install -y python3; \ |
| 90 | + elif [ "${ID}" == "fedora" ]; then \ |
| 91 | + sudo dnf install -y python3; \ |
| 92 | + elif [ "${ID}" == "arch" ]; then \ |
| 93 | + yes | sudo pacman -S python; \ |
| 94 | + fi |
| 95 | + |
| 96 | +pip: python ## install pip |
| 97 | + @echo "Installing Pip..." |
| 98 | + if [ "${UNAME}" == "Darwin" ] && [ -z "${PYTHON})" ]; then \ |
| 99 | + brew install python; \ |
| 100 | + elif [ "${ID}" == "ubuntu" ] && [ -z "${PIP}" ]; then \ |
| 101 | + sudo apt install -y python3-pip; \ |
| 102 | + elif [ "${ID}" == "fedora" ] && [ -z "${PIP}" ]; then \ |
| 103 | + sudo dnf install -y python3-pip; \ |
| 104 | + elif [ "${ID}" == "arch" ] && [ -z "${PIP}" ]; then \ |
| 105 | + yes | sudo pacman -S python-pip; \ |
| 106 | + fi \ |
| 107 | + |
| 108 | +ansible: pip ## install ansible |
| 109 | + @echo "Installing Ansible..." |
| 110 | + if [ "${UNAME}" == "Darwin" ]; then \ |
| 111 | + brew install ansible ansible-lint; \ |
| 112 | + else \ |
| 113 | + python3 -m pip install ansible ansible-lint; \ |
| 114 | + sudo touch /var/log/ansible.log; \ |
| 115 | + sudo chmod 666 /var/log/ansible.log; \ |
| 116 | + fi |
27 | 117 |
|
28 | | -just: check ## install justfile |
| 118 | +just: ## install justfile |
29 | 119 | @echo "Installing Justfile..." |
30 | | - $(shell brew install just) |
| 120 | + if [ "${UNAME}" == "Darwin" ]; then \ |
| 121 | + brew install just; \ |
| 122 | + elif [ "${ID}" == "ubuntu" ]; then \ |
| 123 | + sudo apt install -y just; \ |
| 124 | + elif [ "${ID}" == "fedora" ]; then \ |
| 125 | + sudo dnf install -y just; \ |
| 126 | + elif [ "${ID}" == "arch" ]; then \ |
| 127 | + yes | sudo pacman -S just; \ |
| 128 | + fi |
31 | 129 |
|
32 | | -install: xcode homebrew just ## install all dependencies |
| 130 | +install: sanity-check xcode homebrew git python pip ansible just ## install all dependencies |
33 | 131 |
|
34 | 132 | help: ## Show this help. |
35 | 133 | @echo '' |
|
0 commit comments