From f7381e261ae12eedfd9746937145ce0e28e78d08 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Sat, 17 Sep 2016 09:48:15 +0200 Subject: [PATCH] Add new type __firewalld_start. --- .../type/__firewalld_start/gencode-remote | 84 +++++++++++++++++++ cdist/conf/type/__firewalld_start/man.rst | 53 ++++++++++++ cdist/conf/type/__firewalld_start/manifest | 23 +++++ .../parameter/default/bootstate | 1 + .../parameter/default/startstate | 1 + .../type/__firewalld_start/parameter/optional | 2 + cdist/conf/type/__firewalld_start/singleton | 0 7 files changed, 164 insertions(+) create mode 100644 cdist/conf/type/__firewalld_start/gencode-remote create mode 100644 cdist/conf/type/__firewalld_start/man.rst create mode 100644 cdist/conf/type/__firewalld_start/manifest create mode 100644 cdist/conf/type/__firewalld_start/parameter/default/bootstate create mode 100644 cdist/conf/type/__firewalld_start/parameter/default/startstate create mode 100644 cdist/conf/type/__firewalld_start/parameter/optional create mode 100644 cdist/conf/type/__firewalld_start/singleton diff --git a/cdist/conf/type/__firewalld_start/gencode-remote b/cdist/conf/type/__firewalld_start/gencode-remote new file mode 100644 index 00000000..7a3b6298 --- /dev/null +++ b/cdist/conf/type/__firewalld_start/gencode-remote @@ -0,0 +1,84 @@ +#!/bin/sh +# +# 2016 Darko Poljak(darko.poljak at ungleich.ch) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# + +startstate="$(cat "$__object/parameter/startstate")" +init=$(cat "$__global/explorer/init") + +os=$(cat "$__global/explorer/os") +os_version=$(cat "$__global/explorer/os_version") +name="firewalld" + +case "${startstate}" in + present) + cmd="start" + ;; + absent) + cmd="stop" + ;; + *) + echo "Unknown startstate: ${startstate}" >&2 + exit 1 + ;; +esac + +if [ "$init" = 'systemd' ]; then + # this handles ALL linux distros with systemd + # e.g. archlinux, gentoo in some cases, new RHEL and SLES versions + echo "systemctl \"$cmd\" \"$name\"" +else + case "$os" in + debian) + case "$os_version" in + [1-7]*) + echo "service \"$name\" \"$cmd\"" + ;; + 8*) + echo "systemctl \"$cmd\" \"$name\"" + ;; + *) + echo "Unsupported version $os_version of $os" >&2 + exit 1 + ;; + esac + ;; + + gentoo) + echo service \"$name\" \"$cmd\" + ;; + + amazon|scientific|centos|fedora|owl|redhat|suse) + echo service \"$name\" \"$cmd\" + ;; + + openwrt) + echo "/etc/init.d/\"$name\" \"$cmd\"" + ;; + + ubuntu) + echo "service \"$name\" \"$cmd\"" + ;; + + *) + echo "Unsupported os: $os" >&2 + exit 1 + ;; + esac +fi diff --git a/cdist/conf/type/__firewalld_start/man.rst b/cdist/conf/type/__firewalld_start/man.rst new file mode 100644 index 00000000..03232b72 --- /dev/null +++ b/cdist/conf/type/__firewalld_start/man.rst @@ -0,0 +1,53 @@ +cdist-type__firewalld_start(7) +============================= + +NAME +---- +cdist-type__firewalld_start - start and enable firewalld + + +DESCRIPTION +----------- +This cdist type allows you to start and enable firewalld. + + +REQUIRED PARAMETERS +------------------- +None + +OPTIONAL PARAMETERS +------------------- +startstate + 'present' or 'absent', start/stop firewalld. Default is 'present'. +bootstate + 'present' or 'absent', enable/disable firewalld on boot. Default is 'present'. + + +EXAMPLES +-------- + +.. code-block:: sh + + # start and enable firewalld + __firewalld_start + + # only enable firewalld to start on boot + __firewalld_start --startstate present --bootstate absent + + +SEE ALSO +-------- +:strong:`firewalld`\ (8) + + +AUTHORS +------- +Darko Poljak + + +COPYING +------- +Copyright \(C) 2016 Darko Poljak. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/cdist/conf/type/__firewalld_start/manifest b/cdist/conf/type/__firewalld_start/manifest new file mode 100644 index 00000000..2c6a0219 --- /dev/null +++ b/cdist/conf/type/__firewalld_start/manifest @@ -0,0 +1,23 @@ +#!/bin/sh +# +# 2016 Darko Poljak (darko.poljak at ungleich.ch) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . + +bootstate="$(cat "$__object/parameter/bootstate")" + +__package firewalld +require="__package/firewalld" __start_on_boot firewalld --state "${bootstate}" diff --git a/cdist/conf/type/__firewalld_start/parameter/default/bootstate b/cdist/conf/type/__firewalld_start/parameter/default/bootstate new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__firewalld_start/parameter/default/bootstate @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__firewalld_start/parameter/default/startstate b/cdist/conf/type/__firewalld_start/parameter/default/startstate new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__firewalld_start/parameter/default/startstate @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__firewalld_start/parameter/optional b/cdist/conf/type/__firewalld_start/parameter/optional new file mode 100644 index 00000000..934c7d0d --- /dev/null +++ b/cdist/conf/type/__firewalld_start/parameter/optional @@ -0,0 +1,2 @@ +bootstate +startstate diff --git a/cdist/conf/type/__firewalld_start/singleton b/cdist/conf/type/__firewalld_start/singleton new file mode 100644 index 00000000..e69de29b