Skip to content

Commit

Permalink
Error handling and better output for Makefile
Browse files Browse the repository at this point in the history
Merge pull request #10
  • Loading branch information
weak-head authored Jan 17, 2025
2 parents a55d32d + e789c2b commit 431ffe5
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,56 @@
SBIN_DIR := $(DESTDIR)/usr/local/sbin
SBIN_DIR := /usr/local/sbin
CRON_FILE := /etc/cron.d/zfs-utils
SCRIPTS := \
zfs-clear.sh \
zfs-snap.sh \
zfs-to-s3.sh \
zfs-to-zfs.sh

.PHONY: all install install-cron uninstall uninstall-cron
NC := \033[0m
COLOR_INFO := \033[0;34m
COLOR_ERROR := \033[0;31m
COLOR_SUCCESS := \033[0;32m

all:
.PHONY: install install-cron uninstall uninstall-cron

install:
@echo "Installing scripts to '$(SBIN_DIR)'..."
@install -d $(SBIN_DIR)
@for script in $(SCRIPTS); do \
install $$script $(SBIN_DIR)/$${script%.sh}; \
@echo -e "Installing to '${COLOR_INFO}${SBIN_DIR}${NC}'"
@install -d ${SBIN_DIR} 2>/dev/null || { echo -e "\n${COLOR_ERROR}Failed to create directory: ${SBIN_DIR}${NC}"; exit 1; }
@for script in ${SCRIPTS}; do \
if install $$script ${SBIN_DIR}/$${script%.sh}; then \
echo -e "Installed: ${COLOR_SUCCESS}$${script%.sh}${NC}"; \
else \
echo -e "${COLOR_ERROR}Failed to install: $${script%.sh}${NC}"; \
exit 1; \
fi; \
done

install-cron:
@echo "Installing cron job..."
@install -D cron.d/zfs-utils $(CRON_FILE)
@echo -e "Installing cron to '${COLOR_INFO}${CRON_FILE}${NC}'"
@if install -D cron.d/zfs-utils "${CRON_FILE}"; then \
echo -e "Installed: ${COLOR_SUCCESS}${CRON_FILE}${NC}"; \
else \
echo -e "${COLOR_ERROR}Failed to install: ${CRON_FILE}${NC}"; \
exit 1; \
fi

uninstall:
@echo "Uninstalling scripts from '$(SBIN_DIR)'..."
@for script in $(SCRIPTS); do \
rm -f $(SBIN_DIR)/$${script%.sh}; \
@echo -e "Uninstalling from '${COLOR_INFO}${SBIN_DIR}${NC}'"
@for script in ${SCRIPTS}; do \
if rm -f "${SBIN_DIR}/$${script%.sh}"; then \
echo -e "Uninstalled: ${COLOR_SUCCESS}$${script%.sh}${NC}"; \
else \
echo -e "${COLOR_ERROR}Failed to uninstall: $${script%.sh}${NC}"; \
exit 1; \
fi; \
done

uninstall-cron:
@echo "Uninstalling cron job..."
@rm -f $(CRON_FILE)
@echo -e "Uninstalling cron from '${COLOR_INFO}${CRON_FILE}${NC}'"
@if rm -f "${CRON_FILE}"; then \
echo -e "Uninstalled: ${COLOR_SUCCESS}${CRON_FILE}${NC}"; \
else \
echo -e "${COLOR_ERROR}Failed to uninstall cron: ${CRON_FILE}${NC}"; \
exit 1; \
fi;

0 comments on commit 431ffe5

Please sign in to comment.