summaryrefslogtreecommitdiff
path: root/manifests
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
commite7559e868775b54f59968bb4a18a246bea9108ea (patch)
tree1de22ad6d303fb0c3d6429f48f7a96a5c721580d /manifests
downloadpacman-e7559e868775b54f59968bb4a18a246bea9108ea.tar.gz
pacman-e7559e868775b54f59968bb4a18a246bea9108ea.tar.xz
Add way to manage pacman hooks.
Diffstat (limited to 'manifests')
-rw-r--r--manifests/hook.pp68
-rw-r--r--manifests/init.pp20
2 files changed, 88 insertions, 0 deletions
diff --git a/manifests/hook.pp b/manifests/hook.pp
new file mode 100644
index 0000000..940ae5f
--- /dev/null
+++ b/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/manifests/init.pp b/manifests/init.pp
new file mode 100644
index 0000000..eadc1c2
--- /dev/null
+++ b/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,
+ }
+}