コード例 #1
0
    def install_default(self):
        """
        Install default syslinux/extlinux (version 4) on selected USB disk.
        """
        if config.iso_link:
            self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        mbr_bin = gen_fun.resource_path(os.path.join("tools", "mbr.bin"))
        config.status_text = "Installing default syslinux..."

        if filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs" or filesystem == "ntfs":
            if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux4")
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True)
                    path = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb")
                    quoted_exe = "\"" + syslinux_path.replace('"', '\\"') + "\""
                    quoted_path = "\"" + path.replace('"', '\\"') + "\""
                    quoted_mbusb = "\"" + gen_fun.mbusb_dir().replace('"', '\\"') + "\""
                    if filesystem == "ntfs":
                        ext_fix = []
                    else:
                        ext_fix = ["&&", "chattr", "-i", quoted_path + "/ldlinux.sys"]
                    long_cmd = ["mkdir", "-p", quoted_path,
                            "&&", "chown", "--reference", quoted_mbusb, quoted_path,
                            "&&", quoted_exe, "--install", quoted_path] + ext_fix + \
                            ["&&", "echo", "Default Extlinux install is success...",
                            "&&", "dd", "bs=440", "count=1", "conv=notrunc", "\"if=" + mbr_bin + "\"", "of=" + config.usb_disk[:-1],
                            "&&", "echo", "mbr install is success...",
                            "&&"] + self.set_boot_flag_cmd()
                    return admin.adminCmd(long_cmd) == 0

        elif filesystem == "vfat" or filesystem == "FAT32":
            if platform.system() == "Linux":
                syslinux = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4"))
                if os.access(syslinux, os.X_OK) is False:
                    subprocess.call(['chmod', '+x', syslinux])
                quoted_exe = "\"" + syslinux.replace('"', '\\"') + "\""
                long_cmd = [quoted_exe, "-i", "-d", "multibootusb", config.usb_disk,
                        "&&", "echo", "Default syslinux install is success...",
                        "&&", "dd", "bs=440", "count=1", "conv=notrunc", "\"if=" + mbr_bin + "\"", "of=" + config.usb_disk[:-1],
                        "&&", "echo", "mbr install is success...",
                        "&&"] + self.set_boot_flag_cmd()
                return admin.adminCmd(long_cmd) == 0

            elif platform.system() == "Windows":
                syslinux = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4.exe"))
                if subprocess.call(syslinux + ' -maf -d multibootusb ' + config.usb_disk, shell=True) == 0:
                    print "\nDefault syslinux install is success...\n"
                    return True
                else:
                    print "\nFailed to install default syslinux...\n"
                    return False
