[__sensible_editor] Refactor
This commit is contained in:
parent
b6898b097f
commit
522100b9fb
2 changed files with 34 additions and 19 deletions
|
@ -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,35 +19,47 @@
|
|||
# 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
|
||||
|
||||
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")
|
||||
|
|
Loading…
Reference in a new issue