3

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.

  • 1
    If apt is still working: sudo apt-get install ubuntu-desktop. – muru Sep 11 '14 at 9:02
  • @muru thanks, now 140 MB are being installed. However the purge removed around 350. – dabadaba Sep 11 '14 at 9: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 9: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 9:18
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.

3

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 in 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'

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.