def check_preloaded_system(self): """Checks that the system this tool is being run on contains a recovery partition""" #check any command line arguments if self.rp and not os.path.exists(self.rp): self.rp = None if self.rp: return True self.rp = find_partition() return self.rp
def __init__(self, controller, *args, **kwargs): self.controller = controller rpart = magic.find_partition() dvd, usb = magic.find_burners() oem = 'UBIQUITY_OEM_USER_CONFIG' in os.environ with misc.raised_privileges(): self.genuine = magic.check_vendor() if oem and (dvd or usb) and (rpart or not self.genuine): try: gi.require_version('Gtk', '3.0') from gi.repository import Gtk builder = Gtk.Builder() builder.add_from_file( '/usr/share/ubiquity/gtk/stepRecoveryMedia.ui') builder.connect_signals(self) self.controller.add_builder(builder) self.plugin_widgets = builder.get_object('stepRecoveryMedia') self.usb_media = builder.get_object('save_to_usb') self.dvd_media = builder.get_object('save_to_dvd') self.none_media = builder.get_object('save_to_none') self.grub_menu_98 = builder.get_object('98_grub_menu') self.grub_menu_99 = builder.get_object('99_grub_menu') if not dvd: builder.get_object('dvd_box').hide() if not usb: builder.get_object('usb_box').hide() if not self.genuine: builder.get_object('usb_box').hide() builder.get_object('dvd_box').hide() builder.get_object('none_box').hide() builder.get_object('genuine_box').show() except Exception as err: syslog.syslog('Could not create Dell Recovery page: %s', err) self.plugin_widgets = None else: if not oem: pass elif not rpart: syslog.syslog('%s: partition problems with rp[%s]' % (NAME, rpart)) self.plugin_widgets = None PluginUI.__init__(self, controller, *args, **kwargs)
def install(self, target, progress, *args, **kwargs): """Perform actual install time activities for oem-config""" if not 'UBIQUITY_OEM_USER_CONFIG' in os.environ: return #find the '/' mount partition and then label it as UBUNTU self.Set_RootPartitionLabel() env = os.environ lang = progress.get('debian-installer/locale') env['LANG'] = lang dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) self.progress = progress user = progress.get('passwd/username') uid = pwd.getpwnam(user).pw_uid gid = pwd.getpwnam(user).pw_gid rec_type = progress.get('dell-recovery/destination') if rec_type != "none": dvd, usb = magic.find_burners() rpart = magic.find_partition() self.index = 0 #build all the user's home directories a little earlier than normal subprocess.call(['su', user, '-c', 'xdg-user-dirs-update']) directory = magic.fetch_output(['su', user, '-c', '/usr/bin/xdg-user-dir DOWNLOAD']).strip() fname = os.path.join(directory, 'factory_image.iso') try: bus = dbus.SystemBus() dbus_iface = dbus.Interface(bus.get_object(magic.DBUS_BUS_NAME, '/RecoveryMedia'), magic.DBUS_INTERFACE_NAME) except Exception as err: self.log('install function exception while creating dbus backend: %s' % str(err)) return progress.info('dell-recovery/build_start') #Determine internal version number of image (version, date, platform) = dbus_iface.query_bto_version(rpart) version = magic.increment_bto_version(version) self.log("Generating recovery media from %s : %s" % (version, date)) #Build image try: magic.dbus_sync_call_signal_wrapper(dbus_iface, 'create_ubuntu', {'report_progress':self._update_progress_gui}, rpart, version, fname, platform) os.chown(fname.encode('utf-8'), uid, gid) except dbus.DBusException as err: self.log('install function exception while calling backend: %s' % str(err)) return #Close backend try: dbus_iface.request_exit() except dbus.DBusException as err: if hasattr(err, '_dbus_error_name') and err._dbus_error_name == \ 'org.freedesktop.DBus.Error.ServiceUnknown': pass else: self.log("Received %s when closing recovery-media-backend" \ % str(err)) return if rec_type: if rec_type == "dvd": cmd = ['dbus-launch'] + dvd + [fname.encode('utf-8')] else: cmd = ['dbus-launch'] + usb + [fname.encode('utf-8')] if 'DBUS_SESSION_BUS_ADDRESS' in os.environ: os.environ.pop('DBUS_SESSION_BUS_ADDRESS') progress.info('dell-recovery/burning') subprocess.call(cmd) else: #Mark burning tool to launch on 7th day directory = '/home/%s/.config/autostart' % user if not os.path.exists(directory): os.makedirs(directory) os.chown('/home/%s/.config' % user, uid, gid) os.chown(directory, uid, gid) fname = os.path.join(directory, 'dell-recovery.desktop') with open('/usr/share/applications/dell-recovery-media.desktop', encoding='utf-8') as rfd: with open(fname, 'w', encoding='utf-8') as wfd: for line in rfd.readlines(): if line.startswith('Exec='): line = 'Exec=/home/%s/.config/dell-recovery/reminder\n' % user wfd.write(line) os.chown(fname, uid, gid) directory = '/home/%s/.config/dell-recovery' % user if not os.path.exists(directory): os.makedirs(directory) os.chown(directory, uid, gid) fname = os.path.join(directory, 'reminder') date = magic.fetch_output(['date', '-d', '+7 days', '+%y%m%d']) with open(fname, 'w', encoding='utf-8') as wfd: wfd.write('#!/bin/sh\n') wfd.write('LAUNCH=%s\n' % date) wfd.write('TODAY=$(date +"%y%m%d")\n') wfd.write('if [ $TODAY -ge $LAUNCH ]; then\n') wfd.write(' dell-recovery\n') wfd.write('fi\n') os.chown(fname, uid, gid) os.chmod(fname, 0o744) return InstallPlugin.install(self, target, progress, *args, **kwargs)