Ejemplo n.º 1
0
    def downloadAndCopyPackages(self):
        self.updateProgressTitle_Percent_Detail_(
            'Copying packages for install on first boot...', -1, '')
        # mount the target
        if not self.workVolume.Mounted():
            self.workVolume.Mount()

        pkgs_to_install = [item for item in self.selectedWorkflow['components']
                           if item.get('type') == 'package' and not item.get('pre_first_boot')]
        package_count = len(pkgs_to_install)
        counter = 0.0
        # download packages to /usr/local/first-boot - prepend number
        for item in pkgs_to_install:
            counter = counter + 1.0
            package_name = os.path.basename(item['url'])
            (output, error) = self.downloadPackage(item['url'], self.workVolume.mountpoint, counter,
                                  progress_method=self.updateProgressTitle_Percent_Detail_)
            if error:
                self.errorMessage = "Error copying first boot package %s - %s" % (item['url'], error)
                break
        if package_count:
            # copy bits for first boot script
            packages_dir = os.path.join(self.workVolume.mountpoint, 'usr/local/first-boot/')
            if not os.path.exists(packages_dir):
                os.makedirs(packages_dir)
            Utils.copyFirstBoot(self.workVolume.mountpoint)
Ejemplo n.º 2
0
    def copyFirstBootScripts(self):
        if not self.workVolume.Mounted():
            self.workVolume.Mount()

        scripts_to_run = [item for item in self.selectedWorkflow['components']
                           if item.get('type') == 'script' and not item.get('pre_first_boot')]
        script_count = len(scripts_to_run)
        counter = 0.0
        NSLog(str(scripts_to_run))
        for item in scripts_to_run:
            counter = counter + 1.0
            script = item['content']
            try:
                self.copyScript(
                    script, self.workVolume.mountpoint, counter,
                    progress_method=self.updateProgressTitle_Percent_Detail_)
            except:
                self.errorMessage = "Coun't copy script %s" % str(counter)
                break
        if scripts_to_run:
            Utils.copyFirstBoot(self.workVolume.mountpoint)
Ejemplo n.º 3
0
    def processWorkflowOnThread(self, sender):
        '''Process the selected workflow'''
        pool = NSAutoreleasePool.alloc().init()
        if self.selectedWorkflow:
            # count all of the workflow items - are we still using this?
            components = [item for item in self.selectedWorkflow['components']]
            component_count = len(components)
            counter = 0.0
            first_boot_items = None
            self.should_update_volume_list = False
            for item in self.selectedWorkflow['components']:
                NSLog("%@", self.targetVolume.mountpoint)
                # No point carrying on if something is broken
                if not self.errorMessage:
                    counter = counter + 1.0
                    # Restore image
                    if item.get('type') == 'image' and item.get('url'):
                        self.Clone(item.get('url'), self.targetVolume)
                    # Download and install package
                    elif item.get('type') == 'package' and not item.get('first_boot', True):
                        self.downloadAndInstallPackages(item.get('url'))
                    # Download and copy package
                    elif item.get('type') == 'package' and item.get('first_boot', True):
                        self.downloadAndCopyPackage(item.get('url'), counter)
                        first_boot_items = True
                    # Copy first boot script
                    elif item.get('type') == 'script' and item.get('first_boot', True):
                        self.copyFirstBootScript(item.get('content'), counter)
                        first_boot_items = True
                    # Run script
                    elif item.get('type') == 'script' and not item.get('first_boot', True):
                        self.runPreFirstBootScript(item.get('content'), counter)
                    # Partition a disk
                    elif item.get('type') == 'partition':
                        self.partitionTargetDisk(item.get('partitions'), item.get('map'))
                        if self.future_target == False:
                            # If a partition task is done without a new target specified, no other tasks can be parsed. 
                            # Another workflow must be selected.
                            NSLog("No target specified, reverting to workflow selection screen.")
                            break
                    # Format a volume
                    elif item.get('type') == 'eraseVolume':
                        self.eraseTargetVolume(item.get('name', 'Macintosh HD'), item.get('format', 'Journaled HFS+'))
                    elif item.get('type') == 'computer_name':
                        if self.computerName:
                            script_dir = os.path.dirname(os.path.realpath(__file__))
                            with open(os.path.join(script_dir, 'set_computer_name.sh')) as script:
                                script=script.read()
                            self.copyFirstBootScript(script, counter)
                            first_boot_items = True
                    else:
                        self.errorMessage = "Found an unknown workflow item."

            if first_boot_items:
                # copy bits for first boot script
                packages_dir = os.path.join(self.targetVolume.mountpoint, 'usr/local/first-boot/')
                if not os.path.exists(packages_dir):
                    os.makedirs(packages_dir)
                Utils.copyFirstBoot(self.targetVolume.mountpoint)

        self.performSelectorOnMainThread_withObject_waitUntilDone_(
            self.processWorkflowOnThreadComplete, None, YES)
        del pool