Various Kubernetes-related scenarios to use as kubectl plug-ins.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

111 lines
3.2 KiB

MAKEFLAGS += --warn-undefined-variables
install_path = /usr/local/bin
links_path = ~/.shellrc/bin/scripts
local_man_path = ~/.shellrc/var/man/man1
system_man_path = /usr/local/share/man/man1
SRC := scripts
MAN := man
find := $(shell { command -v gfind || command -v find; } 2>&-)
SCRIPTS := $(wildcard $(SRC)/kubectl-*)
MAN_PAGES := $(subst $(SRC),$(MAN),$(basename $(wildcard $(SRC)/kubectl-*)))
MAN_FILES := $(addsuffix ".1", $(MAN_PAGES))
# --------------------------------------------------------------------------------------------------
# install_files [FILES] TO/
define install_files
@for file in $(1); do \
echo install -m $(3) $$(realpath -- $$file) $(2)/$$(basename $$file); \
install -m $(3) $$(realpath -- $$file) $(2)/$$(basename $$file); \
done
endef
# link_files [FILES] TO/
define link_files
@for file in $(1); do \
ln -f -s -v $$(realpath -- $$file) $(2)/$$(basename $$file); \
done
endef
# delete_files [FILES] FROM/
define delete_files
@for file in $(1); do \
rm -v $(2)/$$(basename $$file) || :; \
done
endef
# --------------------------------------------------------------------------------------------------
help: ## Display this help.
@awk 'BEGIN { \
FS = ":.*##"; \
printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n" \
} \
/^[a-zA-Z_-]+:.*?##/ { \
printf " \033[36m%-10s\033[0m %s\n", $$1, $$2 \
} \
END { \
print \
}' \
$(MAKEFILE_LIST)
# --------------------------------------------------------------------------------------------------
man: $(MAN_PAGES) ## Generate man pages.
links: make_local_dirs make_links link_man_pages ## Install kubectl scripts by creating links.
install: copy_bin copy_man_pages ## Install kubectl scripts to /usr/local/bin.
uninstall: rm_bin rm_links rm_man_pages rm_man_links rm_local_dirs ## Uninstall kubectl scripts.
# --------------------------------------------------------------------------------------------------
%: $(BIN)/%
$(MAN)/%: $(SRC)/%
pod2man --section 1 --release "1.0.0" --center "KUBECTL EXTENSIONS" $< > $@.1
# --------------------------------------------------------------------------------------------------
make_man_directory:
@mkdir -p $(system_man_path)
copy_bin:
$(call install_files, $(SCRIPTS), $(install_path), 755)
rm_bin:
$(call delete_files, $(SCRIPTS), $(install_path))
copy_man_pages: make_man_directory
$(call install_files, $(MAN_FILES), $(system_man_path), 644)
rm_man_pages: make_man_directory
$(call delete_files, $(MAN_FILES), $(system_man_path))
# --------------------------------------------------------------------------------------------------
make_local_dirs:
mkdir -p -v $(links_path)
mkdir -p -v $(local_man_path)
rm_local_dirs:
rmdir $(links_path) 2>&-; :
rmdir $(local_man_path) 2>&-; :
make_links:
$(call link_files, $(SCRIPTS), $(links_path))
rm_links:
$(call delete_files, $(SCRIPTS), $(links_path))
link_man_pages:
$(call link_files, $(MAN_FILES), $(local_man_path))
rm_man_links:
$(call delete_files, $(MAN_FILES), $(local_man_path))
# --------------------------------------------------------------------------------------------------
.PHONY: all make_local_dirs rm_local_dirs links install uninstall