diff --git a/Makefile b/Makefile index a68ebd0..a4c1b28 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,8 @@ .PHONY: help clean uninstall \ install-systemd install-cron \ install-targets-script install-targets-conf install-targets-systemd \ - install-targets-cron + install-targets-cron \ + activate-launchagent deactivate-launchagent #### Macros ################################################################### NOW := $(shell date +%Y-%m-%d_%H:%M:%S) @@ -39,6 +40,11 @@ MKDIR_PARENTS=sh -c '\ test -d $$dir || mkdir -p $$dir \ ' MKDIR_PARENTS +# LaunchAgent names. +UID := $(shell id -u) +LAUNCHAGENT = com.github.erikw.restic-automatic-backup +LAUNCHAGENT_TARGET = gui/$(UID)/$(LAUNCHAGENT) + # Source directories. DIR_SCRIPT = bin DIR_CONF = etc/restic @@ -163,3 +169,13 @@ $(DEST_DIR_LAUNCHAGENT)/%: $(BUILD_DIR_LAUNCHAGENT)/% # Install destination mac log dir. $(DEST_DIR_MAC_LOG): mkdir -p $@ + +# target: activate-launchagent - Activate the LaunchAgent. +activate-launchagent: + launchctl bootstrap gui/$(UID) $(DEST_TARGS_LAUNCHAGENT) + launchctl enable $(LAUNCHAGENT_TARGET) + launchctl kickstart -p $(LAUNCHAGENT_TARGET) + +# target: deactivate-launchagent - Deactivate and remove the LaunchAgent. +deactivate-launchagent: + launchctl bootout $(LAUNCHAGENT_TARGET) diff --git a/README.md b/README.md index a43f8c4..4583c5d 100644 --- a/README.md +++ b/README.md @@ -44,12 +44,11 @@ Tip: use the Section icon in the top left of this document to navigate the secti * Arch: part of the `base-devel` meta package, Debian/Ubuntu: part of the `build-essential` meta package, macOS: use the preinstalled or a more recent with Homebrew) - # Setup Depending on your system, the setup will look different. Choose one of * [Linux + Systemd](#setup-linux-systemd) * [macOS + LaunchAgent](#setup-macos-launchagent) -* [Cron](#setup-cron) - for any system having a cron daemon. Tested on FreeBSD and macOS. +* [Cron](#setup-cron) - for any system having a cron daemon. Tested on FreeBSD and macOS. ## Setup Linux Systemd ### TL;DR Setup @@ -282,6 +281,7 @@ LaunchAgent is the modern service scheduler in in macOS that uses [Launchd](http $ launchctl enable gui/$UID/com.github.erikw.restic-automatic-backup $ launchctl kickstart -p gui/$UID/com.github.erikw.restic-automatic-backup ``` + As a convenience, a shortcut for the above commands are `$ make activate-launchagent`. Use the `disable` command to temporarily pause the agent, or `bootout` to uninstall it. ```