#!/usr/bin/env python3

from os import listdir, system, popen

packages = []

for item in listdir('/usr/share/applications'):
    try:
        package = popen('dpkg -S %s'%('/usr/share/applications/'+item)).readlines()[0].split(':')[0].strip()
    except:
        package = None
    if package != 'dpkg-query' and package != None and package != 'diversion by calamares-settings-debian from':
        packages.append(package)

system('apt install %s'%' '.join(packages))
