Merge remote-tracking branch 'ungleich/master' into keyboard-locale_system-types

This commit is contained in:
Darko Poljak 2016-08-10 18:29:57 +02:00
commit 8918186d53
27 changed files with 402 additions and 351 deletions

View file

@ -0,0 +1,43 @@
#!/bin/sh
#
# 2016 - 2016 Daniel Heule (hda at sfs.biz)
#
# 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 <http://www.gnu.org/licenses/>.
#
os=$("$__explorer/os")
if [ -f "$__object/parameter/device" ]; then
blkdev="$(cat "$__object/parameter/device")"
else
blkdev="$__object_id"
fi
case "$os" in
centos|fedora|redhat|suse|gentoo)
if [ ! -x "$(command -v lsblk)" ]; then
echo "lsblk is required for __filesystem type" >&2
exit 1
else
#echo -n $(lsblk -nd -P -o NAME,FSTYPE,LABEL,MOUNTPOINT "$blkdev" 2>/dev/null)
lsblk -nd -P -o NAME,FSTYPE,LABEL,MOUNTPOINT "$blkdev" 2>/dev/null
fi
;;
*)
echo "__filesystem type lacks implementation for os: $os" >&2
exit 1
;;
esac

View file

@ -0,0 +1,102 @@
#!/bin/sh
#
# 2016 - 2016 Daniel Heule (hda at sfs.biz)
#
# 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 <http://www.gnu.org/licenses/>.
#
fstype="$(cat "$__object/parameter/fstype")"
if [ -f "$__object/parameter/device" ]; then
mydev="$(cat "$__object/parameter/device")"
else
mydev="$__object_id"
fi
label="$(cat "$__object/parameter/label")"
mkfsoptions="$(cat "$__object/parameter/mkfsoptions")"
if [ -f "$__object/parameter/force" ]; then
# create filesystem even an other filesystem is on disk or the label is not correct, use with caution !
forcefs="true"
else
forcefs="false"
fi
blkdev_devname="$(grep -P -o 'NAME="\K[^"]*' "$__object/explorer/lsblk")"
blkdev_fstype="$(grep -P -o 'FSTYPE="\K[^"]*' "$__object/explorer/lsblk")"
blkdev_label="$(grep -P -o 'LABEL="\K[^"]*' "$__object/explorer/lsblk")"
blkdev_mountpoint="$(grep -P -o 'MOUNTPOINT="\K[^"]*' "$__object/explorer/lsblk")"
if [ -z "$blkdev_devname" ]; then
echo "Specified device $mydev not found on target system" >&2
exit 1
fi
[ "$blkdev_label" = "$label" ] && [ "$blkdev_fstype" = "$fstype" ] && exit 0
if [ -n "$blkdev_mountpoint" ]; then
echo "Specified device $mydev is mounted on $blkdev_mountpoint, __filesystem does NOTHING with mountd devices" >&2
exit 0
fi
if [ -n "$blkdev_fstype" ] && [ "$forcefs" != "true" ]; then
if [ "$blkdev_label" != "$label" ]; then
echo "Specified device $mydev has not the spezified label: $blkdev_label, but __filesystem does NOTHING in this case without the --force option" >&2
exit 0
fi
if [ "$blkdev_fstype" != "$fstype" ]; then
echo "Specified device $mydev has not the spezified filesystem: $blkdev_fstype, but __filesystem does NOTHING in this case without the --force option" >&2
exit 0
fi
fi
# ok, all conditions checked, we need to format the device, lets go
opts="$mkfsoptions"
if [ -n "$label" ]; then
opts="$opts -L '$label'"
fi
case "$fstype" in
ext2|ext3|ext4)
if [ "$forcefs" = "true" ]; then
opts="$opts -F"
fi
echo "mkfs.$fstype $opts /dev/$blkdev_devname"
;;
btrfs)
if [ "$forcefs" = "true" ]; then
opts="$opts --force"
fi
echo "mkfs.btrfs $opts /dev/$blkdev_devname"
;;
xfs)
if [ "$forcefs" = "true" ]; then
opts="$opts -f"
fi
echo "mkfs.xfs $opts /dev/$blkdev_devname"
;;
*)
echo "__filesystem type lacks implementation for filesystem: $fstype" >&2
exit 1
;;
esac
echo "filesystem $fstype on $mydev : /dev/$blkdev_devname created" >> "$__messages_out"

View file

@ -0,0 +1,80 @@
cdist-type__filesystem(7)
=========================
NAME
----
cdist-type__filesystem - Create Filesystems.
DESCRIPTION
-----------
This cdist type allows you to create filesystems on devices.
If the device is mounted on target, it refuses to do someting.
If the device has a filesystem other as the specified and/or
the label is not correct, it only make a new filesystem
if you specified --force option
REQUIRED PARAMETERS
-------------------
fstype
Filesystem type, for example 'ext3', 'btrfs' or 'xfs'
OPTIONAL PARAMETERS
-------------------
device
Blockdevice for filesystem, Defaults to object_id.
On linux, it can be any by lsblk accepted device notation
for example
/dev/sdx
or /dev/disk/by-xxxx/xxx
or /dev/mapper/xxxx
label
Label which sould apply on the filesystem
mkfsoptions
Additional options which are inserted to the mkfs.xxx call.
BOOLEAN PARAMETERS
------------------
force
Normaly, this type does nothing if a filesystem is found
on the target device. If you specify force, its formated
if the filesystem type or label differs from parameters
Warning: This option can easy lead into data loss !
MESSAGES
--------
filesystem <fstype> on <device> : <discoverd device> created
Filesytem was created on <discoverd device>
EXAMPLES
--------
.. code-block:: sh
# Ensures that device /dev/sdb is formated with xfs
__filesystem /dev/sdb --fstype xfs --label Testdisk1
# The same thing with btrfs and disk spezified by pci path to disk 1:0 on vmware
__filesystem dev_sdb --fstype btrfs --device /dev/disk/by-path/pci-0000:0b:00.0-scsi-0:0:0:0 --label Testdisk2
# Make sure that a multipath san device has a filesystem ...
__filesystem dev_sdb --fstype xfs --device /dev/mapper/360060e80432f560050202f22000023ff --label Testdisk3
AUTHORS
-------
Daniel Heule <hda--@--sfs.biz>
COPYING
-------
Copyright \(C) 2016 Daniel Heule. Free use of this software is
granted under the terms of the GNU General Public License version 3 or any later version (GPLv3+).

View file

@ -0,0 +1 @@
force

View file

@ -0,0 +1,3 @@
device
label
mkfsoptions

View file

@ -0,0 +1 @@
fstype

View file

@ -3,7 +3,7 @@ cdist-type__locale(7)
NAME
----
cdit-type__locale - Configure locales
cdist-type__locale - Configure locales
DESCRIPTION
@ -34,7 +34,7 @@ EXAMPLES
SEE ALSO
--------
:strong:`locale`\ (1), :strong:`localedef`\ (1)
:strong:`locale`\ (1), :strong:`localedef`\ (1), :strong:`cdist-type__locale_system`\ (7)
AUTHORS
@ -44,5 +44,6 @@ Nico Schottelius <nico-cdist--@--schottelius.org>
COPYING
-------
Copyright \(C) 2013-2014 Nico Schottelius. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).
Copyright \(C) 2013-2016 Nico Schottelius. Free use of this software is
granted under the terms of the GNU General Public License version 3 or
later (GPLv3+).

View file

@ -3,18 +3,27 @@ cdist-type__locale_system(7)
NAME
----
cdit-type__locale_system - Set system-wide locale
cdist-type__locale_system - Set system-wide locale
DESCRIPTION
-----------
This cdist type allows you to modify system-wide locale.
The name of the locale category is given as the object id
(usually you are probably interested in using LANG)
OPTIONAL PARAMETERS
-------------------
locale
Any valid locale, defaults to en_US.UTF-8
state
present or absent, defaults to present.
If present, sets the locale category to the given value.
If absent, removes the locale category from the system file.
value
The value for the locale category.
Defaults to en_US.UTF-8.
EXAMPLES
@ -22,24 +31,36 @@ EXAMPLES
.. code-block:: sh
# Set system locale to en_US.UTF-8
__locale_system
# Set LANG to en_US.UTF-8
__locale_system LANG
# Same as above, but more explicit
__locale_system --locale en_US.UTF-8
__locale_system LANG --value en_US.UTF-8
# Set category LC_MESSAGES to de_CH.UTF-8
__locale_system LC_MESSAGES --value de_CH.UTF-8
# Remove setting for LC_ALL
__locale_system LC_ALL --state absent
SEE ALSO
--------
:strong:`locale`\ (1), :strong:`localedef`\ (1)
:strong:`locale`\ (1)
:strong:`localedef`\ (1)
:strong:`cdist-type__locale`\ (7)
AUTHORS
-------
Carlos Ortigoza <carlos.ortigoza--@--ungleich.ch>
Steven Armstrong <steven-cdist--@--armstrong.cc>,
Carlos Ortigoza <carlos.ortigoza--@--ungleich.ch>,
Nico Schottelius <nico.schottelius--@--ungleich.ch>
COPYING
-------
Copyright \(C) 2016 Carlos Ortigoza. Free use of this software is
granted under the terms of the GNU General Public License v3 or later (GPLv3+).
Copyright \(C) 2016 Nico Schottelius. Free use of this software is
granted under the terms of the GNU General Public License version 3 or
later (GPLv3+).

