from ubiquity import misc, plugin, validation import os import inspect NAME = 'lliurexSecurityUpgrades' AFTER = 'console_setup' BEFORE = 'usersetup' WEIGHT = 12 class PageGtk(plugin.PluginUI): plugin_title = 'lliurex/securityUpgrades' def __init__(self, controller, *args, **kwargs): from gi.repository import Gio, Gtk self.resolver = Gio.Resolver.get_default() self.controller = controller builder = Gtk.Builder() self.controller.add_builder(builder) builder.add_from_file(os.path.join( os.environ['UBIQUITY_GLADE'], 'UbiLliureXSecurityUpgrades.ui')) builder.connect_signals(self) self.page = builder.get_object('UbiLliureXSecurityUpgrades') self.securityUpgrades = builder.get_object('cb_securityUpgrades') self.stats = builder.get_object('cb_stats') self.plugin_widgets = self.page class Page(plugin.Plugin): def ok_handler(self): list_packages = [] if self.ui.securityUpgrades.get_active(): token = os.system("touch /tmp/ubiquitySecurityUpgrades") if self.ui.stats.get_active(): token = os.system("touch /tmp/stats") else: if os.path.isfile("/tmp/stats"): token = os.system("rm /tmp/stats") plugin.Plugin.ok_handler(self) class Install(plugin.InstallPlugin): def test_enable_upgrades(): ''' Due a Ubiquity bug, is necesary for now take a shortcut to test if automaticUpgrades are enabled... ''' result = False if os.path.isfile("/tmp/ubiquitySecurityUpgrades"): print(" * Security Upgrades enabled by GUI") result = True try: print(" * Security Upgrades enabled by preseed") result = self.db.get('lliurex/securityUpgrades/selection') except Excetion as e: print("Ubiquity is not capable to perform this operation : "+str(e)) return result def test_enable_stadistics(): result_stats = False if os.path.isfile("/tmp/stats"): print(" * Stadistics are enabled by GUI") result_stats = True try: print(" * Stadistics are enabled by preseed") except Excetion as e: print("Ubiquity is not capable to perform this operation : "+str(e)) return result_stats def install(self, target, progress, *args, **kwargs): progress.info('lliurex/securityUpgrades') result = False if os.path.isfile("/tmp/ubiquitySecurityUpgrades"): print(" * Security Upgrades enabled by GUI") result = True try: print(" * Security Upgrades enabled by preseed") result = self.db.get('lliurex/securityUpgrades/selection') except Exception as e: print("Ubiquity is not capable to perform this operation : "+str(e)) result_stats = False if os.path.isfile("/tmp/stats"): print(" * Stadistics are enabled by GUI") result_stats = True try: print(" * Stadistics are enabled by preseed") except Excetion as e: print("Ubiquity is not capable to perform this operation : "+str(e)) if (result) : os.system("mkdir -p /target/etc/apt/apt.conf.d/") f = open("/target/etc/apt/apt.conf.d/60auto-upgrades-lliurex","w") f.write('// Enable security \n') f.write('APT::Periodic::Update-Package-Lists "1";\n') f.write('APT::Periodic::Unattended-Upgrade "1";\n') f.close() else : os.system("mkdir -p /target/etc/apt/apt.conf.d/") f = open("/target/etc/apt/apt.conf.d/60auto-upgrades-lliurex","w") f.write('// Enable security \n') f.write('// APT::Periodic::Update-Package-Lists "1";\n') f.write('// APT::Periodic::Unattended-Upgrade "1";\n') f.close() if (result_stats) : os.system("mkdir -p /target/etc/lliurex-analytics/") f = open("/target/etc/lliurex-analytics/status","w") f.write('yes\n') f.close() else : os.system("mkdir -p /target/etc/lliurex-analytics/") f = open("/target/etc/lliurex-analytics/status","w") f.write('no\n') f.close() return plugin.InstallPlugin.install(self, target, progress, *args, **kwargs)