コード例 #2
0
class UpdateCfgFile():
    """
    Update distro and multibootusb congig file(s).
    """
    def __init__(self):
        self.usb_disk = config.usb_disk
        self.usb = USB()


    def distro_cfg_files(self):
        """
        Main function to modify/update distro specific strings on distro config files.
        :return:
        """
        #self.usb = USB()
        self.iso = ISO(config.iso_link)
        config.status_text = "Updating config files..."
        install_dir = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename())
        for dirpath, dirnames, filenames in os.walk(install_dir):
            for f in filenames:
                if f.endswith(".cfg"):
                    cfg_file = os.path.join(dirpath, f)
                    try:
                        string = open(cfg_file).read()
                    except IOError:
                        print "Unable to read " + cfg_file
                    else:
                        if not config.distro == "generic":
                            replace_text = r'\1/multibootusb/' + self.iso.iso_basename() + '/'
                            string = re.sub(r'([ \t =,])/', replace_text, string)
                    if config.distro == "ubuntu":
                        string = re.sub(r'boot=casper',
                                        'boot=casper cdrom-detect/try-usb=true floppy.allowed_drive_mask=0 ignore_uuid ignore_bootid root=UUID=' + self.usb.get_usb(config.usb_disk).uuid + ' live-media-path=/multibootusb/' +
                                        self.iso.iso_basename() + '/casper', string)
                        if not config.persistence == 0:
                            string = re.sub(r'boot=casper', 'boot=casper persistent persistent-path=/multibootusb/' +
                                            self.iso.iso_basename() + "/", string)
                    elif config.distro == "debian":
                        string = re.sub(r'boot=live', 'boot=live ignore_bootid live-media-path=/multibootusb/' +
                                        self.iso.iso_basename() + '/live', string)
                        if not config.persistence == 0:
                            string = re.sub(r'boot=live', 'boot=live persistent persistent-path=/multibootusb/' +
                                                      self.iso.iso_basename() + "/", string)

                    elif config.distro == "ubuntu-server":
                        string = re.sub(r'file', 'cdrom-detect/try-usb=true floppy.allowed_drive_mask=0 ignore_uuid ignore_bootid root=UUID=' + self.usb.get_usb(config.usb_disk).uuid + ' file', string)
                    elif config.distro == "fedora":
                        string = re.sub(r'root=\S*', 'root=UUID=' + self.usb.get_usb(config.usb_disk).uuid, string)
                        if re.search(r'liveimg', string, re.I):
                            string = re.sub(r'liveimg', 'liveimg live_dir=/multibootusb/' +
                                                     self.iso.iso_basename() + '/LiveOS', string)
                        elif re.search(r'rd.live.image', string, re.I):
                            string = re.sub(r'rd.live.image', 'rd.live.image rd.live.dir=/multibootusb/' +
                                                     self.iso.iso_basename() + '/LiveOS', string)
                        if not config.persistence == 0:
                            if re.search(r'liveimg', string, re.I):
                                string = re.sub(r'liveimg', 'liveimg overlay=UUID=' + self.usb.get_usb(config.usb_disk).uuid, string)
                            elif re.search(r'rd.live.image', string, re.I):
                                string = re.sub(r'rd.live.image', 'rd.live.image rd.live.overlay=UUID=' + self.usb.get_usb(config.usb_disk).uuid, string)
                            string = re.sub(r' ro ', ' rw ', string)
                    elif config.distro == "parted-magic":
                        if re.search(r'append', string, re.I):
                            string = re.sub(r'append', 'append directory=/multibootusb/' + self.iso.iso_basename(), string, flags=re.I)
                        string = re.sub(r'initrd=', 'directory=/multibootusb/' + self.iso.iso_basename() + '/ initrd=',
                                        string)
                    elif config.distro == "ubcd":
                        string = re.sub(r'iso_filename=\S*', 'directory=/multibootusb/' + self.iso.iso_basename(),
                                        string, flags=re.I)
                    elif config.distro == "ipcop":
                        string = re.sub(r'ipcopboot=cdrom\S*', 'ipcopboot=usb', string)
                    elif config.distro == "puppy":
                        string = re.sub(r'pmedia=cd\S*',
                                        'pmedia=usbflash psubok=TRUE psubdir=/multibootusb/' + self.iso.iso_basename() + '/',
                                        string)
                    elif config.distro == "slax":
                        string = re.sub(r'initrd=', r'from=/multibootusb/' + self.iso.iso_basename() + '/slax fromusb initrd=', string)
                    elif config.distro == "knoppix":
                        string = re.sub(r'(append)',
                                        r'\1  knoppix_dir=/multibootusb/' + self.iso.iso_basename() + '/KNOPPIX',
                                        string)
                    elif config.distro == "gentoo":
                        string = re.sub(r'append ', 'append real_root=' + config.usb_disk + ' slowusb subdir=/multibootusb/' +
                                        self.iso.iso_basename() + '/ ', string, flags=re.I)
                    elif config.distro == "systemrescuecd":
                        rows = []
                        subdir = '/multibootusb/' + self.iso.iso_basename() + '/'
                        for line in string.splitlines(True):
                            addline = True
                            if re.match(r'append.*--.*', line, flags=re.I):
                                line = re.sub(r'(append)(.*)--(.*)', r'\1\2subdir=' + subdir + r' --\3 subdir=' + subdir,
                                       line, flags=re.I)
                            elif re.match(r'append', line, flags=re.I):
                                    line = re.sub(r'(append)', r'\1 subdir=' + subdir, line, flags=re.I)
                            elif re.match(r'label rescue(32|64)_1', line, flags=re.I):
                                rows.append(line)
                                rows.append('append subdir=%s\n' % (subdir,))
                                addline = False

                            if addline:
                                rows.append(line)

                        string = ''.join(rows)
                    elif config.distro == "arch" or config.distro == "chakra":
                        string = re.sub(r'isolabel=\S*', 'isodevice=/dev/disk/by-uuid/' + self.usb.get_usb(config.usb_disk).uuid, string,
                                        flags=re.I)
                        string = re.sub(r'isobasedir=',
                                        'isobasedir=/multibootusb/' + self.iso.iso_basename() + '/', string,
                                        flags=re.I)
                    elif config.distro == "suse" or config.distro == "opensuse":
                        if re.search(r'opensuse_12', string, re.I):
                            string = re.sub(r'append', 'append loader=syslinux isofrom_system=/dev/disk/by-uuid/' + self.usb.get_usb(config.usb_disk).uuid + ":/" + self.iso.iso_name(), string, flags=re.I)
                        else:
                            string = re.sub(r'append', 'append loader=syslinux isofrom_device=/dev/disk/by-uuid/' + self.usb.get_usb(config.usb_disk).uuid + ' isofrom_system=/multibootusb/' + self.iso.iso_basename() + '/'+ self.iso.iso_name(), string, flags=re.I)
                    elif config.distro == "pclinuxos":
                        string = re.sub(r'livecd=',
                                        'fromusb livecd=' + '/multibootusb/' + self.iso.iso_basename() + '/',
                                        string)
                        string = re.sub(r'prompt', '#prompt', string)
                        string = re.sub(r'ui gfxboot.com', '#ui gfxboot.com', string)
                        string = re.sub(r'timeout', '#timeout', string)
                    elif config.distro == "porteus" or config.distro == "wifislax":
                        string = re.sub(r'initrd=',
                                        'from=' + '/multibootusb/' + self.iso.iso_basename() + ' initrd=', string)
                    elif config.distro == "hbcd":
                        string = re.sub(r'/HBCD', '/multibootusb/' + self.iso.iso_basename() + '/HBCD', string)
                    elif config.distro == "zenwalk":
                        string = re.sub(r'initrd=', 'from=/multibootusb/' + self.iso.iso_basename() + '/' + self.iso.iso_name() + ' initrd=', string)
                    elif config.distro == "mageialive":
                        string = re.sub(r'LABEL=\S*', 'LABEL=' + self.usb.get_usb(config.usb_disk).label, string)
                    elif config.distro == "antix":
                        string = re.sub(r'APPEND', 'image_dir=/multibootusb/' + self.iso.iso_basename(), string)
                    elif config.distro == "solydx":
                        string = re.sub(r'live-media-path=', 'live-media-path=/multibootusb/' + self.iso.iso_basename(), string)
                    elif config.distro == "salix-live":
                        string = re.sub(r'iso_path', '/multibootusb/' + self.iso.iso_basename() + '/' + self.iso.iso_name(), string)

                    config_file = open(cfg_file, "wb")
                    config_file.write(string)
                    config_file.close()

        # Patch for Ubuntu 14.10 and above which uses syslinux version 6
        if config.distro == "ubuntu" and config.sys_version == "6":
            print "Applying Ubuntu patch..."
            for module in os.listdir(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux")):
                if module.endswith(".c32"):
                    if os.path.exists(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux", module)):
                        try:
                            os.remove(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux", module))
                            print "Copying " + module
                            shutil.copy(gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "modules", "ubuntu_patch", module)),
                                    os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux", module))
                        except:
                            print "Could not copy " + module

        self.main_cfg_file()

    def main_cfg_file(self):
        """
        Update main multibootusb suslinux.cfg file after distro is installed.
        :return:
        """
        #self.usb = USB()
        self.iso = ISO(config.iso_link)
        sys_cfg_file = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", "syslinux.cfg")
        install_dir = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename())
        print "Updating main syslinux config file..."
        if os.path.exists(sys_cfg_file):

            if config.distro == "hbcd":
                if os.path.exists(os.path.join(self.usb.get_usb(config.usb_disk).mount,  "multibootusb", "menu.lst")):
                    config_file = open(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", "menu.lst"), "wb")
                    string = re.sub(r'/HBCD', '/multibootusb/' + self.iso.iso_basename() + '/HBCD', config_file)
                    config_file.write(string)
                    config_file.close()

            if config.distro == "Windows":
                if os.path.exists(sys_cfg_file):
                    config_file = open(sys_cfg_file, "a")
                    config_file.write("#start " + self.iso.iso_basename() + "\n")
                    config_file.write("LABEL " + self.iso.iso_basename() + "\n")
                    config_file.write("MENU LABEL " + self.iso.iso_basename() + "\n")
                    config_file.write("KERNEL chain.c32 hd0 1 ntldr=/bootmgr" + "\n")
                    config_file.write("#end " + self.iso.iso_basename() + "\n")
                    config_file.close()

            else:
                admin.adminCmd(["mount", "-o", "remount,rw", config.usb_disk])
                config_file = open(sys_cfg_file, "a")
                config_file.write("#start " + self.iso.iso_basename() + "\n")
                config_file.write("LABEL " + self.iso.iso_basename() + "\n")
                config_file.write("MENU LABEL " + self.iso.iso_basename() + "\n")
                if config.distro == "salix-live":
                    config_file.write(
                        "LINUX " + '/multibootusb/' + self.iso.iso_basename() + '/boot/grub2-linux.img' + "\n")
                elif config.distro == "pclinuxos":
                    config_file.write("kernel " + '/multibootusb/' + self.iso.iso_basename() + '/isolinux/vmlinuz' + "\n")
                    config_file.write("append livecd=livecd root=/dev/rd/3 acpi=on vga=788 keyb=us vmalloc=256M nokmsboot "
                                      "fromusb root=UUID=" + self.usb.get_usb(config.usb_disk).uuid + " bootfromiso=/multibootusb/" +
                                      self.iso.iso_basename() +"/" + self.iso.iso_name() + " initrd=/multibootusb/"
                                      + self.iso.iso_basename() + '/isolinux/initrd.gz' + "\n")
                elif config.distro == "mentest":
                    config_file.write("kernel " + '/multibootusb/' + self.iso.iso_basename() + '/BOOT/MEMTEST.IMG\n')
                else:
                    if config.distro == "ubuntu" and config.sys_version == "6":
                        config_file.write("CONFIG " + "/multibootusb/" + self.iso.iso_basename() +
                                          "/isolinux/isolinux.cfg" + "\n")
                        config_file.write("APPEND " + "/multibootusb/" + self.iso.iso_basename() +
                                          "/isolinux" + "\n")
                    else:
                        if config.distro == "generic":
                            distro_syslinux_install_dir = self.iso.isolinux_bin_dir()
                            if not self.iso.isolinux_bin_dir() == "/":
                                distro_sys_install_bs = os.path.join(self.usb.get_usb(config.usb_disk).mount, self.iso.isolinux_bin_dir()) + '/' + config.distro + '.bs'
                            else:
                                distro_sys_install_bs = '/' + config.distro + '.bs'
                        else:
                            distro_syslinux_install_dir = install_dir
                            distro_syslinux_install_dir = distro_syslinux_install_dir.replace(self.usb.get_usb(config.usb_disk).mount, '')
                            distro_sys_install_bs = distro_syslinux_install_dir + self.iso.isolinux_bin_dir() + '/' + config.distro + '.bs'

                        distro_sys_install_bs = "/" + distro_sys_install_bs.replace("\\", "/")  #  Windows path issue.
                        config_file.write("BOOT " + distro_sys_install_bs.replace("//", "/") + "\n")
                config_file.write("#end " + self.iso.iso_basename() + "\n")
                config_file.close()

        for dirpath, dirnames, filenames in os.walk(install_dir):
            for f in filenames:
                if f.endswith("isolinux.cfg"):
                    shutil.copy2(os.path.join(dirpath, f), os.path.join(dirpath, "syslinux.cfg"))
コード例 #3
0
    def install_distro(self):
        """
        Install syslinux/extlinux on distro isolinux directory.
        """
        self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        config.status_text = "Installing distro specific syslinux..."
        if self.iso.isolinux_bin_exist() is not True:
            print "Distro does not use isolinux/syslinux for booting ISO."
        else:
            self.iso.iso_extract_file(
                os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"),
                "isolinux.bin")
            self.iso.iso_extract_file(
                os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"),
                "ISOLINUX.BIN")
            syslinux_version = self.iso.isolinux_version(
                self.iso.isolinux_bin_path(
                    os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir")))
            if config.distro == "generic" or config.distro == "alpine":
                install_dir = self.usb.get_usb(config.usb_disk).mount
                distro_syslinux_install_dir = os.path.join(
                    install_dir,
                    self.iso.isolinux_bin_dir().strip("/")).replace(
                        self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(
                    install_dir,
                    self.iso.isolinux_bin_dir().strip("/"),
                    config.distro + '.bs')
            else:
                install_dir = os.path.join(
                    self.usb.get_usb(config.usb_disk).mount, "multibootusb",
                    self.iso.iso_basename())
                distro_syslinux_install_dir = os.path.join(
                    install_dir,
                    self.iso.isolinux_bin_dir().strip("/")).replace(
                        self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(
                    install_dir,
                    self.iso.isolinux_bin_dir().strip("/"),
                    config.distro + '.bs')

            if filesystem == "vfat" or filesystem == "FAT32":
                if syslinux_version == str(3):
                    if config.distro == "generic" and self.iso.isolinux_bin_dir(
                    ) == "/":
                        option = ""
                    else:
                        option = " -d "
                else:
                    if config.distro == "generic" and self.iso.isolinux_bin_dir(
                    ) == "/":
                        option = " -i "
                    else:
                        option = " -i -d "
                print "distro_syslinux_install_dir is " + distro_syslinux_install_dir
                print "distro_sys_install_bs is " + distro_sys_install_bs
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(),
                                                 "syslinux", "bin",
                                                 "syslinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path,
                                        shell=True) == 0
                    quoted_exe = "\"" + syslinux_path.replace('"',
                                                              '\\"') + "\""
                    quoted_install_dir = distro_syslinux_install_dir.replace(
                        '"', '\\"')
                    quoted_bs = "of=\"" + distro_sys_install_bs.replace(
                        '"', '\\"') + "\""
                    long_cmd = [
                        quoted_exe, option, quoted_install_dir,
                        config.usb_disk, "&&", "dd", "count=1",
                        "if=" + config.usb_disk, quoted_bs
                    ]
                    return admin.adminCmd(long_cmd) == 0
                elif platform.system() == "Windows":
                    syslinux_path = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin")) + \
                               "\syslinux" + syslinux_version + ".exe"
                    distro_syslinux_install_dir = "/" + distro_syslinux_install_dir.replace(
                        "\\", "/")
                    distro_sys_install_bs = distro_sys_install_bs.replace(
                        "/", "\\")
                    print "\nExecuting ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' ' +  \
                          distro_sys_install_bs + "\n"
                    if subprocess.call(syslinux_path + option +
                                       distro_syslinux_install_dir + ' ' +
                                       config.usb_disk + ' ' +
                                       distro_sys_install_bs,
                                       shell=True) == 0:
                        print "\nSyslinux install was successful on distro directory...\n"
                    else:
                        print "\nFailed to install syslinux on distro directory...\n"

            elif filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs" or filesystem == "ntfs":
                distro_syslinux_install_dir = os.path.join(
                    install_dir,
                    self.iso.isolinux_bin_dir().strip("/"))
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(),
                                                 "syslinux", "bin",
                                                 "extlinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path,
                                        shell=True) == 0
                    quoted_exe = "\"" + syslinux_path.replace('"',
                                                              '\\"') + "\""
                    quoted_install_dir = distro_syslinux_install_dir.replace(
                        '"', '\\"')
                    quoted_bs = "of=\"" + distro_sys_install_bs.replace(
                        '"', '\\"') + "\""
                    long_cmd = [
                        quoted_exe, "--install", quoted_install_dir, "&&",
                        "dd", "count=1", "if=" + config.usb_disk, quoted_bs
                    ]
                    return admin.adminCmd(long_cmd) == 0
コード例 #4
0
    def install_default(self):
        """
        Install default syslinux/extlinux (version 4) on selected USB disk.
        """
        if config.iso_link:
            self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        mbr_bin = gen_fun.resource_path(os.path.join("tools", "mbr.bin"))
        config.status_text = "Installing default syslinux..."

        if filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs" or filesystem == "ntfs":
            if platform.system() == "Linux":
                syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux",
                                             "bin", "extlinux4")
                if os.access(syslinux_path, os.X_OK) is False:
                    subprocess.call('chmod +x ' + syslinux_path, shell=True)
                path = os.path.join(
                    self.usb.get_usb(config.usb_disk).mount, "multibootusb")
                quoted_exe = "\"" + syslinux_path.replace('"', '\\"') + "\""
                quoted_path = "\"" + path.replace('"', '\\"') + "\""
                quoted_mbusb = "\"" + gen_fun.mbusb_dir().replace('"',
                                                                  '\\"') + "\""
                if filesystem == "ntfs":
                    ext_fix = []
                else:
                    ext_fix = [
                        "&&", "chattr", "-i", quoted_path + "/ldlinux.sys"
                    ]
                long_cmd = ["mkdir", "-p", quoted_path,
                        "&&", "chown", "--reference", quoted_mbusb, quoted_path,
                        "&&", quoted_exe, "--install", quoted_path] + ext_fix + \
                        ["&&", "echo", "Default Extlinux install is success...",
                        "&&", "dd", "bs=440", "count=1", "conv=notrunc", "\"if=" + mbr_bin + "\"", "of=" + config.usb_disk[:-1],
                        "&&", "echo", "mbr install is success...",
                        "&&"] + self.set_boot_flag_cmd()
                return admin.adminCmd(long_cmd) == 0

        elif filesystem == "vfat" or filesystem == "FAT32":
            if platform.system() == "Linux":
                syslinux = gen_fun.resource_path(
                    os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin",
                                 "syslinux4"))
                if os.access(syslinux, os.X_OK) is False:
                    subprocess.call(['chmod', '+x', syslinux])
                quoted_exe = "\"" + syslinux.replace('"', '\\"') + "\""
                long_cmd = [
                    quoted_exe, "-i", "-d", "multibootusb", config.usb_disk,
                    "&&", "echo", "Default syslinux install is success...",
                    "&&", "dd", "bs=440", "count=1", "conv=notrunc",
                    "\"if=" + mbr_bin + "\"", "of=" + config.usb_disk[:-1],
                    "&&", "echo", "mbr install is success...", "&&"
                ] + self.set_boot_flag_cmd()
                return admin.adminCmd(long_cmd) == 0

            elif platform.system() == "Windows":
                syslinux = gen_fun.resource_path(
                    os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin",
                                 "syslinux4.exe"))
                if subprocess.call(syslinux + ' -maf -d multibootusb ' +
                                   config.usb_disk,
                                   shell=True) == 0:
                    print "\nDefault syslinux install is success...\n"
                    return True
                else:
                    print "\nFailed to install default syslinux...\n"
                    return False
コード例 #5
0
class Syslinux():
    """
    Main Syslinux class.
    """
    def __init__(self):
        self.usb_disk = config.usb_disk
        self.usb = USB()

    def install_default(self):
        """
        Install default syslinux/extlinux (version 4) on selected USB disk.
        """
        if config.iso_link:
            self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        mbr_bin = gen_fun.resource_path(os.path.join("tools", "mbr.bin"))
        config.status_text = "Installing default syslinux..."

        if filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs" or filesystem == "ntfs":
            if platform.system() == "Linux":
                syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux",
                                             "bin", "extlinux4")
                if os.access(syslinux_path, os.X_OK) is False:
                    subprocess.call('chmod +x ' + syslinux_path, shell=True)
                path = os.path.join(
                    self.usb.get_usb(config.usb_disk).mount, "multibootusb")
                quoted_exe = "\"" + syslinux_path.replace('"', '\\"') + "\""
                quoted_path = "\"" + path.replace('"', '\\"') + "\""
                quoted_mbusb = "\"" + gen_fun.mbusb_dir().replace('"',
                                                                  '\\"') + "\""
                if filesystem == "ntfs":
                    ext_fix = []
                else:
                    ext_fix = [
                        "&&", "chattr", "-i", quoted_path + "/ldlinux.sys"
                    ]
                long_cmd = ["mkdir", "-p", quoted_path,
                        "&&", "chown", "--reference", quoted_mbusb, quoted_path,
                        "&&", quoted_exe, "--install", quoted_path] + ext_fix + \
                        ["&&", "echo", "Default Extlinux install is success...",
                        "&&", "dd", "bs=440", "count=1", "conv=notrunc", "\"if=" + mbr_bin + "\"", "of=" + config.usb_disk[:-1],
                        "&&", "echo", "mbr install is success...",
                        "&&"] + self.set_boot_flag_cmd()
                return admin.adminCmd(long_cmd) == 0

        elif filesystem == "vfat" or filesystem == "FAT32":
            if platform.system() == "Linux":
                syslinux = gen_fun.resource_path(
                    os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin",
                                 "syslinux4"))
                if os.access(syslinux, os.X_OK) is False:
                    subprocess.call(['chmod', '+x', syslinux])
                quoted_exe = "\"" + syslinux.replace('"', '\\"') + "\""
                long_cmd = [
                    quoted_exe, "-i", "-d", "multibootusb", config.usb_disk,
                    "&&", "echo", "Default syslinux install is success...",
                    "&&", "dd", "bs=440", "count=1", "conv=notrunc",
                    "\"if=" + mbr_bin + "\"", "of=" + config.usb_disk[:-1],
                    "&&", "echo", "mbr install is success...", "&&"
                ] + self.set_boot_flag_cmd()
                return admin.adminCmd(long_cmd) == 0

            elif platform.system() == "Windows":
                syslinux = gen_fun.resource_path(
                    os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin",
                                 "syslinux4.exe"))
                if subprocess.call(syslinux + ' -maf -d multibootusb ' +
                                   config.usb_disk,
                                   shell=True) == 0:
                    print "\nDefault syslinux install is success...\n"
                    return True
                else:
                    print "\nFailed to install default syslinux...\n"
                    return False

    def install_distro(self):
        """
        Install syslinux/extlinux on distro isolinux directory.
        """
        self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        config.status_text = "Installing distro specific syslinux..."
        if self.iso.isolinux_bin_exist() is not True:
            print "Distro does not use isolinux/syslinux for booting ISO."
        else:
            self.iso.iso_extract_file(
                os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"),
                "isolinux.bin")
            self.iso.iso_extract_file(
                os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"),
                "ISOLINUX.BIN")
            syslinux_version = self.iso.isolinux_version(
                self.iso.isolinux_bin_path(
                    os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir")))
            if config.distro == "generic" or config.distro == "alpine":
                install_dir = self.usb.get_usb(config.usb_disk).mount
                distro_syslinux_install_dir = os.path.join(
                    install_dir,
                    self.iso.isolinux_bin_dir().strip("/")).replace(
                        self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(
                    install_dir,
                    self.iso.isolinux_bin_dir().strip("/"),
                    config.distro + '.bs')
            else:
                install_dir = os.path.join(
                    self.usb.get_usb(config.usb_disk).mount, "multibootusb",
                    self.iso.iso_basename())
                distro_syslinux_install_dir = os.path.join(
                    install_dir,
                    self.iso.isolinux_bin_dir().strip("/")).replace(
                        self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(
                    install_dir,
                    self.iso.isolinux_bin_dir().strip("/"),
                    config.distro + '.bs')

            if filesystem == "vfat" or filesystem == "FAT32":
                if syslinux_version == str(3):
                    if config.distro == "generic" and self.iso.isolinux_bin_dir(
                    ) == "/":
                        option = ""
                    else:
                        option = " -d "
                else:
                    if config.distro == "generic" and self.iso.isolinux_bin_dir(
                    ) == "/":
                        option = " -i "
                    else:
                        option = " -i -d "
                print "distro_syslinux_install_dir is " + distro_syslinux_install_dir
                print "distro_sys_install_bs is " + distro_sys_install_bs
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(),
                                                 "syslinux", "bin",
                                                 "syslinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path,
                                        shell=True) == 0
                    quoted_exe = "\"" + syslinux_path.replace('"',
                                                              '\\"') + "\""
                    quoted_install_dir = distro_syslinux_install_dir.replace(
                        '"', '\\"')
                    quoted_bs = "of=\"" + distro_sys_install_bs.replace(
                        '"', '\\"') + "\""
                    long_cmd = [
                        quoted_exe, option, quoted_install_dir,
                        config.usb_disk, "&&", "dd", "count=1",
                        "if=" + config.usb_disk, quoted_bs
                    ]
                    return admin.adminCmd(long_cmd) == 0
                elif platform.system() == "Windows":
                    syslinux_path = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin")) + \
                               "\syslinux" + syslinux_version + ".exe"
                    distro_syslinux_install_dir = "/" + distro_syslinux_install_dir.replace(
                        "\\", "/")
                    distro_sys_install_bs = distro_sys_install_bs.replace(
                        "/", "\\")
                    print "\nExecuting ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' ' +  \
                          distro_sys_install_bs + "\n"
                    if subprocess.call(syslinux_path + option +
                                       distro_syslinux_install_dir + ' ' +
                                       config.usb_disk + ' ' +
                                       distro_sys_install_bs,
                                       shell=True) == 0:
                        print "\nSyslinux install was successful on distro directory...\n"
                    else:
                        print "\nFailed to install syslinux on distro directory...\n"

            elif filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs" or filesystem == "ntfs":
                distro_syslinux_install_dir = os.path.join(
                    install_dir,
                    self.iso.isolinux_bin_dir().strip("/"))
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(),
                                                 "syslinux", "bin",
                                                 "extlinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path,
                                        shell=True) == 0
                    quoted_exe = "\"" + syslinux_path.replace('"',
                                                              '\\"') + "\""
                    quoted_install_dir = distro_syslinux_install_dir.replace(
                        '"', '\\"')
                    quoted_bs = "of=\"" + distro_sys_install_bs.replace(
                        '"', '\\"') + "\""
                    long_cmd = [
                        quoted_exe, "--install", quoted_install_dir, "&&",
                        "dd", "count=1", "if=" + config.usb_disk, quoted_bs
                    ]
                    return admin.adminCmd(long_cmd) == 0

    def set_boot_flag_cmd(self):
        disk = config.usb_disk[:-1]
        return [
            "echo", "Checking boot flag on " + disk, "&&", "if", "parted",
            "-m", "-s", disk, "print", "|", "grep", "-q", "boot", ";", "then",
            "echo", "Disk already has boot flag.", ";", "else", "echo",
            "Disk has no boot flag.", ";", "if", "parted", disk, "set", "1",
            "boot", "on", ";", "then", "echo",
            "Boot flag set to bootable on " + disk, ";", "else", "echo",
            "Unable to set boot flag on  " + disk, ";", "fi", ";", "fi"
        ]
コード例 #6
0
    def install_distro(self):
        """
        Install syslinux/extlinux on distro isolinux directory.
        """
        self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        config.status_text = "Installing distro specific syslinux..."
        if self.iso.isolinux_bin_exist() is not True:
            print "Distro doesnot use isolinux/syslinux for booting ISO."
        else:
            self.iso.iso_extract_file(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "isolinux.bin")
            self.iso.iso_extract_file(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "ISOLINUX.BIN")
            syslinux_version = self.iso.isolinux_version(self.iso.isolinux_bin_path(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir")))
            if config.distro == "generic" or config.distro == "alpine":
                install_dir = self.usb.get_usb(config.usb_disk).mount
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/")).replace(self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs')
            else:
                install_dir = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename())
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/")).replace(self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs')

            if filesystem == "vfat" or filesystem == "FAT32":
                if syslinux_version == str(3):
                    if config.distro == "generic" and self.iso.isolinux_bin_dir() == "/":
                        option = ""
                    else:
                        option = " -d "
                else:
                    if config.distro == "generic" and self.iso.isolinux_bin_dir() == "/":
                        option = " -i "
                    else:
                        option = " -i -d "
                print "distro_syslinux_install_dir is " + distro_syslinux_install_dir
                print "distro_sys_install_bs is " + distro_sys_install_bs
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0
                    quoted_exe = "\"" + syslinux_path.replace('"', '\\"') + "\""
                    quoted_install_dir = distro_syslinux_install_dir.replace('"', '\\"')
                    quoted_bs = "of=\"" + distro_sys_install_bs.replace('"', '\\"') + "\""
                    long_cmd = [quoted_exe, option, quoted_install_dir, config.usb_disk,
                            "&&", "dd", "count=1", "if=" + config.usb_disk, quoted_bs]
                    return admin.adminCmd(long_cmd) == 0
                elif platform.system() == "Windows":
                    syslinux_path = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin")) + \
                               "\syslinux" + syslinux_version + ".exe"
                    distro_syslinux_install_dir = "/" + distro_syslinux_install_dir.replace("\\", "/")
                    distro_sys_install_bs = distro_sys_install_bs.replace("/", "\\")
                    print "\nExecuting ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' ' +  \
                          distro_sys_install_bs + "\n"
                    if subprocess.call(syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' '
                        + distro_sys_install_bs, shell=True) == 0:
                        print "\nSyslinux install was successful on distro directory...\n"
                    else:
                        print "\nFailed to install syslinux on distro directory...\n"

            elif filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs" or filesystem == "ntfs":
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"))
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0
                    quoted_exe = "\"" + syslinux_path.replace('"', '\\"') + "\""
                    quoted_install_dir = distro_syslinux_install_dir.replace('"', '\\"')
                    quoted_bs = "of=\"" + distro_sys_install_bs.replace('"', '\\"') + "\""
                    long_cmd = [quoted_exe, "--install", quoted_install_dir,
                            "&&", "dd", "count=1", "if=" + config.usb_disk, quoted_bs]
                    return admin.adminCmd(long_cmd) == 0
コード例 #7
0
ファイル: syslinux.py プロジェクト: dragon788/multibootusb
class Syslinux():
    """
    Main Syslinux class.
    """
    def __init__(self):
        self.usb_disk = config.usb_disk
        self.usb = USB()

    def install_default(self):
        """
        Install default syslinux/extlinux (version 4) on selected USB disk.
        """
        if config.iso_link:
            self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        mbr_bin = gen_fun.resource_path(os.path.join("tools", "mbr.bin"))
        config.status_text = "Installing default syslinux..."

        if filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs":
            if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux4")
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True)
                    if config.user_password:
                        print "\nExecuting ==> " + syslinux_path + " --install " + os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb\n")
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux_path +
                                                   " --install " + os.path.join(self.usb.get_usb(config.usb_disk).mount,
                                                                                "multibootusb"), shell=True) == 0:
                            print "Default Extlinux install is success..."
                            if subprocess.call('echo ' + config.user_password + ' | sudo -S dd bs=440 count=1 conv=notrunc if=' + mbr_bin +
                                                                                    ' of=' + config.usb_disk[:-1], shell=True) == 0:
                                print "mbr install is success..."
                                self.set_boot_flag()
                                return True
                            else:
                                print "Failed to install default extlinux..."
                                return False
                    else:
                        print "\nExecuting ==> " + syslinux_path + " --install " +  os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb\n")
                        if subprocess.call(syslinux_path + " --install " + os.path.join(self.usb.get_usb(config.usb_disk).mount,
                                                                                    "multibootusb"), shell=True) == 0:
                            print "\nExtlinux install on distro directory is success...\n"
                            if subprocess.call('dd bs=440 count=1 conv=notrunc if=' + mbr_bin +
                                                                                    ' of=' + config.usb_disk[:-1], shell=True) == 0:
                                print "\nmbr install is success...\n"
                                self.set_boot_flag()
                                return True
                            else:
                                print "\nFailed to install default extlinux...\n"
                                return False

        elif filesystem == "vfat" or filesystem == "ntfs" or filesystem == "FAT32":
            if platform.system() == "Linux":
                syslinux = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4"))
                if os.access(syslinux, os.X_OK) is False:
                    subprocess.call('chmod +x ' + syslinux, shell=True)
                if config.user_password:
                    print "Executing ==> " + syslinux + ' -i -d multibootusb ' + config.usb_disk
                    if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux + ' -i -d multibootusb ' +
                                        config.usb_disk, shell=True) == 0:
                        print "Default syslinux install is success..."
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S dd bs=440 count=1 conv=notrunc if=' + mbr_bin +
                                                                                        ' of=' + config.usb_disk[:-1], shell=True) == 0:
                            print "mbr install is success..."
                            self.set_boot_flag()
                            return True
                        else:
                            print "Failed to install default syslinux..."
                            return False
                else:
                    print "\nExecuting ==> " + syslinux + ' -i -d multibootusb ' + config.usb_disk + "\n"
                    if subprocess.call(syslinux + ' -i -d multibootusb ' + config.usb_disk, shell=True) == 0:
                        print "\nDefault syslinux install is success...\n"
                        if subprocess.call('dd bs=440 count=1 conv=notrunc if=' + mbr_bin + ' of=' + config.usb_disk[:-1],
                                           shell=True) == 0:
                            print "\nmbr install is success...\n"
                            self.set_boot_flag()
                            return True
                        else:
                            print "\nFailed to install default syslinux...\n"
                            return False

            elif platform.system() == "Windows":
                syslinux = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4.exe"))
                if subprocess.call(syslinux + ' -maf -d multibootusb ' + config.usb_disk, shell=True) == 0:
                    print "Default syslinux install is success..."
                    return True
                else:
                    print "Failed to install default syslinux..."
                    return False

        self.set_boot_flag()

    def install_distro(self):
        """
        Install syslinux/extlinux on distro isolinux directory.
        """
        self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        config.status_text = "Installing distro specific syslinux..."
        if self.iso.isolinux_bin_exist() is not True:
            print "Distro doesnot use isolinux/syslinux for booting ISO."
        else:
            self.iso.iso_extract_file(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "isolinux.bin")
            self.iso.iso_extract_file(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "ISOLINUX.BIN")
            syslinux_version = self.iso.isolinux_version(self.iso.isolinux_bin_path(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir")))
            if config.distro == "generic":
                install_dir = self.usb.get_usb(config.usb_disk).mount
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/")).replace(self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs')
            else:
                install_dir = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename())
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/")).replace(self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs')

            if filesystem == "vfat" or filesystem == "ntfs" or filesystem == "FAT32":
                if syslinux_version == str(3):
                    if config.distro == "generic" and self.iso.isolinux_bin_dir() == "/":
                        option = ""
                    else:
                        option = " -d "
                else:
                    if config.distro == "generic" and self.iso.isolinux_bin_dir() == "/":
                        option = " -i "
                    else:
                        option = " -i -d "
                print "distro_syslinux_install_dir is " + distro_syslinux_install_dir
                print "distro_sys_install_bs is " + distro_sys_install_bs
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0
                    if config.user_password:
                        print "Executing ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk, shell=True) == 0:
                            print "\nSyslinux install on distro directory is success..."
                            print "\nExecuting ==> " + 'dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1\n'
                            if subprocess.call('echo ' + config.user_password + ' | sudo -S dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1', shell=True) == 0:
                                print "\nBootsector copy is success..."
                            else:
                                print "\nFailed to install syslinux on distro directory...\n"
                    else:
                        print "Executing ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk
                        if subprocess.call(syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk, shell=True) == 0:
                            print "Syslinux install on distro directory is success..."
                            print 'Executing ==> dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1'
                            if subprocess.call('dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1', shell=True) == 0:
                                print "\nBootsector copy is success...\n"
                            else:
                                print "\nFailed to copy boot sector...\n"
                        else:
                            print "\nFailed to install syslinux on distro directory...\n"
                elif platform.system() == "Windows":
                    syslinux_path = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin")) + \
                               "\syslinux" + syslinux_version + ".exe"
                    distro_syslinux_install_dir = "/" + distro_syslinux_install_dir.replace("\\", "/")
                    distro_sys_install_bs = distro_sys_install_bs.replace("/", "\\")
                    print "\nExecuting ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' ' +  \
                          distro_sys_install_bs + "\n"
                    if subprocess.call(syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' '
                        + distro_sys_install_bs, shell=True) == 0:
                        print "\nSyslinux install was successful on distro directory...\n"
                    else:
                        print "\nFailed to install syslinux on distro directory...\n"

            elif filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs":
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"))
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0
                    if config.user_password:
                        print "Executing ==> " + syslinux_path + " --install " + distro_syslinux_install_dir
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux_path + " --install " + distro_syslinux_install_dir, shell=True) == 0:
                            print "\nSyslinux install on distro directory is success..."
                            print "Executing ==> " + 'dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1'
                            if subprocess.call('echo ' + config.user_password + ' | sudo -S dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1', shell=True) == 0:
                                print "\nBootsector copy is success..."
                            else:
                                print "Failed to install syslinux on distro directory..."
                    else:
                        print "Executing ==> " + syslinux_path + " --install " + distro_syslinux_install_dir
                        if subprocess.call(syslinux_path + " --install " + distro_syslinux_install_dir, shell=True) == 0:
                            print "Syslinux install on distro directory is success..."
                            if subprocess.call('dd if=' + self.usb_disk + ' ' + 'of=' + self.usb.get_usb(config.usb_disk).mount + distro_sys_install_bs + ' count=1', shell=True) == 0:
                                print "\nBootsector copy is success..."
                            else:
                                print "Failed to install syslinux on distro directory..."

    def set_boot_flag(self):
        if platform.system() == "Linux":
            print "Checking boot flag on " + config.usb_disk[:-1]
            if config.user_password:
                cmd_out = subprocess.check_output("echo " + config.user_password + " | sudo -S parted -m -s " + config.usb_disk[:-1] + " print", shell=True)
                if "boot" in cmd_out:
                    print "Disk already has boot flag."
                else:
                    print "Executing ==>  parted " + config.usb_disk[:-1] + " set 1 boot on"
                    if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + " parted " + config.usb_disk[:-1]+ " set 1 boot on", shell=True) == 0:
                        print "Boot flag set to bootable on " + config.usb_disk[:-1]
                    else:
                        print "Unable to set boot flag on  " + config.usb_disk[:-1]
            else:
                cmd_out = subprocess.check_output("parted -m -s " + config.usb_disk[:-1] + " print", shell=True)
                if "boot" in cmd_out:
                    print "Disk " + config.usb_disk[:-1] + " already has boot flag."
                else:
                    print "Executing ==>  parted " + config.usb_disk[:-1] + " set 1 boot on"
                    if subprocess.call("parted " + config.usb_disk[:-1]+ " set 1 boot on", shell=True) == 0:
                        print "Boot flag set to bootable " + config.usb_disk[:-1]
                    else:
                        print "Unable to set boot flag on  " + config.usb_disk[:-1]
