forked from ungleich-public/cdist
Add __select_editor type
This commit is contained in:
parent
7981f81dcd
commit
644768cc02
8 changed files with 262 additions and 0 deletions
97
cdist/conf/type/__select_editor/explorer/editor_path
Normal file
97
cdist/conf/type/__select_editor/explorer/editor_path
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# 2019 Dennis Camera (dennis.camera at ssrq-sds-fds.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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Check if the given editor is present on the target system and determine its
|
||||||
|
# absolute path.
|
||||||
|
#
|
||||||
|
|
||||||
|
case $("${__explorer}/os")
|
||||||
|
in
|
||||||
|
debian|devuan|ubuntu)
|
||||||
|
: # supported
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
exit 0 # will produce an error message in the manifest
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
editor=$(cat "${__object}/parameter/editor")
|
||||||
|
editors=$(update-alternatives --list editor)
|
||||||
|
|
||||||
|
if test $(echo "${editors}" | wc -l) -lt 1
|
||||||
|
then
|
||||||
|
echo 'No editors have been found on this system.' >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $editor
|
||||||
|
in
|
||||||
|
/*)
|
||||||
|
is_path=true
|
||||||
|
;;
|
||||||
|
*/*)
|
||||||
|
echo 'Relative editor paths are not supported' >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
is_path=false
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
IFS='
|
||||||
|
'
|
||||||
|
if $is_path
|
||||||
|
then
|
||||||
|
if ! test -f "${editor}"
|
||||||
|
then
|
||||||
|
echo "Editor ${editor} is missing on the target system." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for e in $editors
|
||||||
|
do
|
||||||
|
if test "${editor}" = "${e}"
|
||||||
|
then
|
||||||
|
# Editor is present and part of the alternatives list -> use it!
|
||||||
|
echo "${editor}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Editor ${editor} is not in the alternatives list of the target system." >&2
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
for e in $editors
|
||||||
|
do
|
||||||
|
if test "$(basename "${e}")" = "${editor}"
|
||||||
|
then
|
||||||
|
# Editor could be found by basename in the alternatives list -> use it!
|
||||||
|
echo "${e}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Editor ${editor} is missing on the target system." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 1
|
26
cdist/conf/type/__select_editor/explorer/group
Normal file
26
cdist/conf/type/__select_editor/explorer/group
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
#
|
||||||
|
# 2019 Dennis Camera (dennis.camera at ssrq-sds-fds.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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Determines the primary group of the user.
|
||||||
|
#
|
||||||
|
|
||||||
|
user=$__object_id
|
||||||
|
|
||||||
|
id -gn "${user}" 2>/dev/null
|
26
cdist/conf/type/__select_editor/explorer/user_home
Normal file
26
cdist/conf/type/__select_editor/explorer/user_home
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# 2019 Dennis Camera (dennis.camera at ssrq-sds-fds.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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Determines the home folder of the target user.
|
||||||
|
#
|
||||||
|
|
||||||
|
user=$__object_id
|
||||||
|
|
||||||
|
getent passwd "${user}" | cut -d':' -f6
|
51
cdist/conf/type/__select_editor/man.rst
Normal file
51
cdist/conf/type/__select_editor/man.rst
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
cdist-type__select_editor(7)
|
||||||
|
============================
|
||||||
|
|
||||||
|
NAME
|
||||||
|
----
|
||||||
|
cdist-type__select_editor - Select the sensible-editor
|
||||||
|
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
-----------
|
||||||
|
This cdist type allows you to select the sensible-editor on Debian-based systems
|
||||||
|
for a given user.
|
||||||
|
|
||||||
|
|
||||||
|
REQUIRED PARAMETERS
|
||||||
|
-------------------
|
||||||
|
editor
|
||||||
|
Name or path of the editor to be selected.
|
||||||
|
|
||||||
|
|
||||||
|
OPTIONAL PARAMETERS
|
||||||
|
-------------------
|
||||||
|
state
|
||||||
|
either "present" or "absent". Defaults to "present".
|
||||||
|
|
||||||
|
|
||||||
|
EXAMPLES
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: sh
|
||||||
|
|
||||||
|
__select_editor root --editor /bin/ed # ed(1) is the standard
|
||||||
|
__select_editor noob --editor nano
|
||||||
|
|
||||||
|
|
||||||
|
SEE ALSO
|
||||||
|
--------
|
||||||
|
none
|
||||||
|
|
||||||
|
|
||||||
|
AUTHOR
|
||||||
|
-------
|
||||||
|
Dennis Camera <dennis.camera--@--ssrq-sds-fds.ch>
|
||||||
|
|
||||||
|
|
||||||
|
COPYING
|
||||||
|
-------
|
||||||
|
Copyright \(C) 2019 Dennis Camera.
|
||||||
|
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.
|
59
cdist/conf/type/__select_editor/manifest
Normal file
59
cdist/conf/type/__select_editor/manifest
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
# -*- mode: sh; indent-tabs-mode: t -*-
|
||||||
|
#
|
||||||
|
# 2019 Dennis Camera (dennis.camera at ssrq-sds-fds.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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
os=$(cat "${__global}/explorer/os")
|
||||||
|
|
||||||
|
state=$(cat "${__object}/parameter/state")
|
||||||
|
user=$__object_id
|
||||||
|
|
||||||
|
editor_path=$(cat "${__object}/explorer/editor_path")
|
||||||
|
user_home=$(cat "${__object}/explorer/user_home")
|
||||||
|
group=$(cat "${__object}/explorer/group")
|
||||||
|
|
||||||
|
case $os
|
||||||
|
in
|
||||||
|
debian|devuan|ubuntu)
|
||||||
|
test "${state}" = 'present' && __package_apt sensible-utils --state present
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "OS ${os} does not support select-editor." >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if test -z "${user_home}"
|
||||||
|
then
|
||||||
|
echo "Could not find ${user}'s home directory." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -z "${editor_path}"
|
||||||
|
then
|
||||||
|
echo "Editor \"$(cat "${__object}/parameter/editor")\" is missing on the target system." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
__file "${user_home}/.selected_editor" --state "${state}" \
|
||||||
|
--owner "${user}" --group "${group}" --mode 0644 \
|
||||||
|
--source - <<EOF
|
||||||
|
# Managed by cdist
|
||||||
|
SELECTED_EDITOR="${editor_path}"
|
||||||
|
EOF
|
1
cdist/conf/type/__select_editor/parameter/default/state
Normal file
1
cdist/conf/type/__select_editor/parameter/default/state
Normal file
|
@ -0,0 +1 @@
|
||||||
|
present
|
1
cdist/conf/type/__select_editor/parameter/optional
Normal file
1
cdist/conf/type/__select_editor/parameter/optional
Normal file
|
@ -0,0 +1 @@
|
||||||
|
state
|
1
cdist/conf/type/__select_editor/parameter/required
Normal file
1
cdist/conf/type/__select_editor/parameter/required
Normal file
|
@ -0,0 +1 @@
|
||||||
|
editor
|
Loading…
Reference in a new issue