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,215

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,215
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,900
JohannB
  • 141