コード例 #8
0
    def main_cfg_file(self):
        """
        Update main multibootusb suslinux.cfg file after distro is installed.
        :return:
        """
        #self.usb = USB()
        self.iso = ISO(config.iso_link)
        sys_cfg_file = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", "syslinux.cfg")
        install_dir = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename())
        print "Updating main syslinux config file..."
        if os.path.exists(sys_cfg_file):

            if config.distro == "hbcd":
                if os.path.exists(os.path.join(self.usb.get_usb(config.usb_disk).mount,  "multibootusb", "menu.lst")):
                    config_file = open(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", "menu.lst"), "wb")
                    string = re.sub(r'/HBCD', '/multibootusb/' + self.iso.iso_basename() + '/HBCD', config_file)
                    config_file.write(string)
                    config_file.close()

            if config.distro == "Windows":
                if os.path.exists(sys_cfg_file):
                    config_file = open(sys_cfg_file, "a")
                    config_file.write("#start " + self.iso.iso_basename() + "\n")
                    config_file.write("LABEL " + self.iso.iso_basename() + "\n")
                    config_file.write("MENU LABEL " + self.iso.iso_basename() + "\n")
                    config_file.write("KERNEL chain.c32 hd0 1 ntldr=/bootmgr" + "\n")
                    config_file.write("#end " + self.iso.iso_basename() + "\n")
                    config_file.close()

            else:
                config_file = open(sys_cfg_file, "a")
                config_file.write("#start " + self.iso.iso_basename() + "\n")
                config_file.write("LABEL " + self.iso.iso_basename() + "\n")
                config_file.write("MENU LABEL " + self.iso.iso_basename() + "\n")
                if config.distro == "salix-live":
                    config_file.write(
                        "LINUX " + '/multibootusb/' + self.iso.iso_basename() + '/boot/grub2-linux.img' + "\n")
                elif config.distro == "pclinuxos":
                    config_file.write("kernel " + '/multibootusb/' + self.iso.iso_basename() + '/isolinux/vmlinuz' + "\n")
                    config_file.write("append livecd=livecd root=/dev/rd/3 acpi=on vga=788 keyb=us vmalloc=256M nokmsboot "
                                      "fromusb root=UUID=" + self.usb.get_usb(config.usb_disk).uuid + " bootfromiso=/multibootusb/" +
                                      self.iso.iso_basename() +"/" + self.iso.iso_name() + " initrd=/multibootusb/"
                                      + self.iso.iso_basename() + '/isolinux/initrd.gz' + "\n")
                else:
                    if config.distro == "ubuntu" and config.sys_version == "6":
                        config_file.write("CONFIG " + "/multibootusb/" + self.iso.iso_basename() +
                                          "/isolinux/isolinux.cfg" + "\n")
                        config_file.write("APPEND " + "/multibootusb/" + self.iso.iso_basename() +
                                          "/isolinux" + "\n")
                    else:
                        if config.distro == "generic":
                            distro_syslinux_install_dir = self.iso.isolinux_bin_dir()
                            if not self.iso.isolinux_bin_dir() == "/":
                                distro_sys_install_bs = os.path.join(self.usb.get_usb(config.usb_disk).mount, self.iso.isolinux_bin_dir()) + '/' + config.distro + '.bs'
                            else:
                                distro_sys_install_bs = '/' + config.distro + '.bs'
                        else:
                            distro_syslinux_install_dir = install_dir
                            distro_syslinux_install_dir = distro_syslinux_install_dir.replace(self.usb.get_usb(config.usb_disk).mount, '')
                            distro_sys_install_bs = distro_syslinux_install_dir + self.iso.isolinux_bin_dir() + '/' + config.distro + '.bs'

                        distro_sys_install_bs = "/" + distro_sys_install_bs.replace("\\", "/")  #  Windows path issue.
                        config_file.write("BOOT " + distro_sys_install_bs.replace("//", "/") + "\n")
                config_file.write("#end " + self.iso.iso_basename() + "\n")
                config_file.close()

        for dirpath, dirnames, filenames in os.walk(install_dir):
            for f in filenames:
                if f.endswith("isolinux.cfg"):
                    shutil.copy2(os.path.join(dirpath, f), os.path.join(dirpath, "syslinux.cfg"))
コード例 #9
0
    def distro_cfg_files(self):
        """
        Main function to modify/update distro specific strings on distro config files.
        :return:
        """
        #self.usb = USB()
        self.iso = ISO(config.iso_link)
        config.status_text = "Updating config files..."
        install_dir = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename())
        for dirpath, dirnames, filenames in os.walk(install_dir):
            for f in filenames:
                if f.endswith(".cfg"):
                    cfg_file = os.path.join(dirpath, f)
                    try:
                        string = open(cfg_file).read()
                    except IOError:
                        print "Unable to read " + cfg_file
                    else:
                        if not config.distro == "generic":
                            replace_text = r'\1/multibootusb/' + self.iso.iso_basename() + '/'
                            string = re.sub(r'([ \t =,])/', replace_text, string)
                    if config.distro == "ubuntu":
                        string = re.sub(r'boot=casper',
                                        'boot=casper cdrom-detect/try-usb=true floppy.allowed_drive_mask=0 ignore_uuid ignore_bootid root=UUID=' + self.usb.get_usb(config.usb_disk).uuid + ' live-media-path=/multibootusb/' +
                                        self.iso.iso_basename() + '/casper', string)
                        if not config.persistence == 0:
                            string = re.sub(r'boot=casper', 'boot=casper persistent persistent-path=/multibootusb/' +
                                            self.iso.iso_basename() + "/", string)
                    elif config.distro == "debian":
                        string = re.sub(r'boot=live', 'boot=live ignore_bootid live-media-path=/multibootusb/' +
                                        self.iso.iso_basename() + '/live', string)
                        if not config.persistence == 0:
                            string = re.sub(r'boot=live', 'boot=live persistent persistent-path=/multibootusb/' +
                                                      self.iso.iso_basename() + "/", string)

                    elif config.distro == "ubuntu-server":
                        string = re.sub(r'file', 'cdrom-detect/try-usb=true floppy.allowed_drive_mask=0 ignore_uuid ignore_bootid root=UUID=' + self.usb.get_usb(config.usb_disk).uuid + ' file', string)
                    elif config.distro == "fedora":
                        string = re.sub(r'root=\S*', 'root=UUID=' + self.usb.get_usb(config.usb_disk).uuid, string)
                        if re.search(r'liveimg', string, re.I):
                            string = re.sub(r'liveimg', 'liveimg live_dir=/multibootusb/' +
                                                     self.iso.iso_basename() + '/LiveOS', string)
                        elif re.search(r'rd.live.image', string, re.I):
                            string = re.sub(r'rd.live.image', 'rd.live.image rd.live.dir=/multibootusb/' +
                                                     self.iso.iso_basename() + '/LiveOS', string)
                        if not config.persistence == 0:
                            if re.search(r'liveimg', string, re.I):
                                string = re.sub(r'liveimg', 'liveimg overlay=UUID=' + self.usb.get_usb(config.usb_disk).uuid, string)
                            elif re.search(r'rd.live.image', string, re.I):
                                string = re.sub(r'rd.live.image', 'rd.live.image rd.live.overlay=UUID=' + self.usb.get_usb(config.usb_disk).uuid, string)
                            string = re.sub(r' ro ', ' rw ', string)
                    elif config.distro == "parted-magic":
                        if re.search(r'append', string, re.I):
                            string = re.sub(r'append ', 'append directory=/multibootusb/' + self.iso.iso_basename(), string, flags=re.I)
                        string = re.sub(r'initrd=', 'directory=/multibootusb/' + self.iso.iso_basename() + '/ initrd=',
                                        string)
                    elif config.distro == "ubcd":
                        string = re.sub(r'iso_filename=\S*', 'directory=/multibootusb/' + self.iso.iso_basename(),
                                        string, flags=re.I)
                    elif config.distro == "ipcop":
                        string = re.sub(r'ipcopboot=cdrom\S*', 'ipcopboot=usb', string)
                    elif config.distro == "puppy":
                        string = re.sub(r'pmedia=cd\S*',
                                        'pmedia=usbflash psubok=TRUE psubdir=/multibootusb/' + self.iso.iso_basename() + '/',
                                        string)
                    elif config.distro == "slax":
                        string = re.sub(r'initrd=', r'from=/multibootusb/' + self.iso.iso_basename() + '/slax fromusb initrd=', string)
                    elif config.distro == "knoppix":
                        string = re.sub(r'(append)',
                                        r'\1  knoppix_dir=/multibootusb/' + self.iso.iso_basename() + '/KNOPPIX',
                                        string)
                    elif config.distro == "gentoo":
                        string = re.sub(r'append ', 'append real_root=' + config.usb_disk + ' slowusb subdir=/multibootusb/' +
                                        self.iso.iso_basename() + '/ ', string, flags=re.I)
                    elif config.distro == "systemrescuecd":
                        rows = []
                        subdir = '/multibootusb/' + self.iso.iso_basename() + '/'
                        for line in string.splitlines(True):
                            addline = True
                            if re.match(r'append.*--.*', line, flags=re.I):
                                line = re.sub(r'(append)(.*)--(.*)', r'\1\2subdir=' + subdir + r' --\3 subdir=' + subdir,
                                       line, flags=re.I)
                            elif re.match(r'append', line, flags=re.I):
                                    line = re.sub(r'(append)', r'\1 subdir=' + subdir, line, flags=re.I)
                            elif re.match(r'label rescue(32|64)_1', line, flags=re.I):
                                rows.append(line)
                                rows.append('append subdir=%s\n' % (subdir,))
                                addline = False

                            if addline:
                                rows.append(line)

                        string = ''.join(rows)
                    elif config.distro == "arch" or config.distro == "chakra":
                        string = re.sub(r'isolabel=\S*', 'isodevice=/dev/disk/by-uuid/' + self.usb.get_usb(config.usb_disk).uuid, string,
                                        flags=re.I)
                        string = re.sub(r'isobasedir=',
                                        'isobasedir=/multibootusb/' + self.iso.iso_basename() + '/', string,
                                        flags=re.I)
                    elif config.distro == "suse" or config.distro == "opensuse":
                        if re.search(r'opensuse_12', string, re.I):
                            string = re.sub(r'append', 'append loader=syslinux isofrom_system=/dev/disk/by-uuid/' + self.usb.get_usb(config.usb_disk).uuid + ":/" + self.iso.iso_name(), string, flags=re.I)
                        else:
                            string = re.sub(r'append', 'append loader=syslinux isofrom_device=/dev/disk/by-uuid/' + self.usb.get_usb(config.usb_disk).uuid + ' isofrom_system=/multibootusb/' + self.iso.iso_basename() + '/'+ self.iso.iso_name(), string, flags=re.I)
                    elif config.distro == "pclinuxos":
                        string = re.sub(r'livecd=',
                                        'fromusb livecd=' + '/multibootusb/' + self.iso.iso_basename() + '/',
                                        string)
                        string = re.sub(r'prompt', '#prompt', string)
                        string = re.sub(r'ui gfxboot.com', '#ui gfxboot.com', string)
                        string = re.sub(r'timeout', '#timeout', string)
                    elif config.distro == "porteus" or config.distro == "wifislax":
                        string = re.sub(r'initrd=',
                                        'from=' + '/multibootusb/' + self.iso.iso_basename() + ' initrd=', string)
                    elif config.distro == "hbcd":
                        string = re.sub(r'/HBCD', '/multibootusb/' + self.iso.iso_basename() + '/HBCD', string)
                    elif config.distro == "zenwalk":
                        string = re.sub(r'initrd=', 'from=/multibootusb/' + self.iso.iso_basename() + '/' + self.iso.iso_name() + ' initrd=', string)
                    elif config.distro == "mageialive":
                        string = re.sub(r'LABEL=\S*', 'LABEL=' + self.usb.get_usb(config.usb_disk).label, string)
                    elif config.distro == "antix":
                        string = re.sub(r'APPEND', 'image_dir=/multibootusb/' + self.iso.iso_basename(), string)
                    elif config.distro == "solydx":
                        string = re.sub(r'live-media-path=', 'live-media-path=/multibootusb/' + self.iso.iso_basename(), string)
                    elif config.distro == "salix-live":
                        string = re.sub(r'iso_path', '/multibootusb/' + self.iso.iso_basename() + '/' + self.iso.iso_name(), string)

                    config_file = open(cfg_file, "wb")
                    config_file.write(string)
                    config_file.close()

        # Patch for Ubuntu 14.10 and above which uses syslinux version 6
        if config.distro == "ubuntu" and config.sys_version == "6":
            print "Applying Ubuntu patch..."
            for module in os.listdir(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux")):
                if module.endswith(".c32"):
                    if os.path.exists(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux", module)):
                        try:
                            os.remove(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux", module))
                            print "Copying " + module
                            shutil.copy(gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "modules", "ubuntu_patch", module)),
                                    os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux", module))
                        except:
                            print "Could not copy " + module

        self.main_cfg_file()
コード例 #10
0
ファイル: syslinux.py プロジェクト: efisuby/multibootusb
    def install_default(self):
        """
        Install default syslinux/extlinux (version 4) on selected USB disk.
        """
        if config.iso_link:
            self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        mbr_bin = gen_fun.resource_path(os.path.join("tools", "mbr.bin"))
        config.status_text = "Installing default syslinux..."

        if filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs":
            if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux4")
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True)
                    if config.user_password:
                        print "\nExecuting ==> " + syslinux_path + " --install " + os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb\n")
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux_path +
                                                   " --install " + os.path.join(self.usb.get_usb(config.usb_disk).mount,
                                                                                "multibootusb"), shell=True) == 0:
                            print "Default Extlinux install is success..."
                            if subprocess.call('echo ' + config.user_password + ' | sudo -S dd bs=440 count=1 conv=notrunc if=' + mbr_bin +
                                                                                    ' of=' + config.usb_disk[:-1], shell=True) == 0:
                                print "mbr install is success..."
                                self.set_boot_flag()
                                return True
                            else:
                                print "Failed to install default extlinux..."
                                return False
                    else:
                        print "\nExecuting ==> " + syslinux_path + " --install " +  os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb\n")
                        if subprocess.call(syslinux_path + " --install " + os.path.join(self.usb.get_usb(config.usb_disk).mount,
                                                                                    "multibootusb"), shell=True) == 0:
                            print "\nExtlinux install on distro directory is success...\n"
                            if subprocess.call('dd bs=440 count=1 conv=notrunc if=' + mbr_bin +
                                                                                    ' of=' + config.usb_disk[:-1], shell=True) == 0:
                                print "\nmbr install is success...\n"
                                self.set_boot_flag()
                                return True
                            else:
                                print "\nFailed to install default extlinux...\n"
                                return False

        elif filesystem == "vfat" or filesystem == "ntfs" or filesystem == "FAT32":
            if platform.system() == "Linux":
                syslinux = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4"))
                if os.access(syslinux, os.X_OK) is False:
                    subprocess.call('chmod +x ' + syslinux, shell=True)
                if config.user_password:
                    print "Executing ==> " + syslinux + ' -i -d multibootusb ' + config.usb_disk
                    if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux + ' -i -d multibootusb ' +
                                        config.usb_disk, shell=True) == 0:
                        print "Default syslinux install is success..."
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S dd bs=440 count=1 conv=notrunc if=' + mbr_bin +
                                                                                        ' of=' + config.usb_disk[:-1], shell=True) == 0:
                            print "mbr install is success..."
                            self.set_boot_flag()
                            return True
                        else:
                            print "Failed to install default syslinux..."
                            return False
                else:
                    print "\nExecuting ==> " + syslinux + ' -i -d multibootusb ' + config.usb_disk + "\n"
                    if subprocess.call(syslinux + ' -i -d multibootusb ' + config.usb_disk, shell=True) == 0:
                        print "\nDefault syslinux install is success...\n"
                        if subprocess.call('dd bs=440 count=1 conv=notrunc if=' + mbr_bin + ' of=' + config.usb_disk[:-1],
                                           shell=True) == 0:
                            print "\nmbr install is success...\n"
                            self.set_boot_flag()
                            return True
                        else:
                            print "\nFailed to install default syslinux...\n"
                            return False

            elif platform.system() == "Windows":
                syslinux = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4.exe"))
                if subprocess.call(syslinux + ' -maf -d multibootusb ' + config.usb_disk, shell=True) == 0:
                    print "\nDefault syslinux install is success...\n"
                    return True
                else:
                    print "\nFailed to install default syslinux...\n"
                    return False

        self.set_boot_flag()
コード例 #11
0
class UpdateCfgFile():
    """
    Update distro and multibootusb congig file(s).
    """
    def __init__(self):
        self.usb_disk = config.usb_disk
        self.usb = USB()


    def distro_cfg_files(self):
        """
        Main function to modify/update distro specific strings on distro config files.
        :return:
        """
        #self.usb = USB()
        self.iso = ISO(config.iso_link)
        config.status_text = "Updating config files..."
        install_dir = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename())
        for dirpath, dirnames, filenames in os.walk(install_dir):
            for f in filenames:
                if f.endswith(".cfg"):
                    cfg_file = os.path.join(dirpath, f)
                    try:
                        string = open(cfg_file).read()
                    except IOError:
                        print "Unable to read " + cfg_file
                    else:
                        if not config.distro == "generic":
                            replace_text = r'\1/multibootusb/' + self.iso.iso_basename() + '/'
                            string = re.sub(r'([ \t =,])/', replace_text, string)
                    if config.distro == "ubuntu":
                        string = re.sub(r'boot=casper',
                                        'boot=casper cdrom-detect/try-usb=true floppy.allowed_drive_mask=0 ignore_uuid ignore_bootid root=UUID=' + self.usb.get_usb(config.usb_disk).uuid + ' live-media-path=/multibootusb/' +
                                        self.iso.iso_basename() + '/casper', string)
                        if not config.persistence == 0:
                            string = re.sub(r'boot=casper', 'boot=casper persistent persistent-path=/multibootusb/' +
                                            self.iso.iso_basename() + "/", string)
                    elif config.distro == "debian":
                        string = re.sub(r'boot=live', 'boot=live ignore_bootid live-media-path=/multibootusb/' +
                                        self.iso.iso_basename() + '/live', string)
                        if not config.persistence == 0:
                            string = re.sub(r'boot=live', 'boot=live persistent persistent-path=/multibootusb/' +
                                                      self.iso.iso_basename() + "/", string)

                    elif config.distro == "ubuntu-server":
                        string = re.sub(r'file', 'cdrom-detect/try-usb=true floppy.allowed_drive_mask=0 ignore_uuid ignore_bootid root=UUID=' + self.usb.get_usb(config.usb_disk).uuid + ' file', string)
                    elif config.distro == "fedora":
                        string = re.sub(r'root=\S*', 'root=UUID=' + self.usb.get_usb(config.usb_disk).uuid, string)
                        if re.search(r'liveimg', string, re.I):
                            string = re.sub(r'liveimg', 'liveimg live_dir=/multibootusb/' +
                                                     self.iso.iso_basename() + '/LiveOS', string)
                        elif re.search(r'rd.live.image', string, re.I):
                            string = re.sub(r'rd.live.image', 'rd.live.image rd.live.dir=/multibootusb/' +
                                                     self.iso.iso_basename() + '/LiveOS', string)
                        if not config.persistence == 0:
                            if re.search(r'liveimg', string, re.I):
                                string = re.sub(r'liveimg', 'liveimg overlay=UUID=' + self.usb.get_usb(config.usb_disk).uuid, string)
                            elif re.search(r'rd.live.image', string, re.I):
                                string = re.sub(r'rd.live.image', 'rd.live.image rd.live.overlay=UUID=' + self.usb.get_usb(config.usb_disk).uuid, string)
                            string = re.sub(r' ro ', ' rw ', string)
                    elif config.distro == "parted-magic":
                        if re.search(r'append', string, re.I):
                            string = re.sub(r'append ', 'append directory=/multibootusb/' + self.iso.iso_basename(), string, flags=re.I)
                        string = re.sub(r'initrd=', 'directory=/multibootusb/' + self.iso.iso_basename() + '/ initrd=',
                                        string)
                    elif config.distro == "ubcd":
                        string = re.sub(r'iso_filename=\S*', 'directory=/multibootusb/' + self.iso.iso_basename(),
                                        string, flags=re.I)
                    elif config.distro == "ipcop":
                        string = re.sub(r'ipcopboot=cdrom\S*', 'ipcopboot=usb', string)
                    elif config.distro == "puppy":
                        string = re.sub(r'pmedia=cd\S*',
                                        'pmedia=usbflash psubok=TRUE psubdir=/multibootusb/' + self.iso.iso_basename() + '/',
                                        string)
                    elif config.distro == "slax":
                        string = re.sub(r'initrd=', r'from=/multibootusb/' + self.iso.iso_basename() + '/slax fromusb initrd=', string)
                    elif config.distro == "knoppix":
                        string = re.sub(r'(append)',
                                        r'\1  knoppix_dir=/multibootusb/' + self.iso.iso_basename() + '/KNOPPIX',
                                        string)
                    elif config.distro == "gentoo":
                        string = re.sub(r'append ', 'append real_root=' + config.usb_disk + ' slowusb subdir=/multibootusb/' +
                                        self.iso.iso_basename() + '/ ', string, flags=re.I)
                    elif config.distro == "systemrescuecd":
                        rows = []
                        subdir = '/multibootusb/' + self.iso.iso_basename() + '/'
                        for line in string.splitlines(True):
                            addline = True
                            if re.match(r'append.*--.*', line, flags=re.I):
                                line = re.sub(r'(append)(.*)--(.*)', r'\1\2subdir=' + subdir + r' --\3 subdir=' + subdir,
                                       line, flags=re.I)
                            elif re.match(r'append', line, flags=re.I):
                                    line = re.sub(r'(append)', r'\1 subdir=' + subdir, line, flags=re.I)
                            elif re.match(r'label rescue(32|64)_1', line, flags=re.I):
                                rows.append(line)
                                rows.append('append subdir=%s\n' % (subdir,))
                                addline = False

                            if addline:
                                rows.append(line)

                        string = ''.join(rows)
                    elif config.distro == "arch" or config.distro == "chakra":
                        string = re.sub(r'isolabel=\S*', 'isodevice=/dev/disk/by-uuid/' + self.usb.get_usb(config.usb_disk).uuid, string,
                                        flags=re.I)
                        string = re.sub(r'isobasedir=',
                                        'isobasedir=/multibootusb/' + self.iso.iso_basename() + '/', string,
                                        flags=re.I)
                    elif config.distro == "suse" or config.distro == "opensuse":
                        if re.search(r'opensuse_12', string, re.I):
                            string = re.sub(r'append', 'append loader=syslinux isofrom_system=/dev/disk/by-uuid/' + self.usb.get_usb(config.usb_disk).uuid + ":/" + self.iso.iso_name(), string, flags=re.I)
                        else:
                            string = re.sub(r'append', 'append loader=syslinux isofrom_device=/dev/disk/by-uuid/' + self.usb.get_usb(config.usb_disk).uuid + ' isofrom_system=/multibootusb/' + self.iso.iso_basename() + '/'+ self.iso.iso_name(), string, flags=re.I)
                    elif config.distro == "pclinuxos":
                        string = re.sub(r'livecd=',
                                        'fromusb livecd=' + '/multibootusb/' + self.iso.iso_basename() + '/',
                                        string)
                        string = re.sub(r'prompt', '#prompt', string)
                        string = re.sub(r'ui gfxboot.com', '#ui gfxboot.com', string)
                        string = re.sub(r'timeout', '#timeout', string)
                    elif config.distro == "porteus" or config.distro == "wifislax":
                        string = re.sub(r'initrd=',
                                        'from=' + '/multibootusb/' + self.iso.iso_basename() + ' initrd=', string)
                    elif config.distro == "hbcd":
                        string = re.sub(r'/HBCD', '/multibootusb/' + self.iso.iso_basename() + '/HBCD', string)
                    elif config.distro == "zenwalk":
                        string = re.sub(r'initrd=', 'from=/multibootusb/' + self.iso.iso_basename() + '/' + self.iso.iso_name() + ' initrd=', string)
                    elif config.distro == "mageialive":
                        string = re.sub(r'LABEL=\S*', 'LABEL=' + self.usb.get_usb(config.usb_disk).label, string)
                    elif config.distro == "antix":
                        string = re.sub(r'APPEND', 'image_dir=/multibootusb/' + self.iso.iso_basename(), string)
                    elif config.distro == "solydx":
                        string = re.sub(r'live-media-path=', 'live-media-path=/multibootusb/' + self.iso.iso_basename(), string)
                    elif config.distro == "salix-live":
                        string = re.sub(r'iso_path', '/multibootusb/' + self.iso.iso_basename() + '/' + self.iso.iso_name(), string)

                    config_file = open(cfg_file, "wb")
                    config_file.write(string)
                    config_file.close()

        # Patch for Ubuntu 14.10 and above which uses syslinux version 6
        if config.distro == "ubuntu" and config.sys_version == "6":
            print "Applying Ubuntu patch..."
            for module in os.listdir(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux")):
                if module.endswith(".c32"):
                    if os.path.exists(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux", module)):
                        try:
                            os.remove(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux", module))
                            print "Copying " + module
                            shutil.copy(gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "modules", "ubuntu_patch", module)),
                                    os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux", module))
                        except:
                            print "Could not copy " + module

        self.main_cfg_file()

    def main_cfg_file(self):
        """
        Update main multibootusb suslinux.cfg file after distro is installed.
        :return:
        """
        #self.usb = USB()
        self.iso = ISO(config.iso_link)
        sys_cfg_file = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", "syslinux.cfg")
        install_dir = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename())
        print "Updating main syslinux config file..."
        if os.path.exists(sys_cfg_file):

            if config.distro == "hbcd":
                if os.path.exists(os.path.join(self.usb.get_usb(config.usb_disk).mount,  "multibootusb", "menu.lst")):
                    config_file = open(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", "menu.lst"), "wb")
                    string = re.sub(r'/HBCD', '/multibootusb/' + self.iso.iso_basename() + '/HBCD', config_file)
                    config_file.write(string)
                    config_file.close()

            if config.distro == "Windows":
                if os.path.exists(sys_cfg_file):
                    config_file = open(sys_cfg_file, "a")
                    config_file.write("#start " + self.iso.iso_basename() + "\n")
                    config_file.write("LABEL " + self.iso.iso_basename() + "\n")
                    config_file.write("MENU LABEL " + self.iso.iso_basename() + "\n")
                    config_file.write("KERNEL chain.c32 hd0 1 ntldr=/bootmgr" + "\n")
                    config_file.write("#end " + self.iso.iso_basename() + "\n")
                    config_file.close()

            else:
                config_file = open(sys_cfg_file, "a")
                config_file.write("#start " + self.iso.iso_basename() + "\n")
                config_file.write("LABEL " + self.iso.iso_basename() + "\n")
                config_file.write("MENU LABEL " + self.iso.iso_basename() + "\n")
                if config.distro == "salix-live":
                    config_file.write(
                        "LINUX " + '/multibootusb/' + self.iso.iso_basename() + '/boot/grub2-linux.img' + "\n")
                elif config.distro == "pclinuxos":
                    config_file.write("kernel " + '/multibootusb/' + self.iso.iso_basename() + '/isolinux/vmlinuz' + "\n")
                    config_file.write("append livecd=livecd root=/dev/rd/3 acpi=on vga=788 keyb=us vmalloc=256M nokmsboot "
                                      "fromusb root=UUID=" + self.usb.get_usb(config.usb_disk).uuid + " bootfromiso=/multibootusb/" +
                                      self.iso.iso_basename() +"/" + self.iso.iso_name() + " initrd=/multibootusb/"
                                      + self.iso.iso_basename() + '/isolinux/initrd.gz' + "\n")
                else:
                    if config.distro == "ubuntu" and config.sys_version == "6":
                        config_file.write("CONFIG " + "/multibootusb/" + self.iso.iso_basename() +
                                          "/isolinux/isolinux.cfg" + "\n")
                        config_file.write("APPEND " + "/multibootusb/" + self.iso.iso_basename() +
                                          "/isolinux" + "\n")
                    else:
                        if config.distro == "generic":
                            distro_syslinux_install_dir = self.iso.isolinux_bin_dir()
                            if not self.iso.isolinux_bin_dir() == "/":
                                distro_sys_install_bs = os.path.join(self.usb.get_usb(config.usb_disk).mount, self.iso.isolinux_bin_dir()) + '/' + config.distro + '.bs'
                            else:
                                distro_sys_install_bs = '/' + config.distro + '.bs'
                        else:
                            distro_syslinux_install_dir = install_dir
                            distro_syslinux_install_dir = distro_syslinux_install_dir.replace(self.usb.get_usb(config.usb_disk).mount, '')
                            distro_sys_install_bs = distro_syslinux_install_dir + self.iso.isolinux_bin_dir() + '/' + config.distro + '.bs'

                        distro_sys_install_bs = "/" + distro_sys_install_bs.replace("\\", "/")  #  Windows path issue.
                        config_file.write("BOOT " + distro_sys_install_bs.replace("//", "/") + "\n")
                config_file.write("#end " + self.iso.iso_basename() + "\n")
                config_file.close()

        for dirpath, dirnames, filenames in os.walk(install_dir):
            for f in filenames:
                if f.endswith("isolinux.cfg"):
                    shutil.copy2(os.path.join(dirpath, f), os.path.join(dirpath, "syslinux.cfg"))
コード例 #12
0
ファイル: syslinux.py プロジェクト: efisuby/multibootusb
class Syslinux():
    """
    Main Syslinux class.
    """
    def __init__(self):
        self.usb_disk = config.usb_disk
        self.usb = USB()

    def install_default(self):
        """
        Install default syslinux/extlinux (version 4) on selected USB disk.
        """
        if config.iso_link:
            self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        mbr_bin = gen_fun.resource_path(os.path.join("tools", "mbr.bin"))
        config.status_text = "Installing default syslinux..."

        if filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs":
            if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux4")
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True)
                    if config.user_password:
                        print "\nExecuting ==> " + syslinux_path + " --install " + os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb\n")
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux_path +
                                                   " --install " + os.path.join(self.usb.get_usb(config.usb_disk).mount,
                                                                                "multibootusb"), shell=True) == 0:
                            print "Default Extlinux install is success..."
                            if subprocess.call('echo ' + config.user_password + ' | sudo -S dd bs=440 count=1 conv=notrunc if=' + mbr_bin +
                                                                                    ' of=' + config.usb_disk[:-1], shell=True) == 0:
                                print "mbr install is success..."
                                self.set_boot_flag()
                                return True
                            else:
                                print "Failed to install default extlinux..."
                                return False
                    else:
                        print "\nExecuting ==> " + syslinux_path + " --install " +  os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb\n")
                        if subprocess.call(syslinux_path + " --install " + os.path.join(self.usb.get_usb(config.usb_disk).mount,
                                                                                    "multibootusb"), shell=True) == 0:
                            print "\nExtlinux install on distro directory is success...\n"
                            if subprocess.call('dd bs=440 count=1 conv=notrunc if=' + mbr_bin +
                                                                                    ' of=' + config.usb_disk[:-1], shell=True) == 0:
                                print "\nmbr install is success...\n"
                                self.set_boot_flag()
                                return True
                            else:
                                print "\nFailed to install default extlinux...\n"
                                return False

        elif filesystem == "vfat" or filesystem == "ntfs" or filesystem == "FAT32":
            if platform.system() == "Linux":
                syslinux = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4"))
                if os.access(syslinux, os.X_OK) is False:
                    subprocess.call('chmod +x ' + syslinux, shell=True)
                if config.user_password:
                    print "Executing ==> " + syslinux + ' -i -d multibootusb ' + config.usb_disk
                    if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux + ' -i -d multibootusb ' +
                                        config.usb_disk, shell=True) == 0:
                        print "Default syslinux install is success..."
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S dd bs=440 count=1 conv=notrunc if=' + mbr_bin +
                                                                                        ' of=' + config.usb_disk[:-1], shell=True) == 0:
                            print "mbr install is success..."
                            self.set_boot_flag()
                            return True
                        else:
                            print "Failed to install default syslinux..."
                            return False
                else:
                    print "\nExecuting ==> " + syslinux + ' -i -d multibootusb ' + config.usb_disk + "\n"
                    if subprocess.call(syslinux + ' -i -d multibootusb ' + config.usb_disk, shell=True) == 0:
                        print "\nDefault syslinux install is success...\n"
                        if subprocess.call('dd bs=440 count=1 conv=notrunc if=' + mbr_bin + ' of=' + config.usb_disk[:-1],
                                           shell=True) == 0:
                            print "\nmbr install is success...\n"
                            self.set_boot_flag()
                            return True
                        else:
                            print "\nFailed to install default syslinux...\n"
                            return False

            elif platform.system() == "Windows":
                syslinux = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4.exe"))
                if subprocess.call(syslinux + ' -maf -d multibootusb ' + config.usb_disk, shell=True) == 0:
                    print "\nDefault syslinux install is success...\n"
                    return True
                else:
                    print "\nFailed to install default syslinux...\n"
                    return False

        self.set_boot_flag()

    def install_distro(self):
        """
        Install syslinux/extlinux on distro isolinux directory.
        """
        self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        config.status_text = "Installing distro specific syslinux..."
        if self.iso.isolinux_bin_exist() is not True:
            print "Distro doesnot use isolinux/syslinux for booting ISO."
        else:
            self.iso.iso_extract_file(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "isolinux.bin")
            self.iso.iso_extract_file(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "ISOLINUX.BIN")
            syslinux_version = self.iso.isolinux_version(self.iso.isolinux_bin_path(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir")))
            if config.distro == "generic" or config.distro == "alpine":
                install_dir = self.usb.get_usb(config.usb_disk).mount
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/")).replace(self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs')
            else:
                install_dir = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename())
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/")).replace(self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs')

            if filesystem == "vfat" or filesystem == "ntfs" or filesystem == "FAT32":
                if syslinux_version == str(3):
                    if config.distro == "generic" and self.iso.isolinux_bin_dir() == "/":
                        option = ""
                    else:
                        option = " -d "
                else:
                    if config.distro == "generic" and self.iso.isolinux_bin_dir() == "/":
                        option = " -i "
                    else:
                        option = " -i -d "
                print "distro_syslinux_install_dir is " + distro_syslinux_install_dir
                print "distro_sys_install_bs is " + distro_sys_install_bs
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0
                    if config.user_password:
                        print "Executing ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk, shell=True) == 0:
                            print "\nSyslinux install on distro directory is success..."
                            print "\nExecuting ==> " + 'dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1\n'
                            if subprocess.call('echo ' + config.user_password + ' | sudo -S dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1', shell=True) == 0:
                                print "\nBootsector copy is success..."
                            else:
                                print "\nFailed to install syslinux on distro directory...\n"
                    else:
                        print "Executing ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk
                        if subprocess.call(syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk, shell=True) == 0:
                            print "Syslinux install on distro directory is success..."
                            print 'Executing ==> dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1'
                            if subprocess.call('dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1', shell=True) == 0:
                                print "\nBootsector copy is success...\n"
                            else:
                                print "\nFailed to copy boot sector...\n"
                        else:
                            print "\nFailed to install syslinux on distro directory...\n"
                elif platform.system() == "Windows":
                    syslinux_path = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin")) + \
                               "\syslinux" + syslinux_version + ".exe"
                    distro_syslinux_install_dir = "/" + distro_syslinux_install_dir.replace("\\", "/")
                    distro_sys_install_bs = distro_sys_install_bs.replace("/", "\\")
                    print "\nExecuting ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' ' +  \
                          distro_sys_install_bs + "\n"
                    if subprocess.call(syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' '
                        + distro_sys_install_bs, shell=True) == 0:
                        print "\nSyslinux install was successful on distro directory...\n"
                    else:
                        print "\nFailed to install syslinux on distro directory...\n"

            elif filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs":
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"))
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0
                    if config.user_password:
                        print "Executing ==> " + syslinux_path + " --install " + distro_syslinux_install_dir
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux_path + " --install " + distro_syslinux_install_dir, shell=True) == 0:
                            print "\nSyslinux install on distro directory is success..."
                            print "Executing ==> " + 'dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1'
                            if subprocess.call('echo ' + config.user_password + ' | sudo -S dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1', shell=True) == 0:
                                print "\nBootsector copy is success..."
                            else:
                                print "Failed to install syslinux on distro directory..."
                    else:
                        print "Executing ==> " + syslinux_path + " --install " + distro_syslinux_install_dir
                        if subprocess.call(syslinux_path + " --install " + distro_syslinux_install_dir, shell=True) == 0:
                            print "Syslinux install on distro directory is success..."
                            print "Executing ==> " + 'dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs  + ' count=1'
                            if subprocess.call('dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1', shell=True) == 0:

                                print "\nBootsector copy is success..."
                            else:
                                print "Failed to install syslinux on distro directory..."

    def set_boot_flag(self):
        if platform.system() == "Linux":
            print "Checking boot flag on " + config.usb_disk[:-1]
            if config.user_password:
                cmd_out = subprocess.check_output("echo " + config.user_password + " | sudo -S parted -m -s " + config.usb_disk[:-1] + " print", shell=True)
                if "boot" in cmd_out:
                    print "Disk already has boot flag."
                else:
                    print "Executing ==>  parted " + config.usb_disk[:-1] + " set 1 boot on"
                    if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + " parted " + config.usb_disk[:-1]+ " set 1 boot on", shell=True) == 0:
                        print "Boot flag set to bootable on " + config.usb_disk[:-1]
                    else:
                        print "Unable to set boot flag on  " + config.usb_disk[:-1]
            else:
                cmd_out = subprocess.check_output("parted -m -s " + config.usb_disk[:-1] + " print", shell=True)
                if "boot" in cmd_out:
                    print "Disk " + config.usb_disk[:-1] + " already has boot flag."
                else:
                    print "Executing ==>  parted " + config.usb_disk[:-1] + " set 1 boot on"
                    if subprocess.call("parted " + config.usb_disk[:-1]+ " set 1 boot on", shell=True) == 0:
                        print "Boot flag set to bootable " + config.usb_disk[:-1]
                    else:
                        print "Unable to set boot flag on  " + config.usb_disk[:-1]
コード例 #13
0
ファイル: syslinux.py プロジェクト: efisuby/multibootusb
    def install_distro(self):
        """
        Install syslinux/extlinux on distro isolinux directory.
        """
        self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        config.status_text = "Installing distro specific syslinux..."
        if self.iso.isolinux_bin_exist() is not True:
            print "Distro doesnot use isolinux/syslinux for booting ISO."
        else:
            self.iso.iso_extract_file(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "isolinux.bin")
            self.iso.iso_extract_file(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "ISOLINUX.BIN")
            syslinux_version = self.iso.isolinux_version(self.iso.isolinux_bin_path(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir")))
            if config.distro == "generic" or config.distro == "alpine":
                install_dir = self.usb.get_usb(config.usb_disk).mount
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/")).replace(self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs')
            else:
                install_dir = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename())
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/")).replace(self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs')

            if filesystem == "vfat" or filesystem == "ntfs" or filesystem == "FAT32":
                if syslinux_version == str(3):
                    if config.distro == "generic" and self.iso.isolinux_bin_dir() == "/":
                        option = ""
                    else:
                        option = " -d "
                else:
                    if config.distro == "generic" and self.iso.isolinux_bin_dir() == "/":
                        option = " -i "
                    else:
                        option = " -i -d "
                print "distro_syslinux_install_dir is " + distro_syslinux_install_dir
                print "distro_sys_install_bs is " + distro_sys_install_bs
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0
                    if config.user_password:
                        print "Executing ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk, shell=True) == 0:
                            print "\nSyslinux install on distro directory is success..."
                            print "\nExecuting ==> " + 'dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1\n'
                            if subprocess.call('echo ' + config.user_password + ' | sudo -S dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1', shell=True) == 0:
                                print "\nBootsector copy is success..."
                            else:
                                print "\nFailed to install syslinux on distro directory...\n"
                    else:
                        print "Executing ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk
                        if subprocess.call(syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk, shell=True) == 0:
                            print "Syslinux install on distro directory is success..."
                            print 'Executing ==> dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1'
                            if subprocess.call('dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1', shell=True) == 0:
                                print "\nBootsector copy is success...\n"
                            else:
                                print "\nFailed to copy boot sector...\n"
                        else:
                            print "\nFailed to install syslinux on distro directory...\n"
                elif platform.system() == "Windows":
                    syslinux_path = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin")) + \
                               "\syslinux" + syslinux_version + ".exe"
                    distro_syslinux_install_dir = "/" + distro_syslinux_install_dir.replace("\\", "/")
                    distro_sys_install_bs = distro_sys_install_bs.replace("/", "\\")
                    print "\nExecuting ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' ' +  \
                          distro_sys_install_bs + "\n"
                    if subprocess.call(syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' '
                        + distro_sys_install_bs, shell=True) == 0:
                        print "\nSyslinux install was successful on distro directory...\n"
                    else:
                        print "\nFailed to install syslinux on distro directory...\n"

            elif filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs":
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"))
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0
                    if config.user_password:
                        print "Executing ==> " + syslinux_path + " --install " + distro_syslinux_install_dir
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux_path + " --install " + distro_syslinux_install_dir, shell=True) == 0:
                            print "\nSyslinux install on distro directory is success..."
                            print "Executing ==> " + 'dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1'
                            if subprocess.call('echo ' + config.user_password + ' | sudo -S dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1', shell=True) == 0:
                                print "\nBootsector copy is success..."
                            else:
                                print "Failed to install syslinux on distro directory..."
                    else:
                        print "Executing ==> " + syslinux_path + " --install " + distro_syslinux_install_dir
                        if subprocess.call(syslinux_path + " --install " + distro_syslinux_install_dir, shell=True) == 0:
                            print "Syslinux install on distro directory is success..."
                            print "Executing ==> " + 'dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs  + ' count=1'
                            if subprocess.call('dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1', shell=True) == 0:

                                print "\nBootsector copy is success..."
                            else:
                                print "Failed to install syslinux on distro directory..."
