Last active
February 10, 2022 01:56
-
-
Save masutaka/8ea029fbf33c39b0ef62c958c1158926 to your computer and use it in GitHub Desktop.
mitamae Makefile
This file contains hidden or 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
EXPIRE_SEC := $(shell expr 24 '*' 60 '*' 60) | |
KERNEL := $(shell uname | tr '[:upper:]' '[:lower:]') | |
MITAMAE_BIN_DIR := bin | |
MITAMAE_REPO := itamae-kitchen/mitamae | |
MITAMAE := $(MITAMAE_BIN_DIR)/mitamae | |
MITAMAE_ARCH_BIN := mitamae-x86_64-$(KERNEL) | |
MITAMAE_LATEST_TAR_BALL_URL := https://github.com/$(MITAMAE_REPO)/releases/latest/download/$(MITAMAE_ARCH_BIN).tar.gz | |
MITAMAE_LATEST_VERSION := $$(curl -s https://api.github.com/repos/$(MITAMAE_REPO)/releases/latest | jq -r .tag_name) | |
ifeq (linux, $(KERNEL)) | |
MITAMAE_LOCAL := sudo -E $(MITAMAE) local | |
MITAMAE_MTIME := $$(stat -c %Y $(MITAMAE)) | |
else | |
MITAMAE_LOCAL := $(MITAMAE) local | |
MITAMAE_MTIME := $$(stat -f %m $(MITAMAE)) | |
endif | |
all: dry-install | |
.PHONY: mitamae | |
mitamae: | |
@install_mitamae() { \ | |
TMPDIR=$$(mktemp -d); \ | |
trap "$(RM) -r $$TMPDIR" EXIT; \ | |
curl -L $(MITAMAE_LATEST_TAR_BALL_URL) | tar xz -C "$$TMPDIR"; \ | |
mv "$$TMPDIR/$(MITAMAE_ARCH_BIN)" $(MITAMAE); \ | |
touch $(MITAMAE); \ | |
}; \ | |
if [ -x "$(MITAMAE)" ]; then \ | |
MITAMAE_VERSION=$$($(MITAMAE) version | cut -d ' ' -f 2); \ | |
if [ $$(date '+%s') -gt $$(expr $(MITAMAE_MTIME) + $(EXPIRE_SEC)) ]; then \ | |
if [ "$$MITAMAE_VERSION" != "$(MITAMAE_LATEST_VERSION)" ]; then \ | |
$(MITAMAE) version; \ | |
install_mitamae; \ | |
else \ | |
touch $(MITAMAE); \ | |
fi \ | |
fi \ | |
else \ | |
install_mitamae; \ | |
fi | |
@$(MITAMAE) version | |
.PHONY: dry-install | |
dry-install: mitamae | |
@$(MITAMAE_LOCAL) -n recipe.rb | |
.PHONY: install | |
install: mitamae | |
@$(MITAMAE_LOCAL) recipe.rb | |
.PHONY: clean | |
clean: | |
$(RM) $(MITAMAE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment