diff --git a/cdist/conf/type/__dot_file/explorer/home b/cdist/conf/type/__dot_file/explorer/home new file mode 100755 index 00000000..132cfc71 --- /dev/null +++ b/cdist/conf/type/__dot_file/explorer/home @@ -0,0 +1,27 @@ +#!/bin/sh +# Copyright (C) 2016 Dmitry Bogatov + +# Author: Dmitry Bogatov + +# This program 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. + +# This program 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 this program. If not, see . +set -eu + +user="$(cat "${__object}/parameter/user")" + +if which getent >/dev/null 2>&1; then + line=$(getent passwd "${user}") +else + line=$(grep "^${user}:" /etc/passwd) +fi +printf '%s' "$line" | cut -d: -f6 diff --git a/cdist/conf/type/__dot_file/explorer/primary_group b/cdist/conf/type/__dot_file/explorer/primary_group new file mode 100755 index 00000000..30b303ac --- /dev/null +++ b/cdist/conf/type/__dot_file/explorer/primary_group @@ -0,0 +1,21 @@ +#!/bin/sh +# Copyright (C) 2016 Dmitry Bogatov + +# Author: Dmitry Bogatov + +# This program 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. + +# This program 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 this program. If not, see . +set -eu + +user="$(cat "${__object}/parameter/user")" +id -gn "${user}" diff --git a/cdist/conf/type/__dot_file/man.rst b/cdist/conf/type/__dot_file/man.rst new file mode 100644 index 00000000..211c34a5 --- /dev/null +++ b/cdist/conf/type/__dot_file/man.rst @@ -0,0 +1,75 @@ +cdist-type__dot_file(7) +======================== + +NAME +---- + +cdist-type__dot_file - install file under user's home directory + +DESCRIPTION +----------- + +This type installs a file (=\ *__object_id*) under user's home directory, +providing a way to install per-user configuration files. File owner +and group is deduced from user, for who file is installed. + +Unlike regular __file type, you do not need make any assumptions, +where user's home directory is. + +REQUIRED PARAMETERS +------------------- + +user + + User, for who file is installed + +OPTIONAL PARAMETERS +------------------- + +mode + + forwarded to :bold:`__file` type + +state + + forwarded to :bold:`__file` type + +source + + forwarded to :bold:`__file` type + +MESSAGES +-------- + +This type inherits all messages from :bold:`file` type, and do not add +any new. + +EXAMPLES +-------- + +.. code-block:: sh + + # Install .forward file for user 'alice'. Since state is 'present', + # user is not meant to edit this file, all changes will be overridden. + # It is good idea to put warning about it in file itself. + __dot_file .forward --user alice --source "$__files/forward" + + # Install .muttrc for user 'bob', if not already present. User can safely + # edit it, his changes will not be overwritten. + __dot_file .muttrc --user bob --source "$__files/recommended_mutt_config" --state exists + + + # Install default xmonad config for user 'eve'. Parent directory is created automatically. + __dot_file .xmonad/xmonad.hs --user eve --state exists --source "$__files/xmonad.hs" + +SEE ALSO +-------- + +**cdist-type**\ (7), **cdist-type__file**\ (7) + +COPYING +------- + +Copyright (C) 2015 Dmitry Bogatov. Free use of this software is granted +under the terms of the GNU General Public License version 3 or later +(GPLv3+). diff --git a/cdist/conf/type/__dot_file/manifest b/cdist/conf/type/__dot_file/manifest new file mode 100755 index 00000000..4bc9f179 --- /dev/null +++ b/cdist/conf/type/__dot_file/manifest @@ -0,0 +1,65 @@ +#!/bin/sh +# +# Copyright (C) 2016 Bogatov Dmitry +# +# This program 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. +# +# This program 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 this program. If not, see . +set -eu + +user="$(cat "${__object}/parameter/user")" +home="$(cat "${__object}/explorer/home")" +primary_group="$(cat "${__object}/explorer/primary_group")" + +# Create parent directory. Type __directory has flag 'parents', but it +# will leave us with root-owned directory in user home, which is not +# acceptable. So we create parent directories one-by-one. XXX: maybe +# it should be fixed in '__directory'? +set -- +subpath=${__object_id} +while subpath="$(dirname "${subpath}")" ; do + [ "${subpath}" = . ] && break + set -- "${subpath}" "$@" +done +unset subpath + +export CDIST_ORDER_DEPENDENCY +for dir ; do + __directory "${home}/${dir}" \ + --group "${primary_group}" \ + --owner "${user}" +done + +# These parameters are forwarded to __file type. 'mode' is always +# present, since it have been given default. + +set -- +for p in state mode source ; do + if [ -f "${__object}/parameter/${p}" ] ; then + value="$(cat "${__object}/parameter/${p}")" + set -- "$@" "--${p}" "${value}" + unset value + fi +done + +# If source is `-' we can't just forward it, since stdin is already +# captured by __dot_file. So, we replace '-' with "$__object/stdin". +# +# It means that it is possible for __file to receive --source +# parameter twice, but, since latest wins, it is okay. +source="$(cat "${__object}/parameter/source")" +if [ "${source}" = "-" ] ; then + set -- "$@" --source "${__object}/stdin" +fi +unset source + +__file "${home}/${__object_id}" --owner "$user" --group "$primary_group" "$@" diff --git a/cdist/conf/type/__dot_file/parameter/default/mode b/cdist/conf/type/__dot_file/parameter/default/mode new file mode 100644 index 00000000..e9f960cf --- /dev/null +++ b/cdist/conf/type/__dot_file/parameter/default/mode @@ -0,0 +1 @@ +600 diff --git a/cdist/conf/type/__dot_file/parameter/optional b/cdist/conf/type/__dot_file/parameter/optional new file mode 100644 index 00000000..ccab9fa6 --- /dev/null +++ b/cdist/conf/type/__dot_file/parameter/optional @@ -0,0 +1,3 @@ +state +mode +source diff --git a/cdist/conf/type/__dot_file/parameter/required b/cdist/conf/type/__dot_file/parameter/required new file mode 100644 index 00000000..4eb8387f --- /dev/null +++ b/cdist/conf/type/__dot_file/parameter/required @@ -0,0 +1 @@ +user diff --git a/docs/changelog b/docs/changelog index 93e6e24f..f3e4986c 100644 --- a/docs/changelog +++ b/docs/changelog @@ -8,6 +8,7 @@ next: * Type __docker: Support absent state (Dominique Roux) * Type __docker_compose: Support absent state (Dominique Roux) * New type: __hosts (Dmitry Bogatov) + * New type: __dot_file (Dmitry Bogatov) 4.4.1: 2016-12-17 * Documentation: Update docs for types that used man.rst as symbolic links (Darko Poljak)