コード例 #14
0
ファイル: syslinux.py プロジェクト: dragon788/multibootusb
    def install_default(self):
        """
        Install default syslinux/extlinux (version 4) on selected USB disk.
        """
        if config.iso_link:
            self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        mbr_bin = gen_fun.resource_path(os.path.join("tools", "mbr.bin"))
        config.status_text = "Installing default syslinux..."

        if filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs":
            if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux4")
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True)
                    if config.user_password:
                        print "\nExecuting ==> " + syslinux_path + " --install " + os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb\n")
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux_path +
                                                   " --install " + os.path.join(self.usb.get_usb(config.usb_disk).mount,
                                                                                "multibootusb"), shell=True) == 0:
                            print "Default Extlinux install is success..."
                            if subprocess.call('echo ' + config.user_password + ' | sudo -S dd bs=440 count=1 conv=notrunc if=' + mbr_bin +
                                                                                    ' of=' + config.usb_disk[:-1], shell=True) == 0:
                                print "mbr install is success..."
                                self.set_boot_flag()
                                return True
                            else:
                                print "Failed to install default extlinux..."
                                return False
                    else:
                        print "\nExecuting ==> " + syslinux_path + " --install " +  os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb\n")
                        if subprocess.call(syslinux_path + " --install " + os.path.join(self.usb.get_usb(config.usb_disk).mount,
                                                                                    "multibootusb"), shell=True) == 0:
                            print "\nExtlinux install on distro directory is success...\n"
                            if subprocess.call('dd bs=440 count=1 conv=notrunc if=' + mbr_bin +
                                                                                    ' of=' + config.usb_disk[:-1], shell=True) == 0:
                                print "\nmbr install is success...\n"
                                self.set_boot_flag()
                                return True
                            else:
                                print "\nFailed to install default extlinux...\n"
                                return False

        elif filesystem == "vfat" or filesystem == "ntfs" or filesystem == "FAT32":
            if platform.system() == "Linux":
                syslinux = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4"))
                if os.access(syslinux, os.X_OK) is False:
                    subprocess.call('chmod +x ' + syslinux, shell=True)
                if config.user_password:
                    print "Executing ==> " + syslinux + ' -i -d multibootusb ' + config.usb_disk
                    if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux + ' -i -d multibootusb ' +
                                        config.usb_disk, shell=True) == 0:
                        print "Default syslinux install is success..."
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S dd bs=440 count=1 conv=notrunc if=' + mbr_bin +
                                                                                        ' of=' + config.usb_disk[:-1], shell=True) == 0:
                            print "mbr install is success..."
                            self.set_boot_flag()
                            return True
                        else:
                            print "Failed to install default syslinux..."
                            return False
                else:
                    print "\nExecuting ==> " + syslinux + ' -i -d multibootusb ' + config.usb_disk + "\n"
                    if subprocess.call(syslinux + ' -i -d multibootusb ' + config.usb_disk, shell=True) == 0:
                        print "\nDefault syslinux install is success...\n"
                        if subprocess.call('dd bs=440 count=1 conv=notrunc if=' + mbr_bin + ' of=' + config.usb_disk[:-1],
                                           shell=True) == 0:
                            print "\nmbr install is success...\n"
                            self.set_boot_flag()
                            return True
                        else:
                            print "\nFailed to install default syslinux...\n"
                            return False

            elif platform.system() == "Windows":
                syslinux = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4.exe"))
                if subprocess.call(syslinux + ' -maf -d multibootusb ' + config.usb_disk, shell=True) == 0:
                    print "Default syslinux install is success..."
                    return True
                else:
                    print "Failed to install default syslinux..."
                    return False

        self.set_boot_flag()
