Commit 522100b9 authored by Dennis Camera's avatar Dennis Camera

[__sensible_editor] Refactor

parent b6898b09
......@@ -35,7 +35,10 @@ case $("${__explorer}/os")
in
debian|devuan|ubuntu)
has_alternatives=true
editors=$(update-alternatives --list editor)
# NOTE: Old versions do not support `--list`, in this case ignore the errors.
# This will require an absolute path to be provided, though.
editors=$(update-alternatives --list editor 2>/dev/null)
;;
*)
# NOTE: RedHat has an alternatives system but it doesn't usually track
......
......@@ -19,36 +19,48 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
not_supported() {
echo "OS ${os} does not support __sensible_editor." >&2
echo 'If it does, please provide a patch.' >&2
exit 1
}
os=$(cat "${__global}/explorer/os")
state=$(cat "${__object}/parameter/state")
user=$__object_id
if test "${state}" != 'present' && test "${state}" != 'absent'
then
echo 'Only "present" and "absent" are allowed for --state' >&2
exit 1
fi
case $os
in
debian|devuan|ubuntu)
test "${state}" != 'absent' \
&& __package sensible-utils --state present --type apt
debian)
pkg_type='apt'
;;
devuan)
pkg_type='apt'
;;
ubuntu)
pkg_type='apt'
;;
centos|fedora|redhat|scientific)
test "${state}" != 'absent' \
&& __package sensible-utils --state present --type yum
pkg_type='yum'
;;
*)
echo "OS ${os} does not support sensible-editor." >&2
echo "If it does, please provide a patch." >&2
exit 1
not_supported
;;
esac
if test "${state}" != 'present' && test "${state}" != 'absent'
if test "${state}" != 'absent'
then
echo 'Only "present" and "absent" are allowed for --state' >&2
exit 1
__package sensible-utils --state present --type "${pkg_type}"
export __require='__package/sensible-utils'
fi
test "${state}" = 'absent' || export __require='__package/sensible-utils'
editor_path=$(cat "${__object}/explorer/editor_path")
user_home=$(cat "${__object}/explorer/user_home")
group=$(cat "${__object}/explorer/group")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment