-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Error handling and better output for Makefile
Merge pull request #10
- Loading branch information
Showing
1 changed file
with
37 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
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; | ||
|