コード例 #15
0
    def main_cfg_file(self):
        """
        Update main multibootusb suslinux.cfg file after distro is installed.
        :return:
        """
        #self.usb = USB()
        self.iso = ISO(config.iso_link)
        sys_cfg_file = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", "syslinux.cfg")
        install_dir = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename())
        print "Updating main syslinux config file..."
        if os.path.exists(sys_cfg_file):

            if config.distro == "hbcd":
                if os.path.exists(os.path.join(self.usb.get_usb(config.usb_disk).mount,  "multibootusb", "menu.lst")):
                    config_file = open(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", "menu.lst"), "wb")
                    string = re.sub(r'/HBCD', '/multibootusb/' + self.iso.iso_basename() + '/HBCD', config_file)
                    config_file.write(string)
                    config_file.close()

            if config.distro == "Windows":
                if os.path.exists(sys_cfg_file):
                    config_file = open(sys_cfg_file, "a")
                    config_file.write("#start " + self.iso.iso_basename() + "\n")
                    config_file.write("LABEL " + self.iso.iso_basename() + "\n")
                    config_file.write("MENU LABEL " + self.iso.iso_basename() + "\n")
                    config_file.write("KERNEL chain.c32 hd0 1 ntldr=/bootmgr" + "\n")
                    config_file.write("#end " + self.iso.iso_basename() + "\n")
                    config_file.close()

            else:
                admin.adminCmd(["mount", "-o", "remount,rw", config.usb_disk])
                config_file = open(sys_cfg_file, "a")
                config_file.write("#start " + self.iso.iso_basename() + "\n")
                config_file.write("LABEL " + self.iso.iso_basename() + "\n")
                config_file.write("MENU LABEL " + self.iso.iso_basename() + "\n")
                if config.distro == "salix-live":
                    config_file.write(
                        "LINUX " + '/multibootusb/' + self.iso.iso_basename() + '/boot/grub2-linux.img' + "\n")
                elif config.distro == "pclinuxos":
                    config_file.write("kernel " + '/multibootusb/' + self.iso.iso_basename() + '/isolinux/vmlinuz' + "\n")
                    config_file.write("append livecd=livecd root=/dev/rd/3 acpi=on vga=788 keyb=us vmalloc=256M nokmsboot "
                                      "fromusb root=UUID=" + self.usb.get_usb(config.usb_disk).uuid + " bootfromiso=/multibootusb/" +
                                      self.iso.iso_basename() +"/" + self.iso.iso_name() + " initrd=/multibootusb/"
                                      + self.iso.iso_basename() + '/isolinux/initrd.gz' + "\n")
                elif config.distro == "mentest":
                    config_file.write("kernel " + '/multibootusb/' + self.iso.iso_basename() + '/BOOT/MEMTEST.IMG\n')
                else:
                    if config.distro == "ubuntu" and config.sys_version == "6":
                        config_file.write("CONFIG " + "/multibootusb/" + self.iso.iso_basename() +
                                          "/isolinux/isolinux.cfg" + "\n")
                        config_file.write("APPEND " + "/multibootusb/" + self.iso.iso_basename() +
                                          "/isolinux" + "\n")
                    else:
                        if config.distro == "generic":
                            distro_syslinux_install_dir = self.iso.isolinux_bin_dir()
                            if not self.iso.isolinux_bin_dir() == "/":
                                distro_sys_install_bs = os.path.join(self.usb.get_usb(config.usb_disk).mount, self.iso.isolinux_bin_dir()) + '/' + config.distro + '.bs'
                            else:
                                distro_sys_install_bs = '/' + config.distro + '.bs'
                        else:
                            distro_syslinux_install_dir = install_dir
                            distro_syslinux_install_dir = distro_syslinux_install_dir.replace(self.usb.get_usb(config.usb_disk).mount, '')
                            distro_sys_install_bs = distro_syslinux_install_dir + self.iso.isolinux_bin_dir() + '/' + config.distro + '.bs'

                        distro_sys_install_bs = "/" + distro_sys_install_bs.replace("\\", "/")  #  Windows path issue.
                        config_file.write("BOOT " + distro_sys_install_bs.replace("//", "/") + "\n")
                config_file.write("#end " + self.iso.iso_basename() + "\n")
                config_file.close()

        for dirpath, dirnames, filenames in os.walk(install_dir):
            for f in filenames:
                if f.endswith("isolinux.cfg"):
                    shutil.copy2(os.path.join(dirpath, f), os.path.join(dirpath, "syslinux.cfg"))
コード例 #16
0
class Syslinux():
    """
    Main Syslinux class.
    """
    def __init__(self):
        self.usb_disk = config.usb_disk
        self.usb = USB()

    def install_default(self):
        """
        Install default syslinux/extlinux (version 4) on selected USB disk.
        """
        if config.iso_link:
            self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        mbr_bin = gen_fun.resource_path(os.path.join("tools", "mbr.bin"))
        config.status_text = "Installing default syslinux..."

        if filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs" or filesystem == "ntfs":
            if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux4")
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True)
                    path = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb")
                    quoted_exe = "\"" + syslinux_path.replace('"', '\\"') + "\""
                    quoted_path = "\"" + path.replace('"', '\\"') + "\""
                    quoted_mbusb = "\"" + gen_fun.mbusb_dir().replace('"', '\\"') + "\""
                    if filesystem == "ntfs":
                        ext_fix = []
                    else:
                        ext_fix = ["&&", "chattr", "-i", quoted_path + "/ldlinux.sys"]
                    long_cmd = ["mkdir", "-p", quoted_path,
                            "&&", "chown", "--reference", quoted_mbusb, quoted_path,
                            "&&", quoted_exe, "--install", quoted_path] + ext_fix + \
                            ["&&", "echo", "Default Extlinux install is success...",
                            "&&", "dd", "bs=440", "count=1", "conv=notrunc", "\"if=" + mbr_bin + "\"", "of=" + config.usb_disk[:-1],
                            "&&", "echo", "mbr install is success...",
                            "&&"] + self.set_boot_flag_cmd()
                    return admin.adminCmd(long_cmd) == 0

        elif filesystem == "vfat" or filesystem == "FAT32":
            if platform.system() == "Linux":
                syslinux = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4"))
                if os.access(syslinux, os.X_OK) is False:
                    subprocess.call(['chmod', '+x', syslinux])
                quoted_exe = "\"" + syslinux.replace('"', '\\"') + "\""
                long_cmd = [quoted_exe, "-i", "-d", "multibootusb", config.usb_disk,
                        "&&", "echo", "Default syslinux install is success...",
                        "&&", "dd", "bs=440", "count=1", "conv=notrunc", "\"if=" + mbr_bin + "\"", "of=" + config.usb_disk[:-1],
                        "&&", "echo", "mbr install is success...",
                        "&&"] + self.set_boot_flag_cmd()
                return admin.adminCmd(long_cmd) == 0

            elif platform.system() == "Windows":
                syslinux = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4.exe"))
                if subprocess.call(syslinux + ' -maf -d multibootusb ' + config.usb_disk, shell=True) == 0:
                    print "\nDefault syslinux install is success...\n"
                    return True
                else:
                    print "\nFailed to install default syslinux...\n"
                    return False

    def install_distro(self):
        """
        Install syslinux/extlinux on distro isolinux directory.
        """
        self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        config.status_text = "Installing distro specific syslinux..."
        if self.iso.isolinux_bin_exist() is not True:
            print "Distro doesnot use isolinux/syslinux for booting ISO."
        else:
            self.iso.iso_extract_file(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "isolinux.bin")
            self.iso.iso_extract_file(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "ISOLINUX.BIN")
            syslinux_version = self.iso.isolinux_version(self.iso.isolinux_bin_path(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir")))
            if config.distro == "generic" or config.distro == "alpine":
                install_dir = self.usb.get_usb(config.usb_disk).mount
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/")).replace(self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs')
            else:
                install_dir = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename())
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/")).replace(self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs')

            if filesystem == "vfat" or filesystem == "FAT32":
                if syslinux_version == str(3):
                    if config.distro == "generic" and self.iso.isolinux_bin_dir() == "/":
                        option = ""
                    else:
                        option = " -d "
                else:
                    if config.distro == "generic" and self.iso.isolinux_bin_dir() == "/":
                        option = " -i "
                    else:
                        option = " -i -d "
                print "distro_syslinux_install_dir is " + distro_syslinux_install_dir
                print "distro_sys_install_bs is " + distro_sys_install_bs
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0
                    quoted_exe = "\"" + syslinux_path.replace('"', '\\"') + "\""
                    quoted_install_dir = distro_syslinux_install_dir.replace('"', '\\"')
                    quoted_bs = "of=\"" + distro_sys_install_bs.replace('"', '\\"') + "\""
                    long_cmd = [quoted_exe, option, quoted_install_dir, config.usb_disk,
                            "&&", "dd", "count=1", "if=" + config.usb_disk, quoted_bs]
                    return admin.adminCmd(long_cmd) == 0
                elif platform.system() == "Windows":
                    syslinux_path = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin")) + \
                               "\syslinux" + syslinux_version + ".exe"
                    distro_syslinux_install_dir = "/" + distro_syslinux_install_dir.replace("\\", "/")
                    distro_sys_install_bs = distro_sys_install_bs.replace("/", "\\")
                    print "\nExecuting ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' ' +  \
                          distro_sys_install_bs + "\n"
                    if subprocess.call(syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' '
                        + distro_sys_install_bs, shell=True) == 0:
                        print "\nSyslinux install was successful on distro directory...\n"
                    else:
                        print "\nFailed to install syslinux on distro directory...\n"

            elif filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs" or filesystem == "ntfs":
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"))
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0
                    quoted_exe = "\"" + syslinux_path.replace('"', '\\"') + "\""
                    quoted_install_dir = distro_syslinux_install_dir.replace('"', '\\"')
                    quoted_bs = "of=\"" + distro_sys_install_bs.replace('"', '\\"') + "\""
                    long_cmd = [quoted_exe, "--install", quoted_install_dir,
                            "&&", "dd", "count=1", "if=" + config.usb_disk, quoted_bs]
                    return admin.adminCmd(long_cmd) == 0

    def set_boot_flag_cmd(self):
        disk = config.usb_disk[:-1]
        return ["echo", "Checking boot flag on " + disk,
                "&&", "if", "parted", "-m", "-s", disk, "print", "|", "grep", "-q", "boot", ";", "then",
                    "echo", "Disk already has boot flag.",
                ";", "else",
                    "echo", "Disk has no boot flag.", ";",
                    "if", "parted", disk, "set", "1", "boot", "on", ";", "then",
                        "echo", "Boot flag set to bootable on " + disk,
                    ";", "else",
                        "echo", "Unable to set boot flag on  " + disk,
                    ";", "fi",
                ";", "fi"]
コード例 #17
0
    def distro_cfg_files(self):
        """
        Main function to modify/update distro specific strings on distro config files.
        :return:
        """
        #self.usb = USB()
        self.iso = ISO(config.iso_link)
        config.status_text = "Updating config files..."
        install_dir = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename())
        for dirpath, dirnames, filenames in os.walk(install_dir):
            for f in filenames:
                if f.endswith(".cfg"):
                    cfg_file = os.path.join(dirpath, f)
                    try:
                        string = open(cfg_file).read()
                    except IOError:
                        print "Unable to read " + cfg_file
                    else:
                        if not config.distro == "generic":
                            replace_text = r'\1/multibootusb/' + self.iso.iso_basename() + '/'
                            string = re.sub(r'([ \t =,])/', replace_text, string)
                    if config.distro == "ubuntu":
                        string = re.sub(r'boot=casper',
                                        'boot=casper cdrom-detect/try-usb=true floppy.allowed_drive_mask=0 ignore_uuid ignore_bootid root=UUID=' + self.usb.get_usb(config.usb_disk).uuid + ' live-media-path=/multibootusb/' +
                                        self.iso.iso_basename() + '/casper', string)
                        if not config.persistence == 0:
                            string = re.sub(r'boot=casper', 'boot=casper persistent persistent-path=/multibootusb/' +
                                            self.iso.iso_basename() + "/", string)
                    elif config.distro == "debian":
                        string = re.sub(r'boot=live', 'boot=live ignore_bootid live-media-path=/multibootusb/' +
                                        self.iso.iso_basename() + '/live', string)
                        if not config.persistence == 0:
                            string = re.sub(r'boot=live', 'boot=live persistent persistent-path=/multibootusb/' +
                                                      self.iso.iso_basename() + "/", string)

                    elif config.distro == "ubuntu-server":
                        string = re.sub(r'file', 'cdrom-detect/try-usb=true floppy.allowed_drive_mask=0 ignore_uuid ignore_bootid root=UUID=' + self.usb.get_usb(config.usb_disk).uuid + ' file', string)
                    elif config.distro == "fedora":
                        string = re.sub(r'root=\S*', 'root=UUID=' + self.usb.get_usb(config.usb_disk).uuid, string)
                        if re.search(r'liveimg', string, re.I):
                            string = re.sub(r'liveimg', 'liveimg live_dir=/multibootusb/' +
                                                     self.iso.iso_basename() + '/LiveOS', string)
                        elif re.search(r'rd.live.image', string, re.I):
                            string = re.sub(r'rd.live.image', 'rd.live.image rd.live.dir=/multibootusb/' +
                                                     self.iso.iso_basename() + '/LiveOS', string)
                        if not config.persistence == 0:
                            if re.search(r'liveimg', string, re.I):
                                string = re.sub(r'liveimg', 'liveimg overlay=UUID=' + self.usb.get_usb(config.usb_disk).uuid, string)
                            elif re.search(r'rd.live.image', string, re.I):
                                string = re.sub(r'rd.live.image', 'rd.live.image rd.live.overlay=UUID=' + self.usb.get_usb(config.usb_disk).uuid, string)
                            string = re.sub(r' ro ', ' rw ', string)
                    elif config.distro == "parted-magic":
                        if re.search(r'append', string, re.I):
                            string = re.sub(r'append', 'append directory=/multibootusb/' + self.iso.iso_basename(), string, flags=re.I)
                        string = re.sub(r'initrd=', 'directory=/multibootusb/' + self.iso.iso_basename() + '/ initrd=',
                                        string)
                    elif config.distro == "ubcd":
                        string = re.sub(r'iso_filename=\S*', 'directory=/multibootusb/' + self.iso.iso_basename(),
                                        string, flags=re.I)
                    elif config.distro == "ipcop":
                        string = re.sub(r'ipcopboot=cdrom\S*', 'ipcopboot=usb', string)
                    elif config.distro == "puppy":
                        string = re.sub(r'pmedia=cd\S*',
                                        'pmedia=usbflash psubok=TRUE psubdir=/multibootusb/' + self.iso.iso_basename() + '/',
                                        string)
                    elif config.distro == "slax":
                        string = re.sub(r'initrd=', r'from=/multibootusb/' + self.iso.iso_basename() + '/slax fromusb initrd=', string)
                    elif config.distro == "knoppix":
                        string = re.sub(r'(append)',
                                        r'\1  knoppix_dir=/multibootusb/' + self.iso.iso_basename() + '/KNOPPIX',
                                        string)
                    elif config.distro == "gentoo":
                        string = re.sub(r'append ', 'append real_root=' + config.usb_disk + ' slowusb subdir=/multibootusb/' +
                                        self.iso.iso_basename() + '/ ', string, flags=re.I)
                    elif config.distro == "systemrescuecd":
                        rows = []
                        subdir = '/multibootusb/' + self.iso.iso_basename() + '/'
                        for line in string.splitlines(True):
                            addline = True
                            if re.match(r'append.*--.*', line, flags=re.I):
                                line = re.sub(r'(append)(.*)--(.*)', r'\1\2subdir=' + subdir + r' --\3 subdir=' + subdir,
                                       line, flags=re.I)
                            elif re.match(r'append', line, flags=re.I):
                                    line = re.sub(r'(append)', r'\1 subdir=' + subdir, line, flags=re.I)
                            elif re.match(r'label rescue(32|64)_1', line, flags=re.I):
                                rows.append(line)
                                rows.append('append subdir=%s\n' % (subdir,))
                                addline = False

                            if addline:
                                rows.append(line)

                        string = ''.join(rows)
                    elif config.distro == "arch" or config.distro == "chakra":
                        string = re.sub(r'isolabel=\S*', 'isodevice=/dev/disk/by-uuid/' + self.usb.get_usb(config.usb_disk).uuid, string,
                                        flags=re.I)
                        string = re.sub(r'isobasedir=',
                                        'isobasedir=/multibootusb/' + self.iso.iso_basename() + '/', string,
                                        flags=re.I)
                    elif config.distro == "suse" or config.distro == "opensuse":
                        if re.search(r'opensuse_12', string, re.I):
                            string = re.sub(r'append', 'append loader=syslinux isofrom_system=/dev/disk/by-uuid/' + self.usb.get_usb(config.usb_disk).uuid + ":/" + self.iso.iso_name(), string, flags=re.I)
                        else:
                            string = re.sub(r'append', 'append loader=syslinux isofrom_device=/dev/disk/by-uuid/' + self.usb.get_usb(config.usb_disk).uuid + ' isofrom_system=/multibootusb/' + self.iso.iso_basename() + '/'+ self.iso.iso_name(), string, flags=re.I)
                    elif config.distro == "pclinuxos":
                        string = re.sub(r'livecd=',
                                        'fromusb livecd=' + '/multibootusb/' + self.iso.iso_basename() + '/',
                                        string)
                        string = re.sub(r'prompt', '#prompt', string)
                        string = re.sub(r'ui gfxboot.com', '#ui gfxboot.com', string)
                        string = re.sub(r'timeout', '#timeout', string)
                    elif config.distro == "porteus" or config.distro == "wifislax":
                        string = re.sub(r'initrd=',
                                        'from=' + '/multibootusb/' + self.iso.iso_basename() + ' initrd=', string)
                    elif config.distro == "hbcd":
                        string = re.sub(r'/HBCD', '/multibootusb/' + self.iso.iso_basename() + '/HBCD', string)
                    elif config.distro == "zenwalk":
                        string = re.sub(r'initrd=', 'from=/multibootusb/' + self.iso.iso_basename() + '/' + self.iso.iso_name() + ' initrd=', string)
                    elif config.distro == "mageialive":
                        string = re.sub(r'LABEL=\S*', 'LABEL=' + self.usb.get_usb(config.usb_disk).label, string)
                    elif config.distro == "antix":
                        string = re.sub(r'APPEND', 'image_dir=/multibootusb/' + self.iso.iso_basename(), string)
                    elif config.distro == "solydx":
                        string = re.sub(r'live-media-path=', 'live-media-path=/multibootusb/' + self.iso.iso_basename(), string)
                    elif config.distro == "salix-live":
                        string = re.sub(r'iso_path', '/multibootusb/' + self.iso.iso_basename() + '/' + self.iso.iso_name(), string)

                    config_file = open(cfg_file, "wb")
                    config_file.write(string)
                    config_file.close()

        # Patch for Ubuntu 14.10 and above which uses syslinux version 6
        if config.distro == "ubuntu" and config.sys_version == "6":
            print "Applying Ubuntu patch..."
            for module in os.listdir(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux")):
                if module.endswith(".c32"):
                    if os.path.exists(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux", module)):
                        try:
                            os.remove(os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux", module))
                            print "Copying " + module
                            shutil.copy(gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "modules", "ubuntu_patch", module)),
                                    os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename(), "isolinux", module))
                        except:
                            print "Could not copy " + module

        self.main_cfg_file()
