It’s a really good tip to use the -x flag to debug bash scripts. I had a problem that GDM wasn’t starting anymore after the regular aptitude upgrade. I didn’t find a hint in the log files and had a look at its init-script /etc/init.d/gdm, which appeared quite complex to me: It sources various config files and calls macros that are defined in there. How the heck should I trace the problem down? The best way was to change the initial line to
#!/bin/sh -x
what starts the debug mode when the script is invoked. Here’s what it does: It prints every single command that is executed line by line in a fully expanded form, no matter if macros were defined or several other shell scripts are invoked from within. The lines are indented by a sequence of plus symbols to represent the invocation depth of the other scripts. By this, I saw that the last calls referred to splashy, a bootsplash package that I had installed for test purposes but never had configured. The solution was to simply remove that package.
Another tip: Don’t do experiments on a system that is supposed to work! This also means to not install the complete Debian ‘testing’ version on it. If you need a selected number of some more recent software, upgrade it individually, but keep the basic packages ‘stable’. On the other hand, you wouldn’t learn much if you weren’t forced to fix things once in a while.