Linux Mint: MDM fails to load after login

Some annoying problem has been occured on one of the client machines I work with. Every time when I tried to login, the MDM has thrown an error which says that it was unable to login due to undefined commands and variables. The client runs Linux Mint 17, but the problem happens with 18 as well.

The problem

If I tried to login MDM failed to load Cinnamon, Gnome, MATE or whatever I tried to use. If I expanded the error login message, it reported, that it was unable to use the additional scripts for the profiles, which were stored in /etc/profile.d/. This scripts, which are made by myself for a longer time now, are using a lot of specific bash stuff (variables, built-in commands, and so on).
Sadly, the MDM XSession file comes with a /bin/sh shebang which does not have the same spectrum of commands as bash.

The solution

The solution is rather simple. If MDM yells, that it is unable to load the Desktop because of a script error due to a file which is located in /etc/profile.d you simply have to modify the XSession script which comes with MDM.
The XSession Script for MDM is located at /etc/mdm/XSession. A simple change of the shebang does solve the problem. Just change the first line of the XSession file from

#!/bin/sh

to

#!/bin/bash

and you should be able to successfully login again.

You should always keep an eye of possible MDM updates. If the MDM Login Manager is updated on your system, it’s very likely, that the XSession file is getting overwritten and you will have the do this change again.