+# 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."
+ $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."
+ $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."
+ $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
+
+if $ROOTCMD update-alternatives --list x-terminal-emulator 2>/dev/null | grep -q '/uxterm' ; then
+ echo "Setting uxterm as x-terminal-emulator using update-alternatives."
+ $ROOTCMD update-alternatives --set x-terminal-emulator /usr/bin/uxterm
+elif $ROOTCMD update-alternatives --list x-terminal-emulator 2>/dev/null | grep -q '/xterm' ; then
+ echo "Setting xterm as x-terminal-emulator using update-alternatives."
+ $ROOTCMD update-alternatives --set x-terminal-emulator /usr/bin/xterm
+fi
+
+if $ROOTCMD update-alternatives --list x-cursor-theme 2>/dev/null | grep -q '/whiteglass.theme' ; then
+ echo "Setting whiteglass.theme as x-cursor-theme using update-alternatives."
+ $ROOTCMD update-alternatives --set x-cursor-theme /etc/X11/cursors/whiteglass.theme
+fi
+
+if $ROOTCMD update-alternatives --list x-www-browser 2>/dev/null | grep -q '/iceweasel' ; then
+ echo "Setting iceweasel as x-www-browser using update-alternatives."
+ $ROOTCMD update-alternatives --set x-www-browser /usr/bin/iceweasel
+fi
+
+if $ROOTCMD update-alternatives --list x-www-browser 2>/dev/null | grep -q '/firefox-esr' ; then
+ echo "Setting firefox-esr as x-www-browser using update-alternatives."
+ $ROOTCMD update-alternatives --set x-www-browser /usr/bin/firefox-esr
+fi
+
+if $ROOTCMD update-alternatives --list www-browser 2>/dev/null | grep -q '/w3m' ; then
+ echo "Setting w3m as www-browser using update-alternatives."
+ $ROOTCMD update-alternatives --set www-browser /usr/bin/w3m
+fi
+
+if $ROOTCMD update-alternatives --list x-window-manager 2>/dev/null | grep -q '/wm-ng' ; then
+ echo "Setting wm-ng as x-window-manager using update-alternatives."
+ $ROOTCMD update-alternatives --set x-window-manager /usr/bin/wm-ng
+fi
+
+# sadly isn't available via update-alternates, anyway - use
+# ntfs-3g (if available) as default for ntfs
+if [ -r $target/sbin/mount.ntfs-3g ] || [ -L $target/sbin/mount.ntfs-3g ] ; then
+ $ROOTCMD ln -sf /sbin/mount.ntfs-3g /sbin/mount.ntfs