Commits

Anonymous committed cf46fe6

[svn r37] reorg makefile

Comments (0)

Files changed (2)

+USER = backupuser
+EXE = ./backup-controller
+SCRIPT = $(EXE).sh
+SHELL = /bin/bash
+
 all : backup-controller cache
 
+.PHONY : all permissions install clean is_root test confirm_clobber clean clobber
+.SILENT : is_root confirm_clobber install
+
 cache :
 	mkdir -p cache
 	chmod 777 cache
-backup-controller : backup-controller.c
-	gcc -Wall -o backup-controller backup-controller.c
-	sudo chown root:root backup-controller
-	sudo chmod a+x backup-controller
+
+is_root :
+	[ 'root' = `whoami` ] || (echo "Must be root to perform this operation"  1>&2 && exit 1)
+
+permissions : is_root backup-controller
+	sudo chown root:www-data backup-controller
+	sudo chmod ug+x backup-controller
 	sudo chmod ug+s backup-controller
 
+backup-controller : backup-controller.c
+	gcc -Wall -DUSER="\"$(USER)\"" -DSCRIPT_NAME="\"$(SCRIPT)\"" -o backup-controller backup-controller.c
+
 test : backup-controller
-	./backup-controller -b isenguard2 -b jasper -s edoras -s onyx -p onyx:222 check
+	./backup-controller -b isenguard2 -b jasper -s edoras -s onyx -p onyx:222 check
+
+crontab:
+	(crontab -u backupuser -l | sed "/^#AUTOGENERATED FOR backup-controller DO NOT REMOVE/,/./ d" ; echo ; echo "#AUTOGENERATED FOR backup-controller DO NOT REMOVE" ; echo "50 23 * * * /bin/bash -c '/var/www/backups/backup-controller batch /var/www/backups/*plan'") | crontab -u backupuser -
+
+confirm_clobber:
+	[ . -ef /var/www/backups ] || echo
+	[ . -ef /var/www/backups ] || (read -p "This will clobber /var/www/backups. Continue [y|N]" -n 1 && ([ "$$REPLY" = Y -o "$$REPLY" = y ] || (echo "ABORTING" 1>&2 ; exit 1)))
+	[ . -ef /var/www/backups ] || echo
+
+
+/var/www/backups: permissions clobber
+	[ . -ef /var/www/backups ] || cp -R . /var/www/backups
+
+install: all /var/www/backups crontab
+	echo
+	echo "Successfully installed to /var/www/backups"
+
+clean:
+	rm -rf $(EXE) cache/*
+clobber: confirm_clobber
+	[ '!' -e /var/www/backups -o . -ef /var/www/backups ] || rm -R /var/www/backups

backup-controller.c

 #include <error.h>
 #include <pwd.h>
 
-#define SCRIPT_NAME "./backup-controller.sh"
-#define USER "backupuser"
-
 //extern int errno;
 
 int main(int argc, char** argv){