View file

@ -1,6 +1,8 @@
#!/bin/sh
#
# Carlos Ortigoza (carlos.ortigoza at ungleich.ch)
# 2012-2016 Steven Armstrong (steven-cdist at armstrong.cc)
# 2016 Carlos Ortigoza (carlos.ortigoza at ungleich.ch)
# 2016 Nico Schottelius (nico.schottelius at ungleich.ch)
#
# This file is part of cdist.
#
@ -22,22 +24,32 @@
#
os=$(cat "$__global/explorer/os")
locale="$(cat "$__object/parameter/locale")"
case "$os" in
centos)
__file /etc/sysconfig/i18n \
--owner root --group root --mode 644 \
--state exists
require="__file/etc/sysconfig/i18n" \
__key_value LANG \
--file /etc/sysconfig/i18n \
--delimiter '=' \
--value "\"$locale\""
;;
debian|ubuntu)
locale_conf="/etc/default/locale"
;;
archlinux)
locale_conf="/etc/locale.conf"
;;
redhat|centos)
locale_conf="/etc/sysconfig/i18n"
;;
*)
echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
echo "Please contribute an implementation for it if you can." >&2
exit 1
;;
echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
echo "Please contribute an implementation for it if you can." >&2
exit 1
;;
esac
__file "$locale_conf" \
--owner root --group root --mode 644 \
--state exists
require="__file/$locale_conf" \
__key_value "$locale_conf:$__object_id" \
--file "$locale_conf" \
--key "$__object_id" \
--delimiter = \
--state "$(cat "$__object/parameter/state")" \
--value "$(cat "$__object/parameter/value")"

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1 @@
en_US.UTF-8

View file

@ -1 +1,2 @@
locale
state
value

View file

@ -0,0 +1,22 @@
#!/bin/sh
#
# 2014 Steven Armstrong (steven-cdist at armstrong.cc)
#
# 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 <http://www.gnu.org/licenses/>.
#
# get the current runtime value
sysctl -n "$__object_id" || true

View file

@ -0,0 +1,30 @@
#!/bin/sh
#
# 2014 Steven Armstrong (steven-cdist at armstrong.cc)
#
# 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 <http://www.gnu.org/licenses/>.
#
value_should="$(cat "$__object/parameter/value")"
value_is="$(cat "$__object/explorer/value")"
if [ "$value_should" = "$value_is" ]; then
# Nothing to do
exit 0
fi
# set the current runtime value
printf 'sysctl -w %s="%s"\n' "$__object_id" "$value_should"

View file

@ -0,0 +1,39 @@
cdist-type__sysctl(7)
=====================
NAME
----
cdist-type__sysctl - manage sysctl settings
DESCRIPTION
-----------
Manages permanent as well as runtime sysctl settings.
Permament settings are set by managing entries in /etc/sysctl.conf.
Runtime settings are set by directly calling the sysctl executable.
REQUIRED PARAMETERS
-------------------
value::
The value to set for the given key (object_id)
EXAMPLES
--------
.. code-block:: sh
__sysctl net.ipv4.ip_forward --value 1
AUTHORS
-------
Steven Armstrong <steven-cdist--@--armstrong.cc>
COPYING
-------
Copyright \(C) 2014 Steven Armstrong. Free use of this software is
granted under the terms of the GNU General Public License version 3 or
later (GPLv3+).

View file

@ -0,0 +1,39 @@
#!/bin/sh
#
# 2014 Steven Armstrong (steven-cdist at armstrong.cc)
#
# 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 <http://www.gnu.org/licenses/>.
#
os=$(cat "$__global/explorer/os")
case "$os" in
redhat|centos|ubuntu|debian|archlinux)
:
;;
*)
echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
echo "Please contribute an implementation for it if you can." >&2
exit 1
;;
esac
__key_value "$__object_name" \
--key "$__object_id" \
--file /etc/sysctl.conf \
--value "$(cat "$__object/parameter/value")" \
--delimiter '='

View file

@ -0,0 +1 @@
value