示例#1
0
 def sync_new_media (self):
     for item in [self.mount_point, self.loop_point]:
         if not os.path.exists (item):
             os.mkdir (item)
             
     # Mount loopback
     SystemManager.mount (self.image_source, self.loop_point, options="loop")
     
     # Mount fresh filesystem
     SystemManager.mount (self.fs_image, self.mount_point, options="loop")
     
     # Find the actual total number of files
     dry_run = "rsync -az --stats --dry-run \"%s/\" \"%s/\"" % (self.loop_point, self.mount_point)
     p = subprocess.Popen (dry_run, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
     remainder = p.communicate() [0]
     mn = re.findall(r'Number of files: (\d+)', remainder)
     total_files = int(mn[0])
     
     # Really run rsync now
     cmd = "rsync -avz \"%s/\" \"%s/\" --progress" % (self.loop_point, self.mount_point)
     p = subprocess.Popen (cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
     
     while True:
         output = p.stdout.readline()
         if 'to-check' in output:
             m = re.findall(r'to-check=(\d+)/(\d+)', output)
             progress = (100 * (int(m[0][1]) - int(m[0][0]))) / total_files
             self.imaging_progress = progress
             if int(m[0][0]) == 0:
                 break
         if output is None or p.poll() is not None:
             break
     
     self.imaging_progress = 0
     
     # Quickly install dbus
     self.install_dbus ()
             
     # Unmount it
     SystemManager.umount (self.mount_point)
     SystemManager.umount (self.loop_point)
 def _enter_system (self, enableServices=False):
     '''
     Setup and enter our new system (i.e. mountpoints and such)
     '''
     SystemManager.mount (self.fs_image, self.mount_point, options="loop")
     
     self.dbus_pid = os.path.join (self.mount_point, "var/run/dbus/pid")
     if os.path.exists (self.dbus_pid):
         os.unlink (self.dbus_pid)
         
     self.dbus_service = "/etc/rc.d/init.d/dbus"
     if not self._run_chroot_command_in_system ("%s start" % self.dbus_service):
         SystemManager.umount (self.mount_point)
         self.errors = "Could not start D-BUS"
     else:
         # Let's get some stuff mounted shall we?
         self.dev_shm_path = os.path.join (self.mount_point, "dev/shm")
         self.proc_dir = os.path.join (self.mount_point, "proc")
         SystemManager.mount ("tmpfs", self.dev_shm_path, filesystem="tmpfs")
         SystemManager.mount ("proc", self.proc_dir, filesystem="proc")
             
     return self.errors is None
示例#3
0
    def _enter_system(self, enableServices=False):
        '''
        Setup and enter our new system (i.e. mountpoints and such)
        '''
        SystemManager.mount(self.fs_image, self.mount_point, options="loop")

        self.dbus_pid = os.path.join(self.mount_point, "var/run/dbus/pid")
        if os.path.exists(self.dbus_pid):
            os.unlink(self.dbus_pid)

        self.dbus_service = "/etc/rc.d/init.d/dbus"
        if not self._run_chroot_command_in_system(
                "%s start" % self.dbus_service):
            SystemManager.umount(self.mount_point)
            self.errors = "Could not start D-BUS"
        else:
            # Let's get some stuff mounted shall we?
            self.dev_shm_path = os.path.join(self.mount_point, "dev/shm")
            self.proc_dir = os.path.join(self.mount_point, "proc")
            SystemManager.mount("tmpfs", self.dev_shm_path, filesystem="tmpfs")
            SystemManager.mount("proc", self.proc_dir, filesystem="proc")

        return self.errors is None
 def _exit_system (self):
     '''
     Tear down the environment and kill anything running
     '''
     if hasattr(self, "dev_shm_path"):
         SystemManager.umount (self.dev_shm_path)
     if hasattr (self, "proc_dir"):
         SystemManager.umount (self.proc_dir)
     
     self._run_chroot_command_in_system ("%s stop" % self.dbus_service)
         
     with open (self.dbus_pid, "r") as pid_file:
         pid = pid_file.read().strip()
         try:
             os.system ("kill -9 %s" % pid)  
         except:
             pass
     
     self.murder_death_kill (be_gentle=True)
     self.murder_death_kill ()
                   
     SystemManager.umount (self.mount_point)
示例#5
0
    def _exit_system(self):
        '''
        Tear down the environment and kill anything running
        '''
        if hasattr(self, "dev_shm_path"):
            SystemManager.umount(self.dev_shm_path)
        if hasattr(self, "proc_dir"):
            SystemManager.umount(self.proc_dir)

        self._run_chroot_command_in_system("%s stop" % self.dbus_service)

        with open(self.dbus_pid, "r") as pid_file:
            pid = pid_file.read().strip()
            try:
                os.system("kill -9 %s" % pid)
            except:
                pass

        self.murder_death_kill(be_gentle=True)
        self.murder_death_kill()

        SystemManager.umount(self.mount_point)
示例#6
0
	def exit_system (self):
		SystemManager.umount (self.mountpoint)
示例#7
0
	def enter_system (self):
		SystemManager.mount (self.fs_image, self.mountpoint, filesystem=self.filesystem, options="loop")
示例#8
0
	def dbus_configure(self):
		# D-BUS.
		self.dbus_pid = os.path.join (self.mountpoint, "var/run/dbus/pid")
		if os.path.exists (self.dbus_pid):
			print_info ("Deleting stale D-BUS PID file..")
			os.unlink (self.dbus_pid)

		
		# Always ensure the dbus start files exist
		lsb_init = os.path.join (self.mountpoint, "lib/lsb")
		dbus_rc = os.path.join (self.mountpoint, "etc/rc.d/init.d")
		if not os.path.exists (lsb_init):
			source_lsb = os.path.join (RESOURCE_DIR, "data/lsb")
			dest_lsb = os.path.join (self.mountpoint, "lib/lsb")
			print_info ("Copying lsb init functions")
			shutil.copytree (source_lsb, dest_lsb)
		
		if not os.path.exists (dbus_rc):
			source_dbus = os.path.join (RESOURCE_DIR, "data/init.d")
			dest_dbus = os.path.join (self.mountpoint, "etc/rc.d/init.d")
			print_info ("Copying dbus startup files")
			shutil.copytree (source_dbus, dest_dbus)
		
		# Startup dbus
		self.dbus_service = "/etc/rc.d/init.d/dbus"
		print_info ("Starting the D-Bus systemwide message bus")
		execute_hide ("chroot \"%s\" \"%s\" start" % (self.mountpoint, self.dbus_service))

		# Check for urandom
		urandom = os.path.join (self.mountpoint, "dev/urandom")
		if not os.path.exists (urandom):
			execute_hide ("chroot \"%s\" mknod -m 644 /dev/urandom c 1 9" % self.mountpoint)

		# FIX: dbus
		execute_hide ("chroot \"%s\" chmod o+x /usr/lib/dbus-1.0/dbus-daemon-launch-helper" % self.mountpoint)

		# Set up devices + stuff
		self.dev_shm_path = os.path.join (self.mountpoint, "dev/shm")
		if not os.path.exists (self.dev_shm_path):
			os.makedirs (self.dev_shm_path)
		
		self.proc_dir = os.path.join (self.mountpoint, "proc")
		SystemManager.mount ("tmpfs", self.dev_shm_path, filesystem="tmpfs")
		SystemManager.mount ("proc", self.proc_dir, filesystem="proc")

        ### ADD DBUSY TYPE STUFF HERE ####
		execute_hide ("chroot \"%s\" pisi configure-pending" % self.mountpoint)

		dbus_pid = os.path.join (self.mountpoint, "var/run/dbus/pid")
		print_info ("Stopping D-BUS...")
		
		with open (dbus_pid, "r") as pid_file:
			pid = pid_file.read().strip()
			os.system ("kill -9 %s" % pid)
		# Safety, gives dbus enough time to die
		time.sleep (3)
		
		# Murder the remaining processes
		print_info ("Asking all remaining processes to stop...")
		self.murder_death_kill (be_gentle=True)
		print_info ("Force-kill any remaining processes...")
		self.murder_death_kill ()
		
		print_info ("Unmounting virtual filesystems...")				
		SystemManager.umount (self.dev_shm_path)
		SystemManager.umount (self.proc_dir)
示例#9
0
    def enter_system(self, bind_home=False):
        ''' Enter the system '''
        # Mount the cache file (i.e. the 500MB filesystem)
        options = "loop"
        if self.loopback_filesystem == "btrfs":
            # Automatically compress a btrfs loopback file
            options += ",compress"

        self.bind_home = bind_home
        SystemManager.mount(self.loopback_file,
                            self.cache_dir,
                            filesystem=None,
                            options=options)

        # Mount our root buildkit filesystem
        SystemManager.mount(self.underlay,
                            self.underlay_dir,
                            filesystem="squashfs",
                            options="loop,ro")

        options = "dirs=%s:%s=ro" % (self.cache_dir, self.underlay_dir)
        SystemManager.mount("none",
                            self.union_dir,
                            filesystem="unionfs",
                            options=options)

        # D-BUS.
        self.dbus_pid = os.path.join(self.union_dir, "var/run/dbus/pid")
        if os.path.exists(self.dbus_pid):
            print_info("Deleting stale D-BUS PID file..")
            os.unlink(self.dbus_pid)

        # Always ensure the dbus start files exist
        lsb_init = os.path.join(self.union_dir, "lib/lsb")
        dbus_rc = os.path.join(self.union_dir, "etc/rc.d/init.d")
        if not os.path.exists(lsb_init):
            source_lsb = os.path.join(RESOURCE_DIR, "data/lsb")
            dest_lsb = os.path.join(self.union_dir, "lib/lsb")
            print_info("Copying lsb init functions")
            shutil.copytree(source_lsb, dest_lsb)

        if not os.path.exists(dbus_rc):
            source_dbus = os.path.join(RESOURCE_DIR, "data/init.d")
            dest_dbus = os.path.join(self.union_dir, "etc/rc.d/init.d")
            print_info("Copying dbus startup files")
            shutil.copytree(source_dbus, dest_dbus)

        # Startup dbus
        self.dbus_service = "/etc/rc.d/init.d/dbus"
        print_info("Starting the D-Bus systemwide message bus")
        execute_hide("chroot \"%s\" \"%s\" start" %
                     (self.union_dir, self.dbus_service))

        # Set up devices + stuff
        self.dev_shm_path = os.path.join(self.union_dir, "dev/shm")
        if not os.path.exists(self.dev_shm_path):
            os.makedirs(self.dev_shm_path)

        self.proc_dir = os.path.join(self.union_dir, "proc")
        SystemManager.mount("tmpfs", self.dev_shm_path, filesystem="tmpfs")
        SystemManager.mount("proc", self.proc_dir, filesystem="proc")

        # Finally, bind home
        if bind_home:
            self.home_dir = os.path.join(self.union_dir, "home")
            if not os.path.exists(self.home_dir):
                os.makedirs(self.home_dir)
            SystemManager.mount_home(self.home_dir)
示例#10
0
    def exit_system(self):
        ''' Exit the system '''
        # Clean up by unmounting for now

        if self.bind_home:
            print_info("Unmounting home...")
            SystemManager.umount(self.home_dir)

        dbus_pid = os.path.join(self.union_dir, "var/run/dbus/pid")
        print_info("Stopping D-BUS...")

        with open(dbus_pid, "r") as pid_file:
            pid = pid_file.read().strip()
            os.system("kill -9 %s" % pid)
        # Safety, gives dbus enough time to die
        time.sleep(3)

        # Murder the remaining processes
        print_info("Asking all remaining processes to stop...")
        self.murder_death_kill(be_gentle=True)
        print_info("Force-kill any remaining processes...")
        self.murder_death_kill()

        print_info("Unmounting virtual filesystems...")
        SystemManager.umount(self.dev_shm_path)
        SystemManager.umount(self.proc_dir)

        print_info("Unmounting SolusOS 2 system...")
        SystemManager.umount(self.union_dir)
        SystemManager.umount(self.cache_dir)
        SystemManager.umount(self.underlay_dir)