From 667357c7602f8c057305343d96e258efb8eeec32 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= <hugo@lysator.liu.se>
Date: Mon, 23 Oct 2023 20:37:33 +0200
Subject: [PATCH] Add PDK validation, fix resulting errors.

---
 manifests/ident.pp        | 20 +++++++++-------
 manifests/init.pp         |  7 +++---
 manifests/module.pp       | 14 ++++++++---
 manifests/setup.pp        | 49 ++++++++++++++++++++-------------------
 metadata.json             | 39 +++++++++++++++++++++++++++++++
 pdk.yaml                  |  2 ++
 templates/znc.service.epp |  2 +-
 7 files changed, 92 insertions(+), 41 deletions(-)
 create mode 100644 metadata.json
 create mode 100644 pdk.yaml

diff --git a/manifests/ident.pp b/manifests/ident.pp
index b50eacd..7053fdd 100644
--- a/manifests/ident.pp
+++ b/manifests/ident.pp
@@ -1,14 +1,10 @@
+# @summary Configures ident
+#
+# https://en.wikipedia.org/wiki/Ident_protocol
 class irc_bouncer::ident {
-  ensure_packages (
-    ['oidentd', ],
-    { ensure => installed, })
+  ensure_packages(['oidentd',], { ensure => installed, })
 
-
-  file { '/etc/oidentd.conf':
-    ensure  => 'present',
-    group   => 'znc',
-    mode    => '0664',
-    content => @(EOF)
+  $oident_conf = @(EOF)
     user "znc" {
       default {
         allow spoof
@@ -16,6 +12,12 @@ class irc_bouncer::ident {
       }
     }
     |- EOF
+
+  file { '/etc/oidentd.conf':
+    ensure  => file,
+    group   => 'znc',
+    mode    => '0664',
+    content => $oident_conf,
   }
 
   service { 'oidentd':
diff --git a/manifests/init.pp b/manifests/init.pp
index 052ba49..f8526bb 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -1,8 +1,7 @@
+# @summary
 class irc_bouncer {
-
-  require ::irc_bouncer::setup
-  require ::irc_bouncer::ident
-
+  require irc_bouncer::setup
+  require irc_bouncer::ident
 
   service { 'znc':
     ensure => running,
diff --git a/manifests/module.pp b/manifests/module.pp
index a92ea9e..0f16c41 100644
--- a/manifests/module.pp
+++ b/manifests/module.pp
@@ -1,15 +1,23 @@
-# Really znc module
+# @summary Load a ZNC module
+#
+# Adds a module to the list of loaded modules.
+#
+# Note that this module doesn't provide the modules.
+#
+# @param module
+#   Name of the module to load
+# @param args
+#   Extra arguments to pass to module.
 define irc_bouncer::module (
   String $module = $name,
   Array[String] $args = [],
 ) {
-
   $arg_str = join($args, ' ')
 
   file_line { "ZNC module ${module}":
     ensure => present,
     path   => '/var/lib/znc/configs/znc.conf',
     match  => "^LoadModule = ${module}",
-    line   => "LoadModule = ${module} ${arg_str}"
+    line   => "LoadModule = ${module} ${arg_str}",
   }
 }
diff --git a/manifests/setup.pp b/manifests/setup.pp
index 858a711..41fdd3c 100644
--- a/manifests/setup.pp
+++ b/manifests/setup.pp
@@ -1,26 +1,24 @@
+# @summary Initial configuration of ZNC
 class irc_bouncer::setup {
   file { [
-    '/var/lib/znc',
-    '/var/lib/znc/configs',
-    '/var/lib/znc/mobdata',
-    '/var/lib/znc/moddata/cyrusauth',
-    '/var/lib/znc/moddata/identfile',
-  ]:
-    ensure => directory,
-    owner  => 'znc',
+      '/var/lib/znc',
+      '/var/lib/znc/configs',
+      '/var/lib/znc/mobdata',
+      '/var/lib/znc/moddata/cyrusauth',
+      '/var/lib/znc/moddata/identfile',
+    ]:
+      ensure => directory,
+      owner  => 'znc',
   }
 
-
   # We use a self-packaged version of ZNC, whose package source is
   # available at:
   # https://git.lysator.liu.se/hugo/deb-znc
   # It also comes bundled with a lysator module.
 
-  ensure_packages ( ['znc'],
-    { ensure => latest, })
+  ensure_packages(['znc'], { ensure => latest, })
 
-  ensure_packages ( ['sasl2-bin'],
-    { ensure => installed, })
+  ensure_packages(['sasl2-bin'], { ensure => installed, })
 
   file_line { 'saslauthd remove START=no':
     ensure  => absent,
@@ -45,23 +43,22 @@ class irc_bouncer::setup {
 
   # restart saslauthd here?
 
-
   user { 'znc':
     comment => 'ZNC Daemon runner',
     home    => '/var/lib/znc',
     system  => true,
     shell   => '/usr/sbin/nologin',
-    groups  => [ 'sasl', ],
+    groups  => ['sasl',],
   }
 
   file { '/var/lib/znc/configs/znc.conf':
-    ensure  => present,
+    ensure  => file,
     replace => no,
     source  => 'puppet:///modules/irc_bouncer/znc.conf',
     owner   => 'znc',
   }
 
-  $certname = $facts['fqdn']
+  $certname = $facts['networking']['fqdn']
 
   file_line { 'Set ZNC SSL Cert File':
     path  => '/var/lib/znc/configs/znc.conf',
@@ -81,10 +78,14 @@ class irc_bouncer::setup {
 
   # lysconf module comes bundled with lysator-version of znc
 
-  irc_bouncer::module { [ 'webadmin',
-                          'fail2ban',
-                          'chansaver',
-                          'lysconf' ]: }
+  irc_bouncer::module { [
+      'webadmin',
+      'fail2ban',
+      'chansaver',
+      'lysconf',
+    ]:
+  }
+
   irc_bouncer::module { 'cyrusauth':
     args => ['saslauthd'],
   }
@@ -103,9 +104,9 @@ class irc_bouncer::setup {
   #
   # Se möjligen även över loggar
 
-
   systemd::unit_file { 'znc.service':
-    content       => epp('irc_bouncer/znc.service.epp',
-      { 'keyname' => $certname, })
+    content       => epp('irc_bouncer/znc.service.epp', {
+        'keyname' => $certname,
+    }),
   }
 }
diff --git a/metadata.json b/metadata.json
new file mode 100644
index 0000000..dd57493
--- /dev/null
+++ b/metadata.json
@@ -0,0 +1,39 @@
+{
+	"name": "lysator-znc",
+	"version": "0.2.0",
+	"author": "hugo",
+	"summary": "Configures the ZNC IRC bouncer",
+	"license": "Apache-2.0",
+	"source": "https://git.lysator.liu.se/lysator/puppet/irc_bouncer",
+	"operatingsystem_support": [
+		{
+			"operatingsystem": "Debian",
+			"operatingsystemrelease": [
+				"12"
+			]
+		}
+	],
+	"requirements": [
+		{
+			"name": "puppet",
+			"version_requirement": ">= 7.0.0 < 8.0.0"
+		}
+	],
+	"dependencies": [
+		{
+			"name": "puppetlabs/stdlib",
+			"version_requirement": ">= 6.3.0 < 9.0.0"
+		},
+		{
+			"name": "puppet/systemd",
+			"version_requirement": ">= 3.0.0 < 7.0.0"
+		}
+	],
+	"tags": [
+		"znc",
+		"irc"
+	],
+	"pdk-version": "2.5.0",
+	"template-url": "pdk-default#2.5.0",
+	"template-ref": "tags/2.5.0-0-g369d483"
+}
diff --git a/pdk.yaml b/pdk.yaml
new file mode 100644
index 0000000..4bef4bd
--- /dev/null
+++ b/pdk.yaml
@@ -0,0 +1,2 @@
+---
+ignore: []
diff --git a/templates/znc.service.epp b/templates/znc.service.epp
index 866a8c9..6e3d6ef 100644
--- a/templates/znc.service.epp
+++ b/templates/znc.service.epp
@@ -5,7 +5,7 @@ Description=ZNC, an advanced IRC bouncer
 After=network-online.target
 
 [Service]
-ExecStart=/usr/bin/znc -f --datadir=/var/lib/znc
+ExecStart=/usr/bin/znc --foreground --datadir=/var/lib/znc
 AmbientCapabilities=CAP_NET_BIND_SERVICE
 User=znc
 
-- 
GitLab