summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2021-07-13 19:26:14 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2021-07-13 19:29:10 +0200
commit85eecfe470274e746df7d776f357fdba2c5de44f (patch)
tree4278d3f3060b1ac77a9ac15ea18489edee9d7831
parentAdd gandalf with remarkable conf. (diff)
downloadwebdav_server-85eecfe470274e746df7d776f357fdba2c5de44f.tar.gz
webdav_server-85eecfe470274e746df7d776f357fdba2c5de44f.tar.xz
Add way to manage pacman hooks.
-rw-r--r--modules/pacman/manifests/hook.pp68
-rw-r--r--modules/pacman/manifests/init.pp20
-rw-r--r--modules/pacman/templates/hook.epp31
3 files changed, 119 insertions, 0 deletions
diff --git a/modules/pacman/manifests/hook.pp b/modules/pacman/manifests/hook.pp
new file mode 100644
index 0000000..940ae5f
--- /dev/null
+++ b/modules/pacman/manifests/hook.pp
@@ -0,0 +1,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,
+ }
+}
diff --git a/modules/pacman/manifests/init.pp b/modules/pacman/manifests/init.pp
new file mode 100644
index 0000000..eadc1c2
--- /dev/null
+++ b/modules/pacman/manifests/init.pp
@@ -0,0 +1,20 @@
+class pacman (
+ String $hooks_path = '/etc/pacman.d/hooks-puppet',
+ String $conf_path = '/etc/pacman.conf',
+) {
+
+ # TODO ability to set multiple settings
+ ini_setting { 'Pacman HookDir':
+ path => $conf_path,
+ section => 'options',
+ setting => 'HookDir',
+ value => $hooks_path,
+
+ }
+
+ file { $hooks_path:
+ ensure => directory,
+ recurse => true,
+ purge => true,
+ }
+}
diff --git a/modules/pacman/templates/hook.epp b/modules/pacman/templates/hook.epp
new file mode 100644
index 0000000..08377d9
--- /dev/null
+++ b/modules/pacman/templates/hook.epp
@@ -0,0 +1,31 @@
+<%- | Array[Pacman::Trigger] $triggers,
+ Optional[String] $description,
+ String $exec,
+ Enum['PreTransation', 'PostTransaction'] $when,
+ Array[String] $depends,
+ Boolean $abortOnFail,
+ Boolean $needsTargets,
+
+| -%>
+# Managed by Puppet
+
+[Trigger]
+<%- $triggers.each |$trigger| { -%>
+Type = <%= $trigger['type'] %>
+<%- $trigger['operation'].each |$op| { -%>
+Operation = <%= $op %>
+<%- } -%>
+<% $trigger['target'].each |$target| { -%>
+Target = <%= $target %>
+<%- } -%>
+<%- } %>
+
+[Action]
+<%- if ($description) { -%>Description = <%= $description %><% } %>
+Exec = <%= $exec %>
+When = <%= $when %>
+<%- $depends.each |$depend| { -%>
+Depends = <%= $depend %>
+<%- } -%>
+<%- if ($abortOnFail) { -%>AbortOnFail<% } %>
+<%- if ($needsTargets) { -%>NeedsTargets<% } %>