bunch of errors during any installation witn any utility apt, apt-get, synaptic, etc

Solution 1:

OK, after much of hair pulling and digging deeper, I've finally found the issue:

It appears that insserv stumbles upon some services, so I've moved all services that insserv was complaining about to a temporarily created dir: /etc/d.init from /etc/init.d. Then, I did sudo dpkg --configure -a and voila, it worked almost without errors. I ran it a couple more times until all the errors disappeared.

After that, I did sudo apt-get -f install just to make sure, and there is nothing left.

Then I started to reinstall and reset the configs in problematic packages, so, gradually, I came up with the following script:

#!/bin/sh

#First, manually move problematic services from init.d to d.init (i.e.: /etc/d.init/)
cd /etc

var_srv=$1
var_pkg=$(dpkg-query -S init.d/$var_srv|egrep -o '^.*\:'|egrep -o '^.*[^\:]')

#To Reinstall the problematic package:
sudo aptitude reinstall $var_pkg
#To Restore missing configs:
sudo apt-get -o DPkg::options::=--force-confmiss --reinstall install $var_pkg

#Show that both (the backup copy and the newly created copy exist):
ls d.init/$var_srv init.d/$var_srv
#Show the difference between 2 files (the new and the backup):
meld d.init/$var_srv init.d/$var_srv
sudo rm -vi d.init/$var_srv

#To show what files have left for processing
find d.init/|sort

During comparison, I've noticed, that showfsck's file doesn't have the required header that I've read about on forums. All init.d scripts have to have the following header:

### BEGIN INIT INFO
# Provides:
# Required-Start:
# Required-Stop:
# Should-Start:
# Should-Stop:
# X-Start-Before:
# X-Stop-After:
# Default-Start:
# Default-Stop:
# Short-Description:
# Description:
### END INIT INFO

I didn't know what values it should have so I left them empty. My installation works now without errors.