aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: 891126c128c525ee5609947c2408666b55a8818d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# unp

![Build Status](https://github.com/mpolden/unp/workflows/ci/badge.svg)

`unp` monitors a list of configured directories and automatically verifies and
unpacks multi-volume RAR archives as they are written. A combination of file
system events and SFV files are used to determine when archives should be
unpacked.

## Usage

```
$ unp -h
Usage of unp:
  -f string
    	Path to config file (default "~/.unprc")
  -t	Test and print config
```

## Example config

```json
{
  "BufferSize": 1024,
  "Paths": [
    {
      "Name": "/home/foo/videos",
      "Handler": "rar",
      "MinDepth": 4,
      "MaxDepth": 5,
      "SkipHidden": true,
      "Patterns": [
        "*.r??",
        "*.sfv"
      ],
      "Remove": false,
      "PostCommand": "mv {{.Dir}} /tmp/"
    }
  ]
}
```

## Configuration options

`BufferSize` sets the maximum number of file system events to queue in memory.
This should be large enough to store any events that occur while an event is
processed by its handler. The default value is `1024`.

`Paths` is an array of paths to watch.

`Name` is the path that should be watched.

`Handler` sets the handler to use. This can be either `rar` (default if
unspecified) or `script`. The `rar` handler automatically unpacks RAR archives
and uses SFV files to determine completeness. The `script` handler calls the
specified `PostCommand` without any processing or completeness checks.

`MinDepth` sets the minimum depth allowed to trigger the handler. A `MinDepth`
of `4` would allow files in `/home/foo/videos/bar` to trigger an event.

`MaxDepth` sets the maximum depth allowed to trigger the handler. A `MaxDepth`
of `5` would allow files in `/home/foo/videos/bar/baz` to trigger an event.

`SkipHidden` determines whether events for hidden files (files prefix with `.`)
should be ignored.

`Patterns` sets the wildcard patterns that a file needs to match to trigger an
event.

`Remove` determines whether the handler should delete files after processing
them.

`PostCommand` is an optional command to run after the handler processing
completes.

## Command templates

The following template variables are available for use in the `PostCommand`
option:

Variable | Description                                    | Example
-------- | ---------------------------------------------- | -------
`Base`   | Basename of the file triggering the event      | `baz.rar`
`Dir`    | Directory holding the file                     | `/tmp/foo/bar`
`Name`   | Full path to archive file triggering the event | `/tmp/foo/bar/baz.rar`

The template is compiled using the
[text/template](http://golang.org/pkg/text/template/) package. Variables can be
used like this: `{{.Name}}`

The working directory of `PostCommand` will be set to the directory where the
archive is located, equal to `{{.Dir}}`.

## Signals

`unp` reacts to the following signals:

`SIGUSR1` triggers a re-scan which walks all configured paths and triggers its
handler for any matching files that are found.

`SIGUSR2` reloads configuration from disk. This can be used to watch new paths
without restarting the program.