Exemplo n.º 1
0
    def start(cls):
        Tools.ProcessArguments(Addon)
        call(["clear"])
        Tools.PrintHeader()
        Core.PrintMenuAndGetDesiredFeatures()

        if var.kernel or Addon.GetFiles():
            Core.GetDesiredKernel()

        Core.VerifySupportedArchitecture()
        Tools.Clean()
        Core.VerifyPreliminaryBinaries()
        Core.CreateBaselayout()
        Core.VerifyBinaries()
        Core.CopyBinaries()
        Core.CopyManPages()
        Core.CopyModules()
        Core.CopyFirmware()

        # Dependencies must be copied before we create links since the commands inside of
        # the create links (i.e chroot) function require that the libraries are already
        # in our chroot environment.
        Core.CopyDependencies()
        Core.CreateLinks()

        Core.LastSteps()
        Core.CreateInitramfs()
        Tools.CleanAndExit(var.initrd)
Exemplo n.º 2
0
    def CopyModules(cls):
        moddeps = set()

        # Build the list of module dependencies
        if Addon.IsEnabled():
            Tools.Info("Copying modules ...")

            # Checks to see if all the modules in the list exist
            for file in Addon.GetFiles():
                try:
                    cmd = 'find ' + var.modules + ' -iname "' + file + '.ko" | grep ' + file + '.ko'
                    result = check_output(cmd,
                                          universal_newlines=True,
                                          shell=True).strip()
                    cls._modset.add(result)
                except CalledProcessError:
                    Tools.ModuleDoesntExist(file)

        # If a kernel has been set, try to update the module dependencies
        # database before searching it
        if var.kernel:
            try:
                result = call(["depmod", var.kernel])

                if result:
                    Tools.Fail("Error updating module dependency database!")
            except FileNotFoundError:
                # This should never occur because the application checks
                # that root is the user that is running the application.
                # Non-administraative users normally don't have access
                # to the 'depmod' command.
                Tools.Fail("The 'depmod' command wasn't found.")

        # Get the dependencies for all the modules in our set
        for file in cls._modset:
            # Get only the name of the module
            match = re.search('(?<=/)[a-zA-Z0-9_-]+.ko', file)

            if match:
                sFile = match.group().split(".")[0]

                cmd = "modprobe -S " + var.kernel + " --show-depends " + sFile + " | awk -F ' ' '{print $2}'"
                results = check_output(cmd,
                                       shell=True,
                                       universal_newlines=True).strip()

                for i in results.split("\n"):
                    moddeps.add(i.strip())

        # Copy the modules/dependencies
        if moddeps:
            for module in moddeps:
                Tools.Copy(module)

            # Update module dependency database inside the initramfs
            cls.GenerateModprobeInfo()
Exemplo n.º 3
0
    def PrintMenuAndGetDesiredFeatures(cls):
        # If the user didn't pass their desired features through the command
        # line, then ask them which initramfs they would like to generate.
        if not var.features:
            print(
                "Which initramfs features do you want? (Separated by a comma):"
            )
            Tools.PrintFeatures()
            var.features = Tools.Question("Features [1]: ")

            if var.features:
                var.features = cls.ConvertNumberedFeaturesToNamedList(
                    var.features)
            else:
                var.features = ["zfs"]

            Tools.NewLine()
        else:
            var.features = var.features.split(",")

        # Enable the addons if the addon has files (modules) listed
        if Addon.GetFiles():
            Addon.Enable()

        for feature in var.features:
            if feature == "zfs":
                Zfs.Enable()
                Addon.Enable()
                Addon.AddFile("zfs")
            elif feature == "lvm":
                Lvm.Enable()
            elif feature == "raid":
                Raid.Enable()
            elif feature == "luks":
                Luks.Enable()
            # Just a base initramfs with no additional stuff
            # This can be used with other options though
            # (i.e you have your rootfs directly on top of LUKS)
            elif feature == "basic":
                pass
            else:
                Tools.Warn("Exiting.")
                quit(1)
Exemplo n.º 4
0
    def start(cls):
        Tools.ProcessArguments(Addon)
        call(["clear"])
        Tools.PrintHeader()
        Core.PrintMenu()

        if var.kernel or Addon.GetFiles():
            Core.GetDesiredKernel()

        Core.VerifySupportedArchitecture()
        Tools.Clean()
        Core.VerifyPreliminaryBinaries()
        Core.CreateBaselayout()
        Core.VerifyBinaries()
        Core.CopyBinaries()
        Core.CopyManPages()
        Core.CopyModules()
        Core.CopyFirmware()
        Core.CreateLinks()
        Core.CopyDependencies()
        Core.LastSteps()
        Core.CreateInitramfs()
        Tools.CleanAndExit(var.initrd)
