[__sensible_editor] Add support for RedHat derivatives
They have added sensible-utils lately. select-editor(1) does not work because their alternatives system is broken, but sensible-editor(1) works just fine, so we can support it.
This commit is contained in:
parent
9a6ca1a343
commit
b6898b097f
3 changed files with 78 additions and 39 deletions
|
@ -22,76 +22,92 @@
|
||||||
# absolute path.
|
# absolute path.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
die() {
|
||||||
|
echo "$@" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
editor_missing() { die "Editor '$1' is missing on the target system."; }
|
||||||
|
editor_no_alternative() { die "Editor '$1' is not in the alternatives list of the target system."; }
|
||||||
|
|
||||||
|
|
||||||
case $("${__explorer}/os")
|
case $("${__explorer}/os")
|
||||||
in
|
in
|
||||||
debian|devuan|ubuntu)
|
debian|devuan|ubuntu)
|
||||||
: # supported
|
has_alternatives=true
|
||||||
|
editors=$(update-alternatives --list editor)
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
exit 0 # will produce an error message in the manifest
|
# NOTE: RedHat has an alternatives system but it doesn't usually track
|
||||||
|
# editors and it is a pain to extract the list.
|
||||||
|
has_alternatives=false
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
editor=$(cat "${__object}/parameter/editor")
|
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
|
case $editor
|
||||||
in
|
in
|
||||||
/*)
|
/*)
|
||||||
is_path=true
|
is_abspath=true
|
||||||
;;
|
;;
|
||||||
*/*)
|
*/*)
|
||||||
echo 'Relative editor paths are not supported' >&2
|
die 'Relative editor paths are not supported'
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
is_path=false
|
is_abspath=false
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
if $has_alternatives && test "$(echo "${editors}" | wc -l)" -gt 0
|
||||||
|
then
|
||||||
IFS='
|
IFS='
|
||||||
'
|
'
|
||||||
if $is_path
|
if ! $is_abspath
|
||||||
then
|
then
|
||||||
if ! test -f "${editor}"
|
# First, try to resolve the absolute path using $editors.
|
||||||
|
for e in $editors
|
||||||
|
do
|
||||||
|
if test "$(basename "${e}")" = "${editor}"
|
||||||
then
|
then
|
||||||
echo "Editor ${editor} is missing on the target system." >&2
|
editor="${e}"
|
||||||
exit 1
|
break
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if path is present
|
||||||
|
test -f "${editor}" || editor_missing "${editor}"
|
||||||
|
|
||||||
for e in $editors
|
for e in $editors
|
||||||
do
|
do
|
||||||
if test "${editor}" = "${e}"
|
if test "${editor}" = "${e}"
|
||||||
then
|
then
|
||||||
# Editor is present and part of the alternatives list -> use it!
|
# Editor is part of the alternatives list -> use it!
|
||||||
echo "${editor}"
|
echo "${editor}"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Editor ${editor} is not in the alternatives list of the target system." >&2
|
editor_no_alternative "${editor}"
|
||||||
exit 1
|
|
||||||
else
|
else
|
||||||
for e in $editors
|
# NOTE: This branch is mostly for RedHat-based systems which do
|
||||||
do
|
# not track editor alternatives. To make this type useful
|
||||||
if test "$(basename "${e}")" = "${editor}"
|
# on RedHat at all we allow an absoloute path to be provided
|
||||||
|
# in any case.
|
||||||
|
|
||||||
|
if $is_abspath
|
||||||
then
|
then
|
||||||
# Editor could be found by basename in the alternatives list -> use it!
|
test -x "${editor}" || editor_missing "${editor}"
|
||||||
echo "${e}"
|
|
||||||
|
echo "${editor}"
|
||||||
exit 0
|
exit 0
|
||||||
|
else
|
||||||
|
die "The target doesn't list any editor alternatives. " \
|
||||||
|
"Please specify an absolute path or populate the alternatives list."
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
echo "Editor ${editor} is missing on the target system." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# The script should never reach this statement!
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -8,14 +8,15 @@ cdist-type__sensible_editor - Select the sensible-editor
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
This cdist type allows you to select the sensible-editor on Debian-based systems
|
This cdist type allows you to select the :strong:`sensible-editor` for
|
||||||
for a given user.
|
a given user.
|
||||||
|
|
||||||
|
|
||||||
REQUIRED PARAMETERS
|
REQUIRED PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
editor
|
editor
|
||||||
Name or path of the editor to be selected.
|
Name or path of the editor to be selected.
|
||||||
|
On systems other than Debian derivatives an absolute path is required.
|
||||||
|
|
||||||
|
|
||||||
OPTIONAL PARAMETERS
|
OPTIONAL PARAMETERS
|
||||||
|
@ -33,9 +34,17 @@ EXAMPLES
|
||||||
__sensible_editor noob --editor nano
|
__sensible_editor noob --editor nano
|
||||||
|
|
||||||
|
|
||||||
|
LIMITATIONS
|
||||||
|
-----------
|
||||||
|
This type only works on operating systems on which the sensible-utils package
|
||||||
|
is available.
|
||||||
|
|
||||||
|
Hint: On RedHat-based systems setting up the EPEL repo might be necessary.
|
||||||
|
|
||||||
|
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
none
|
:strong:`select-editor`\ (1), :strong:`sensible-editor`\ (1).
|
||||||
|
|
||||||
|
|
||||||
AUTHOR
|
AUTHOR
|
||||||
|
|
|
@ -27,14 +27,28 @@ user=$__object_id
|
||||||
case $os
|
case $os
|
||||||
in
|
in
|
||||||
debian|devuan|ubuntu)
|
debian|devuan|ubuntu)
|
||||||
test "${state}" = 'present' && __package_apt sensible-utils --state present
|
test "${state}" != 'absent' \
|
||||||
|
&& __package sensible-utils --state present --type apt
|
||||||
|
;;
|
||||||
|
centos|fedora|redhat|scientific)
|
||||||
|
test "${state}" != 'absent' \
|
||||||
|
&& __package sensible-utils --state present --type yum
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "OS ${os} does not support select-editor." >&2
|
echo "OS ${os} does not support sensible-editor." >&2
|
||||||
|
echo "If it does, please provide a patch." >&2
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
if test "${state}" != 'present' && test "${state}" != 'absent'
|
||||||
|
then
|
||||||
|
echo 'Only "present" and "absent" are allowed for --state' >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
test "${state}" = 'absent' || export __require='__package/sensible-utils'
|
||||||
|
|
||||||
editor_path=$(cat "${__object}/explorer/editor_path")
|
editor_path=$(cat "${__object}/explorer/editor_path")
|
||||||
user_home=$(cat "${__object}/explorer/user_home")
|
user_home=$(cat "${__object}/explorer/user_home")
|
||||||
group=$(cat "${__object}/explorer/group")
|
group=$(cat "${__object}/explorer/group")
|
||||||
|
|
Loading…
Reference in a new issue