Need to repair or reinstall Ubuntu 12.04 without losing programs or data

First, you should really have a backup of your personal data, because harddisks are crashing all the time.

Second, I would recommend a complete reinstallation, because getting to the bottom of your problems is quite hard to accomplish.

To make things not too hard you can remember all the packages you installed via apt/dpkg by using

$ dpkg --get-selections "*" > package.list

then save that file somewhere save, reinstall, and restore the package selection.

$ sudo dpkg --set-selections < package.list
$ sudo apt-get -u dselect-upgrade

The restore your the data you backuped before and you should be good to go.