Commits

Rodrigo Bistolfi committed 453476b

Finish setup: fstab, services, umount pseudo fs

Comments (0)

Files changed (1)

vinstall/controller/usersetup.py

 
 
 from vinstall.core import Application, Render, Controller, model
-from vinstall.backend import users, utils
+from vinstall.backend import users, utils, fstab, services
 import os
 
 
         """
         yield self.set_root_password, (rootpassword,), "Creating users"
         yield self.create_user_account, (username, password), "Setting passwords"
+        yield self.fstab, tuple(), "Creating fstab"
+        yield self.setup_services, tuple(), "Setting up services"
+        yield self.vector_version, tuple(), "Writting /etc/vector-version"
+        yield self.clear_bind_mounts, tuple(), "Clearing bind mounts"
 
     def set_root_password(self, rootpassword):
         """Set the root password
         with utils.Chroot("/mnt/TARGET"):
             account.create()
 
+    def fstab(self):
+        """Create and install a fstab file in disk
+
+        """
+        print "Installing fstab in", disk
+        if not self._check_continue():
+            return
+
+        fstab_obj = fstab.Fstab("/mnt/TARGET/etc/fstab")
+
+        mountpoints = self.config.get("mountpoints")
+        for dev, mount, fs in mountpoints:
+            print dev, mount, fs
+            if not fs:
+                fs = dev.query_filesystem()
+
+            entry = fstab.FstabEntry(
+                    device=dev.device_path,
+                    mountpoint=mount,
+                    filesystem=fs)
+            fstab_obj.add_entry(entry)
+
+    def setup_services(self):
+        """Setup default system services
+
+        """
+        if not self._check_continue():
+            return
+
+        svcbasic = [ "cron", "portmap", "lm_sensors", "gpm", "inetd" ]
+        svc2 = svcbasic[:]
+        svc3 = svcbasic[:]
+        svc3.extend(["samba", "cups", "sshd"])
+        svc4 = svcbasic[:]
+        svc4.extend(["bluetooth", "fuse", "cups"])
+        svc5 = svc3[:]
+        svc5.extend(["bluetooth", "fuse"])
+
+        for svc in service.Service.all("/mnt/TARGET"):
+            for s, runlevel in ((svc2, 2), (svc3, 3), (svc4, 4), (svc5, 5)):
+                if svc.name in s:
+                    svc.enable(runlevel)
+
+    def vector_version(self):
+        """write /etc/vector-version based on the information
+        in VINSTALL.INI
+
+        """
+        print "Writing vector-version"
+
+        if not self._check_continue():
+            return
+
+        install_media = self.config["install_media"]
+        distro = install_media.config.get("general", "distro").replace("\"", "")
+        version = install_media.config.get("general", "version").replace("\"", "")
+        build_date = install_media.config.get("general",
+                "build_date").replace("\"", "")
+        vector_version =  "%s built on %s\n" % (version, build_date)
+        with open("/mnt/TARGET/etc/vector-version", 'w') as f:
+            f.write(vector_version)
+
+     def clear_bind_mounts(self):
+        """Clear the mountpoints that were mounted for the configuration
+
+        """
+        if not self._check_continue():
+            return
+
+        for mpoint in ("sys","proc","dev"):
+            cmd = "umount -f /mnt/TARGET/%s" % mpoint
+            subprocess.check_call(cmd.split())
+
     def _check_continue(self):
         return 'I_MEAN_IT' in os.environ