コード例 #18
0
ファイル: syslinux.py プロジェクト: dragon788/multibootusb
    def install_distro(self):
        """
        Install syslinux/extlinux on distro isolinux directory.
        """
        self.iso = ISO(config.iso_link)
        filesystem = self.usb.get_usb(config.usb_disk).filesystem
        config.status_text = "Installing distro specific syslinux..."
        if self.iso.isolinux_bin_exist() is not True:
            print "Distro doesnot use isolinux/syslinux for booting ISO."
        else:
            self.iso.iso_extract_file(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "isolinux.bin")
            self.iso.iso_extract_file(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "ISOLINUX.BIN")
            syslinux_version = self.iso.isolinux_version(self.iso.isolinux_bin_path(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir")))
            if config.distro == "generic":
                install_dir = self.usb.get_usb(config.usb_disk).mount
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/")).replace(self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs')
            else:
                install_dir = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename())
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/")).replace(self.usb.get_usb(config.usb_disk).mount, "")
                distro_sys_install_bs = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs')

            if filesystem == "vfat" or filesystem == "ntfs" or filesystem == "FAT32":
                if syslinux_version == str(3):
                    if config.distro == "generic" and self.iso.isolinux_bin_dir() == "/":
                        option = ""
                    else:
                        option = " -d "
                else:
                    if config.distro == "generic" and self.iso.isolinux_bin_dir() == "/":
                        option = " -i "
                    else:
                        option = " -i -d "
                print "distro_syslinux_install_dir is " + distro_syslinux_install_dir
                print "distro_sys_install_bs is " + distro_sys_install_bs
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0
                    if config.user_password:
                        print "Executing ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk, shell=True) == 0:
                            print "\nSyslinux install on distro directory is success..."
                            print "\nExecuting ==> " + 'dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1\n'
                            if subprocess.call('echo ' + config.user_password + ' | sudo -S dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1', shell=True) == 0:
                                print "\nBootsector copy is success..."
                            else:
                                print "\nFailed to install syslinux on distro directory...\n"
                    else:
                        print "Executing ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk
                        if subprocess.call(syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk, shell=True) == 0:
                            print "Syslinux install on distro directory is success..."
                            print 'Executing ==> dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1'
                            if subprocess.call('dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1', shell=True) == 0:
                                print "\nBootsector copy is success...\n"
                            else:
                                print "\nFailed to copy boot sector...\n"
                        else:
                            print "\nFailed to install syslinux on distro directory...\n"
                elif platform.system() == "Windows":
                    syslinux_path = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin")) + \
                               "\syslinux" + syslinux_version + ".exe"
                    distro_syslinux_install_dir = "/" + distro_syslinux_install_dir.replace("\\", "/")
                    distro_sys_install_bs = distro_sys_install_bs.replace("/", "\\")
                    print "\nExecuting ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' ' +  \
                          distro_sys_install_bs + "\n"
                    if subprocess.call(syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' '
                        + distro_sys_install_bs, shell=True) == 0:
                        print "\nSyslinux install was successful on distro directory...\n"
                    else:
                        print "\nFailed to install syslinux on distro directory...\n"

            elif filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs":
                distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"))
                if platform.system() == "Linux":
                    syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux") + syslinux_version
                    if os.access(syslinux_path, os.X_OK) is False:
                        subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0
                    if config.user_password:
                        print "Executing ==> " + syslinux_path + " --install " + distro_syslinux_install_dir
                        if subprocess.call('echo ' + config.user_password + ' | sudo -S ' + syslinux_path + " --install " + distro_syslinux_install_dir, shell=True) == 0:
                            print "\nSyslinux install on distro directory is success..."
                            print "Executing ==> " + 'dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1'
                            if subprocess.call('echo ' + config.user_password + ' | sudo -S dd if=' + config.usb_disk + ' ' + 'of=' + distro_sys_install_bs + ' count=1', shell=True) == 0:
                                print "\nBootsector copy is success..."
                            else:
                                print "Failed to install syslinux on distro directory..."
                    else:
                        print "Executing ==> " + syslinux_path + " --install " + distro_syslinux_install_dir
                        if subprocess.call(syslinux_path + " --install " + distro_syslinux_install_dir, shell=True) == 0:
                            print "Syslinux install on distro directory is success..."
                            if subprocess.call('dd if=' + self.usb_disk + ' ' + 'of=' + self.usb.get_usb(config.usb_disk).mount + distro_sys_install_bs + ' count=1', shell=True) == 0:
                                print "\nBootsector copy is success..."
                            else:
                                print "Failed to install syslinux on distro directory..."