diff --git a/Makefile b/Makefile index 443d13d..876ad10 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,21 @@ -SHELL=/bin/bash +SHELL := /bin/bash -# The cron job you want to add -NEW_CRON="0 3 * * * $(shell pwd)/main.sh" +# Use Make's built-in current directory variable +CURDIR := $(abspath .) +NEW_CRON := 0 3 * * * $(CURDIR)/main.sh + +.PHONY: run-script install requirements run-script: - # run the main script - main.sh + # Run the main script + ./main.sh install: - # Add entry in crontab - # Check if it already exists (to avoid duplicates) - ( crontab -l 2>/dev/null | grep -F "$(NEW_CRON)" ) && echo "Cron already exists." && exit 0 - # Add the new cron safely - ( crontab -l 2>/dev/null; echo "$(NEW_CRON)" ) | crontab - + # Add entry in crontab if missing (no duplicates) + @crontab -l 2>/dev/null | grep -Fqx '$(NEW_CRON)' && \ + echo "Cron already exists." || \ + { (crontab -l 2>/dev/null; echo '$(NEW_CRON)') | crontab -; echo "Cron installed."; } requirements: # Add the necessary packages - apt-get -y install make miniupnpc gawk + apt-get -y install make miniupnpc gawk \ No newline at end of file