Exemplo n.º 5
0
    def LastSteps(cls):
        Tools.Info("Performing finishing steps ...")

        # Create mtab file
        call(["touch", var.temp + "/etc/mtab"])

        if not os.path.isfile(var.temp + "/etc/mtab"):
            Tools.Fail("Error creating the mtab file. Exiting.")

        cls.CreateLibraryLinks()

        # Copy the init script
        Tools.SafeCopy(var.files_dir + "/init", var.temp)

        # Give execute permissions to the script
        cr = call(["chmod", "u+x", var.temp + "/init"])

        if cr != 0:
            Tools.Fail("Failed to give executive privileges to " + var.temp +
                       "/init")

        # Copy the bash related files
        bash_files = [
            var.files_dir + "/bash/profile", var.files_dir + "/bash/DIR_COLORS"
        ]

        for bash_file in bash_files:
            Tools.SafeCopy(bash_file, var.temp + "/etc/")

        Tools.SafeCopy(var.files_dir + "/bash/bashrc", var.temp + "/etc/bash")

        # Sets initramfs script version number
        call([
            "sed", "-i", "-e",
            var.initrdVersionLine + "s/0/" + var.version + "/",
            var.temp + "/init"
        ])

        # Copy all of the modprobe configurations
        if os.path.isdir("/etc/modprobe.d/"):
            shutil.copytree("/etc/modprobe.d/", var.temp + "/etc/modprobe.d/")

        cls.CopyUdevAndSupportFiles()
        cls.DumpSystemKeymap()

        # Any last substitutions or additions/modifications should be done here

        # Enable LUKS in the init if LUKS is being used
        if Luks.IsEnabled():
            Tools.ActivateTriggerInInit(var.useLuksLine)

            # Copy over our keyfile if the user activated it
            if Luks.IsKeyfileEnabled():
                Tools.Flag("Embedding our keyfile into the initramfs...")
                Tools.SafeCopy(Luks.GetKeyfilePath(), var.temp + "/etc",
                               "keyfile")

            # Copy over our detached header if the user activated it
            if Luks.IsDetachedHeaderEnabled():
                Tools.Flag(
                    "Embedding our detached header into the initramfs...")
                Tools.SafeCopy(Luks.GetDetachedHeaderPath(), var.temp + "/etc",
                               "header")

        # Enable RAID in the init if RAID is being used
        if Raid.IsEnabled():
            Tools.ActivateTriggerInInit(var.useRaidLine)

            # Make sure to copy the mdadm.conf from our current system.
            # If not, the kernel autodetection while assembling the array
            # will not know what name to give them, so it will name it something
            # like /dev/md126, /dev/md127 rather than /dev/md0, /dev/md1.

            # If the user didn't modify the default (all commented) mdadm.conf file,
            # then they will obviously get wrong raid array numbers being assigned
            # by the kernel. The user needs to run a "mdadm --examine --scan > /etc/mdadm.conf"
            # to fix this, and re-run the initramfs creator.
            mdadm_conf = "/etc/mdadm.conf"
            Tools.CopyConfigOrWarn(mdadm_conf)

        # Enable LVM in the init if LVM is being used
        if Lvm.IsEnabled():
            Tools.ActivateTriggerInInit(var.useLvmLine)

            lvm_conf = "/etc/lvm/lvm.conf"
            Tools.CopyConfigOrWarn(lvm_conf)

        # Enable ZFS in the init if ZFS is being used
        if Zfs.IsEnabled():
            Tools.ActivateTriggerInInit(var.useZfsLine)

        # Enable ADDON in the init and add our modules to the initramfs
        # if addon is being used
        if Addon.IsEnabled():
            Tools.ActivateTriggerInInit(var.useAddonLine)
            call([
                "sed", "-i", "-e", var.addonModulesLine + "s/\"\"/\"" +
                " ".join(Addon.GetFiles()) + "\"/", var.temp + "/init"
            ])

        cls.CopyLibGccLibrary()
Exemplo n.º 6
0
    def PrintMenu(cls):
        # If the user didn't pass an option through the command line,
        # then ask them which initramfs they would like to generate.
        if not var.choice:
            print("Which initramfs would you like to generate:")
            Tools.PrintOptions()
            temp_choice = Tools.Question("Current choice [1]: ")

            # If the user leaves the choice blank (default choice),
            # we won't be able to convert an empty string into an int.
            # Do some checking beforehand.
            if temp_choice:
                var.choice = int(temp_choice)
            else:
                var.choice = 1

            Tools.NewLine()

        # Enable the addons if the addon has files (modules) listed
        if Addon.GetFiles():
            Addon.Enable()

        # ZFS
        if var.choice == 1:
            Zfs.Enable()
            Addon.Enable()
            Addon.AddFile("zfs")
        # LVM
        elif var.choice == 2:
            Lvm.Enable()
        # RAID
        elif var.choice == 3:
            Raid.Enable()
        # LVM on RAID
        elif var.choice == 4:
            Raid.Enable()
            Lvm.Enable()
        # Normal
        elif var.choice == 5:
            pass
        # Encrypted ZFS
        elif var.choice == 6:
            Luks.Enable()
            Zfs.Enable()
            Addon.Enable()
            Addon.AddFile("zfs")
        # Encrypted LVM
        elif var.choice == 7:
            Luks.Enable()
            Lvm.Enable()
        # Encrypted RAID
        elif var.choice == 8:
            Luks.Enable()
            Raid.Enable()
        # Encrypted LVM on RAID
        elif var.choice == 9:
            Luks.Enable()
            Raid.Enable()
            Lvm.Enable()
        # Encrypted Normal
        elif var.choice == 10:
            Luks.Enable()
        # Exit
        elif var.choice == 11:
            Tools.Warn("Exiting.")
            quit(1)
        # Invalid Option
        else:
            Tools.Warn("Invalid Option. Exiting.")
            quit(1)

        Tools.PrintDesiredOption(var.choice)