5

I wanted a fresh install of Python and ran sudo apt-get remove --purge python. Apparently it has killed almost everything I had installed in my system.

Looking at the history.log I guess I could manually install the packages again, but there are hundreds of them, I can't just copy paste.

Ironically, python is still installed. Could I perform some replace regex with it so I can fix this mess? Or with bash.

dabadaba
  • 1,155
  • 2
  • 12
  • 20
  • 1
    If apt is still working: sudo apt-get install ubuntu-desktop. – muru Sep 11 '14 at 09:02
  • @muru thanks, now 140 MB are being installed. However the purge removed around 350. – dabadaba Sep 11 '14 at 09:03
  • @muru well now I am not sure, if downloaded or installed. But I still have some packages missing, ubuntu-desktop just helped me get back some of it (which is a lot, thanks). – dabadaba Sep 11 '14 at 09:09
  • 1
    @muru nvm, I managed to make my own python script and it's already installing the missing packages. Installign ubuntu-desktop package helped a lot though, thanks! – dabadaba Sep 11 '14 at 09:18

2 Answers2

6

First I ran sudo apt-get install ubuntu-desktop as I was told in the comments, then I copied the part of /var/log/apt/history.log concerning the purge action, and ran on it the following python script I made. Probably someone more skilled in regex would cry when seeing how I did it, but it worked for me:

import re

f = open('remove.log', 'r')
s = ""
for i in f:
    s += i + '\n'

s = re.sub(':.*?', '', s)
s = re.sub(r'\([^)]*\)', '', s)
s = re.sub(',', '', s)
s = re.sub('amd64', '', s)

f = open('replaced.txt', 'w')
f.write(s)

Then I could see a Install block and Purge block in replaced.txt, so I would just sudo apt-get install all the packages in the first block, and then in the second.

And voilà, apparently.

dabadaba
  • 1,155
  • 2
  • 12
  • 20
4

I had a similar problem. @dabadaba's script worked great, but I found manually installing each package to be a little tedious.

Here is a python script I wrote to automate installing the packages listed in the replaced.txt file created in @dabadaba's answer

import subprocess

f = open('replaced.txt', 'r')

for line in f:
    if line.startswith('Install') or line.startswith('Purge'):
        packages = line.split()
        for i in range(1, len(packages)):
            print 'Do you want to install ' + packages[i] + '? [y/n]'
            input = raw_input()
            if input == 'y':
                print 'beginning install'
                p = subprocess.Popen('apt-get install ' + packages[i], shell=True)
                p.wait()
            else:
                print 'not installing'
dlin
  • 3,830
JohannB
  • 141