GRMLBASE/90-update-alternatives: support vim >=2:8.1.2136-1
authorMichael Prokop <mika@grml.org>
Tue, 22 Oct 2019 09:02:19 +0000 (11:02 +0200)
committerMichael Prokop <mika@grml.org>
Tue, 22 Oct 2019 10:42:44 +0000 (12:42 +0200)
vim 2:8.1.2136-1 moved /usr/bin/vim.* into /usr/libexec/vim/,
so we need to check for its base path.

Also vim-gtk became a transitional package for vim-gtk3 and
the binary is called vim.gtk3, add according additional check.

Fixes:

| Setting vim.gtk as editor using update-alternatives.
| update-alternatives: error: alternative /usr/bin/vim.gtk for editor not registered; not setting
| GRMLBASE/90-update-alternatives FAILED with exit code 2.

etc/grml/fai/config/scripts/GRMLBASE/90-update-alternatives

index bc67650..9c3d188 100755 (executable)
@@ -9,20 +9,32 @@
 set -u
 set -e
 
 set -u
 set -e
 
-if $ROOTCMD update-alternatives --list editor 2>/dev/null | grep -q vim.gtk ; then
+# starting with vim v2:8.1.2136-1 it uses /usr/libexec/vim for the vim.* binaries
+if $ROOTCMD update-alternatives --list editor 2>/dev/null | grep -q /usr/libexec/vim ; then
+  VIM_PATH=/usr/libexec/vim
+else # for backwards compatibility
+  VIM_PATH=/usr/bin
+fi
+
+if $ROOTCMD update-alternatives --list editor 2>/dev/null | grep -q 'vim.gtk3' ; then
+  echo "Setting vim.gtk3 as editor using update-alternatives."
+  $ROOTCMD update-alternatives --set editor "${VIM_PATH}"/vim.gtk3
+  $ROOTCMD update-alternatives --set vi     "${VIM_PATH}"/vim.gtk3
+  $ROOTCMD update-alternatives --set vim    "${VIM_PATH}"/vim.gtk3
+elif $ROOTCMD update-alternatives --list editor 2>/dev/null | grep -q 'vim.gtk$' ; then
   echo "Setting vim.gtk as editor using update-alternatives."
   echo "Setting vim.gtk as editor using update-alternatives."
-  $ROOTCMD update-alternatives --set editor /usr/bin/vim.gtk
-  $ROOTCMD update-alternatives --set vi     /usr/bin/vim.gtk
-  $ROOTCMD update-alternatives --set vim    /usr/bin/vim.gtk
-elif $ROOTCMD update-alternatives --list editor 2>/dev/null | grep -q vim.basic ; then
+  $ROOTCMD update-alternatives --set editor "${VIM_PATH}"/vim.gtk
+  $ROOTCMD update-alternatives --set vi     "${VIM_PATH}"/vim.gtk
+  $ROOTCMD update-alternatives --set vim    "${VIM_PATH}"/vim.gtk
+elif $ROOTCMD update-alternatives --list editor 2>/dev/null | grep -q 'vim.basic' ; then
   echo "Setting vim.basic as editor using update-alternatives."
   echo "Setting vim.basic as editor using update-alternatives."
-  $ROOTCMD update-alternatives --set editor /usr/bin/vim.basic
-  $ROOTCMD update-alternatives --set vi     /usr/bin/vim.basic
-  $ROOTCMD update-alternatives --set vim    /usr/bin/vim.basic
-elif $ROOTCMD update-alternatives --list editor 2>/dev/null | grep -q vim.tiny ; then
+  $ROOTCMD update-alternatives --set editor "${VIM_PATH}"/vim.basic
+  $ROOTCMD update-alternatives --set vi     "${VIM_PATH}"/vim.basic
+  $ROOTCMD update-alternatives --set vim    "${VIM_PATH}"/vim.basic
+elif $ROOTCMD update-alternatives --list editor 2>/dev/null | grep -q 'vim.tiny' ; then
   echo "Setting vim.tiny as editor using update-alternatives."
   echo "Setting vim.tiny as editor using update-alternatives."
-  $ROOTCMD update-alternatives --set editor /usr/bin/vim.tiny
-  $ROOTCMD update-alternatives --set vi     /usr/bin/vim.tiny
+  $ROOTCMD update-alternatives --set editor "${VIM_PATH}"/vim.tiny
+  $ROOTCMD update-alternatives --set vi     "${VIM_PATH}"/vim.tiny
 else
   echo "Warning: No vim binary suitable for update-alternatives found."
 fi
 else
   echo "Warning: No vim binary suitable for update-alternatives found."
 fi