diff --git a/cdist/conf/type/__sensible_editor/explorer/editor_path b/cdist/conf/type/__sensible_editor/explorer/editor_path index 8b10b17b..b0de2f0a 100644 --- a/cdist/conf/type/__sensible_editor/explorer/editor_path +++ b/cdist/conf/type/__sensible_editor/explorer/editor_path @@ -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 diff --git a/cdist/conf/type/__sensible_editor/manifest b/cdist/conf/type/__sensible_editor/manifest index 56a6b02f..2ad8c54e 100644 --- a/cdist/conf/type/__sensible_editor/manifest +++ b/cdist/conf/type/__sensible_editor/manifest @@ -19,35 +19,47 @@ # along with cdist. If not, see . # +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 -case $os -in - debian|devuan|ubuntu) - 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 sensible-editor." >&2 - echo "If it does, please provide a patch." >&2 - exit 1 - ;; -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' +case $os +in + debian) + pkg_type='apt' + ;; + devuan) + pkg_type='apt' + ;; + ubuntu) + pkg_type='apt' + ;; + centos|fedora|redhat|scientific) + pkg_type='yum' + ;; + *) + not_supported + ;; +esac + +if test "${state}" != 'absent' +then + __package sensible-utils --state present --type "${pkg_type}" + export __require='__package/sensible-utils' +fi editor_path=$(cat "${__object}/explorer/editor_path") user_home=$(cat "${__object}/explorer/user_home")