M README.md => README.md +39 -7
@@ 33,15 33,18 @@ Move it to the bindir:
sudo mv git-mirror /usr/bin/git-mirror
```
+If you also want to use the `git-mirror-auto` script and Systemd timer, you also have to install these files using the same method.
+Check your systems documentation on how to install Systemd files.
+
### Packages
-I maintain a [copr repo][copr-url] for Fedora and EPEL.
+I maintain a [copr repo][copr-url] for Fedora and CentOS.
## Usage
-For details, see the manual page for `git-mirror(1)` or `git-mirror help`
+For details, see the manual page for `git-mirror(1)` (and `git-mirror-auto(1)`) or `git-mirror help`.
-There are two commands `setup` and `update`.
+There are two commands - `setup` and `update` - as well as a batch-update script along with a Systemd timer.
### `setup`
@@ 61,6 64,19 @@ Fetches everything from the primary repository and then pushes it to the mirror.
git-mirror update path/to/directory
```
+### `git-mirror-auto` and systemd
+
+The `git-mirror-auto` script takes one directory to batch update all subdirectories using `git-mirror update`.
+The directory to check is provided as a commandline argument or via the `UPDATE_DIRECTORY` environment variable.
+
+There is also a Systemd timer provided: `git-mirror-auto.timer` (with the according service file).
+It will run the `git-mirror-auto` script every 5 minutes.
+To use this timer, set the directory to update in `/etc/git-mirror/git-mirror-auto.env` (default is `/var/git-mirror`) and enable the timer:
+
+```
+systemctl enable git-mirror-auto.timer
+```
+
## Example Usage
### 1. Setup
@@ 68,18 84,34 @@ git-mirror update path/to/directory
Set up a new mirror directory.
```
-git-mirror setup /var/data/some-mirror https://someserver.domain/user/tomirror git@someserver.domain/user/mirror
+git-mirror setup /var/git-mirror/some-mirror https://someserver.domain/user/tomirror git@someserver.domain/user/mirror
```
-### 2. Cronjob
+### 2. (a) Systemd
+
+Enable the timer:
+
+```
+systemctl enable git-mirror-auto.timer
+```
+
+### 2. (b) One cronjob for everything
Add a cronjob (e.g. with `crontab -e`) containing the following:
```
-*/5 * * * * git-mirror update /var/data/some-mirror
+*/5 * * * * git-mirror-auto /var/git-mirror
+```
+
+### 2. (c) One cronjob for each mirror
+
+Add a cronjob (e.g. with `crontab -e`) containing the following for every mirror to update:
+
+```
+*/5 * * * * git-mirror update /var/git-mirror/some-mirror
```
-This will update the mirror every 5 minutes.
+This will update the mirror(s) every 5 minutes.
## In Action
A git-mirror-auto => git-mirror-auto +16 -0
@@ 0,0 1,16 @@
+#!/bin/sh
+
+[ ! -z "$1" ] && UPDATE_DIRECTORY="$1"
+
+[ -z "$UPDATE_DIRECTORY" ] && echo >&2 "No update path given." && exit 1
+
+for directory in $(find "$UPDATE_DIRECTORY" -maxdepth 1 -type d)
+do
+ [ "$directory" = "$UPDATE_DIRECTORY" ] && continue
+
+ echo "Updating $directory ..."
+
+ git-mirror update "$directory"
+
+ echo "Updated $directory."
+done
A git-mirror-auto.1 => git-mirror-auto.1 +14 -0
@@ 0,0 1,14 @@
+.TH man 1 "16 May 2020" "0.3.0" "git-mirror-auto man page"
+.SH NAME
+git-mirror-auto \- automatic updater for git-mirror
+.SH SYNOPSIS
+.B git-mirror-auto
+[path]
+.PP
+Batch updates all subdirectories.
+.SH ARGUMENTS
+.B path
+\- path to check for batch updating subdirectories
+.PP
+.SH AUTHOR
+Jan Baudisch (jan@baudisch.xyz)
A git-mirror-auto.env => git-mirror-auto.env +1 -0
@@ 0,0 1,1 @@
+UPDATE_DIRECTORY=/var/git-mirror
A git-mirror-auto.service => git-mirror-auto.service +8 -0
@@ 0,0 1,8 @@
+[Unit]
+Description=Automatic updater for git-mirror
+Documentation=https://git.sr.ht/~janbaudisch/git-mirror
+After=network.target
+
+[Service]
+EnvironmentFile=/etc/git-mirror/git-mirror-auto.env
+ExecStart=/usr/bin/git-mirror-auto
A git-mirror-auto.timer => git-mirror-auto.timer +8 -0
@@ 0,0 1,8 @@
+[Unit]
+Description=Run git-mirror-auto every five minutes
+
+[Timer]
+OnCalendar=*:0/5
+
+[Install]
+WantedBy=timers.target