New type: __dot_file
This commit is contained in:
parent
448126f498
commit
6d277ef1f1
8 changed files with 194 additions and 0 deletions
27
cdist/conf/type/__dot_file/explorer/home
Executable file
27
cdist/conf/type/__dot_file/explorer/home
Executable file
|
@ -0,0 +1,27 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Copyright (C) 2016 Dmitry Bogatov <KAction@gnu.org>
|
||||||
|
|
||||||
|
# Author: Dmitry Bogatov <KAction@gnu.org>
|
||||||
|
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
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
|
21
cdist/conf/type/__dot_file/explorer/primary_group
Executable file
21
cdist/conf/type/__dot_file/explorer/primary_group
Executable file
|
@ -0,0 +1,21 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Copyright (C) 2016 Dmitry Bogatov <kaction@sagulo>
|
||||||
|
|
||||||
|
# Author: Dmitry Bogatov <kaction@sagulo>
|
||||||
|
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
user="$(cat "${__object}/parameter/user")"
|
||||||
|
id -gn "${user}"
|
75
cdist/conf/type/__dot_file/man.rst
Normal file
75
cdist/conf/type/__dot_file/man.rst
Normal file
|
@ -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+).
|
65
cdist/conf/type/__dot_file/manifest
Executable file
65
cdist/conf/type/__dot_file/manifest
Executable file
|
@ -0,0 +1,65 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (C) 2016 Bogatov Dmitry <KAction@gnu.org>
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
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" "$@"
|
1
cdist/conf/type/__dot_file/parameter/default/mode
Normal file
1
cdist/conf/type/__dot_file/parameter/default/mode
Normal file
|
@ -0,0 +1 @@
|
||||||
|
600
|
3
cdist/conf/type/__dot_file/parameter/optional
Normal file
3
cdist/conf/type/__dot_file/parameter/optional
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
state
|
||||||
|
mode
|
||||||
|
source
|
1
cdist/conf/type/__dot_file/parameter/required
Normal file
1
cdist/conf/type/__dot_file/parameter/required
Normal file
|
@ -0,0 +1 @@
|
||||||
|
user
|
|
@ -8,6 +8,7 @@ next:
|
||||||
* Type __docker: Support absent state (Dominique Roux)
|
* Type __docker: Support absent state (Dominique Roux)
|
||||||
* Type __docker_compose: Support absent state (Dominique Roux)
|
* Type __docker_compose: Support absent state (Dominique Roux)
|
||||||
* New type: __hosts (Dmitry Bogatov)
|
* New type: __hosts (Dmitry Bogatov)
|
||||||
|
* New type: __dot_file (Dmitry Bogatov)
|
||||||
|
|
||||||
4.4.1: 2016-12-17
|
4.4.1: 2016-12-17
|
||||||
* Documentation: Update docs for types that used man.rst as symbolic links (Darko Poljak)
|
* Documentation: Update docs for types that used man.rst as symbolic links (Darko Poljak)
|
||||||
|
|
Loading…
Reference in a new issue