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
|
type Pacman::Operation = Enum['Install', 'Upgrade', 'Remove']
# type Variant[Type, Array[Type, 1]] = Variant[Type, Array[Type, 1]]
type Pacman::Trigger = Struct[{
type => Enum['Path', 'Package'],
operation => Variant[Pacman::Operation, Array[Pacman::Operation, 1]],
target => Variant[String, Array[String, 1]],
}]
define pacman::hook (
Integer $priority = 50,
Optional[String] $description = undef,
Enum['PreTransation', 'PostTransaction'] $when,
String $exec,
Optional[Variant[String, Array[String, 1]]] $depends = undef,
Boolean $abortOnFail = false, # only for PreTransation
Boolean $needsTargets = false,
Variant[Pacman::Trigger, Array[Pacman::Trigger, 1]] $trigger,
) {
require ::pacman
if ($abortOnFail and $when != 'PreTransation') {
fail('abortOnFail only valid when "when" => "PreTransation"')
}
$triggers = $trigger ? {
Array => $trigger,
default => [$trigger],
}
$str = epp('pacman/hook.epp', {
description => $description,
depends => $depends ? {
Optional => [],
Array => $depends,
default => [$depends],
},
triggers => $triggers.map |$trigger| {
{
type => $trigger['type'],
operation => $trigger['operation'] ? {
Array => $trigger['operation'],
default => [$trigger['operation']],
},
target => $trigger['target'] ? {
Array => $trigger['target'],
default => [$trigger['target']],
}
}
},
exec => $exec,
when => $when,
abortOnFail => $abortOnFail,
needsTargets => $needsTargets,
})
$chksum = $str.md5()
file { $chksum:
ensure => 'present',
content => $str,
path => "${pacman::hooks_path}/${priority}-${name}.hook",
checksum => 'md5',
checksum_value => $chksum,
}
}
|