From e4173be1b76842e865c152c0b0ef3b23eb726d12 Mon Sep 17 00:00:00 2001 From: mbusb Date: Sun, 27 Nov 2016 06:16:12 +0530 Subject: [PATCH] Added Sergei Strelec --- scripts/config.py | 2 ++ scripts/distro.py | 14 ++++++--- scripts/install.py | 23 +++++++++++---- scripts/iso.py | 19 +++++++++++-- scripts/persistence.py | 32 ++++++++++++--------- scripts/update_cfg_file.py | 58 +++++++++++++++++++++++++------------- 6 files changed, 104 insertions(+), 44 deletions(-) diff --git a/scripts/config.py b/scripts/config.py index a3e4432..74744f5 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -9,6 +9,8 @@ iso_link = "" usb_disk = "" usb_mount = "" +usb_uuid = "" +usb_label = "" persistence = 0 distro = "" status_text = "" diff --git a/scripts/distro.py b/scripts/distro.py index 4656abc..e6c99c7 100644 --- a/scripts/distro.py +++ b/scripts/distro.py @@ -13,6 +13,7 @@ import re from .iso import * from .isodump3 import ISO9660 from .gen import * +from . import _7zip from . import config @@ -23,11 +24,13 @@ def distro(iso_cfg_ext_dir, iso_link): :return: Detected distro name as string. """ iso9660fs = ISO9660(iso_link) - iso_file_list = iso9660fs.readDir("/") + # iso_file_list = iso9660fs.readDir("/") + iso_file_list = _7zip.list_iso(iso_link) if platform.system() == "Linux" or platform.system() == "Windows": for path, subdirs, files in os.walk(iso_cfg_ext_dir): for name in files: - if name.endswith('.cfg') or name.endswith('.CFG') or name.endswith('.txt') or name.endswith('.TXT'): + if name.endswith('.cfg') or name.endswith('.CFG') or name.endswith('.txt') or name.endswith('.TXT') \ + or name.endswith('.lst'): try: # errors='ignore' is required as some files also contain non utf character string = open(os.path.join(path, name), errors='ignore').read() @@ -80,7 +83,7 @@ def distro(iso_cfg_ext_dir, iso_link): return "wifislax" elif re.search(r'slax', string, re.I): return "slax" - elif re.search(r'sms|vector|autoexec', string, re.I): + elif re.search(r'sms|vector|autoexec', string, re.I) and isolinux_bin_exist(iso_link): return "sms" elif re.search(r'antix', string, re.I): return "antix" @@ -116,6 +119,8 @@ def distro(iso_cfg_ext_dir, iso_link): return "kaspersky" elif re.search(r'ALT Linux', string, re.I): return "alt-linux" + elif re.search(r'Sergei Strelec', string, re.I): + return "Windows" distro = detect_iso_from_file_list(iso_link) if distro: @@ -139,7 +144,6 @@ def detect_iso_from_file_list(iso_link): Fallback detection script from the content of an ISO. :return: supported distro as string """ - from . import _7zip if os.path.exists(iso_link): iso_file_list = _7zip.list_iso(iso_link) if any("sources" in s.lower() for s in iso_file_list) and any("boot.wim" in s.lower() for s in iso_file_list): @@ -150,6 +154,8 @@ def detect_iso_from_file_list(iso_link): return "slitaz" elif any("memtest.img" in s.lower() for s in iso_file_list): return "mentest" + elif any("menu.lst" in s.lower() for s in iso_file_list): + return "grub4dos" else: print(iso_file_list) diff --git a/scripts/install.py b/scripts/install.py index 283f8f3..20c8bb8 100644 --- a/scripts/install.py +++ b/scripts/install.py @@ -66,18 +66,29 @@ def install_distro(): iso.iso_extract_file(config.iso_link, install_dir, "kernel") copy_iso(config.iso_link, install_dir) elif config.distro == "salix-live": - iso.iso_extract_file(config.iso_link, install_dir, "boot") - config.status_text = "Copying ISO..." - copy_iso(config.iso_link, install_dir) + # iso.iso_extract_file(config.iso_link, install_dir, "boot") + iso.iso_extract_file(config.iso_link, install_dir, '*syslinux') + iso.iso_extract_file(config.iso_link, install_dir, '*menus') + iso.iso_extract_file(config.iso_link, install_dir, '*vmlinuz') + iso.iso_extract_file(config.iso_link, install_dir, '*initrd*') + iso.iso_extract_file(config.iso_link, usb_mount, '*modules') + iso.iso_extract_file(config.iso_link, usb_mount, '*packages') + iso.iso_extract_file(config.iso_link, usb_mount, '*optional') + iso.iso_extract_file(config.iso_link, usb_mount, '*liveboot') + #iso.iso_extract_full(config.iso_link, usb_mount) + # config.status_text = "Copying ISO..." + # copy_iso(config.iso_link, install_dir) elif config.distro == 'sgrubd2': copy_iso(config.iso_link, install_dir) elif config.distro == 'alt-linux': iso.iso_extract_file(config.iso_link, install_dir, '-xr!*rescue') iso.iso_extract_file(config.iso_link, config.usb_mount, 'rescue') elif config.distro == "generic": - with open(os.path.join(install_dir, "generic.cfg"), "w") as f: - f.write(os.path.join(isolinux_bin_dir(config.iso_link), "generic") + ".bs") - iso_extract_full(config.iso_link, usb_mount) + #with open(os.path.join(install_dir, "generic.cfg"), "w") as f: + # f.write(os.path.join(isolinux_bin_dir(config.iso_link), "generic") + ".bs") + iso_extract_full(config.iso_link, usb_mount) + elif config.distro == 'grub4dos': + iso_extract_full(config.iso_link, usb_mount) else: iso.iso_extract_full(config.iso_link, install_dir) diff --git a/scripts/iso.py b/scripts/iso.py index 16b39af..7851bcc 100644 --- a/scripts/iso.py +++ b/scripts/iso.py @@ -100,7 +100,7 @@ def isolinux_bin_dir(iso_link): def isolinux_bin_path(iso_link): """ Detects pat to "isolinux.bin". - :return: path of "isolinux.bin" directory as string. + :return: path of "isolinux.bin" as a string. """ iso_bin_path = False if isolinux_bin_exist(iso_link) is not False: @@ -113,6 +113,21 @@ def isolinux_bin_path(iso_link): return iso_bin_path +def iso_menu_lst_path(iso_link): + """ + Detects pat to "menu.lst" of grub4dos. + :return: path of "menu.lst" as a string. + """ + menu_lst_path = False + iso_file_list = _7zip.list_iso(iso_link) + for f in iso_file_list: + if 'menu.lst' in f.lower(): + menu_lst_path = f + break + + return menu_lst_path + + def integrity(iso_link): """ Check the integrity of an ISO. @@ -162,7 +177,7 @@ def extract_cfg_file(iso_link): :param iso_link: Path to ISO file :return: """ - _pattern = ['.cfg', '.CFG', '.txt', '.TXT', 'isolinux.bin', 'ISOLINUX.BIN'] + _pattern = ['.cfg', '.CFG', '.txt', '.TXT', 'isolinux.bin', 'ISOLINUX.BIN', '.lst'] # file_list = iso_file_list(iso_link) for ext in _pattern: _7zip.extract_iso(iso_link, _iso_cfg_ext_dir, pattern='*' + ext) diff --git a/scripts/persistence.py b/scripts/persistence.py index cbca7e6..c69e9a9 100644 --- a/scripts/persistence.py +++ b/scripts/persistence.py @@ -28,6 +28,8 @@ def persistence_distro(distro, usb_disk, iso_link): usb_details = usb.details(usb_disk) usb_sf = usb_details['file_system'] usb_free_size = usb_details['size_free'] + config.usb_uuid = usb_details['uuid'] + config.usb_label = usb_details['label'] if usb_sf == 'vfat' or 'FAT32': if usb_free_size > fat_max_size: _max_size = fat_max_size @@ -45,21 +47,19 @@ def persistence_distro(distro, usb_disk, iso_link): return None, None # FIXME to get debian and fedora persistence workable... # Able to add successfully but unable to keep persistence data. - - - ''' - elif distro == "fedora": - print "Persistence option is available." - return "fedora" + elif distro == "fedora": + print("Persistence option is available.") + return "fedora", _max_size ''' - def create_persistence(): if config.distro == "ubuntu": fs_name = 'casper-rw' elif config.distro == 'debian' or config.distro == "debian-install": fs_name = 'live-rw' + elif config.distro == 'fedora': + fs_name = 'overlay-' + config.usb_label + '-' + config.usb_uuid persistence = config.persistence / 1024 / 1024 @@ -75,8 +75,13 @@ def create_persistence(): persistence_mkfs_cmd = 'echo y|' + mkfs + ' -b 1024 -L ' + fs_name + ' ' + os.path.join(config.usb_mount, 'multibootusb', iso.iso_basename(config.iso_link), fs_name) - persistence_dd_cmd = dd + ' if=/dev/zero ' \ - 'of=' + os.path.join(config.usb_mount, 'multibootusb', + if config.distro == 'fedora': + persistence_dd_cmd = dd + ' if=/dev/zero ' \ + 'of=' + os.path.join(config.usb_mount, 'multibootusb', + iso.iso_basename(config.iso_link), 'LiveOS', fs_name) + \ + ' bs=1M count=' + str(int(persistence)) + else: + persistence_dd_cmd = dd + ' if=/dev/zero of=' + os.path.join(config.usb_mount, 'multibootusb', iso.iso_basename(config.iso_link), fs_name) +\ ' bs=1M count=' + str(int(persistence)) @@ -86,10 +91,11 @@ def create_persistence(): if subprocess.call(persistence_dd_cmd, shell=True) == 0: print("\nSuccessfully created persistence file...\n") - print('Executing ==>', persistence_mkfs_cmd) - config.status_text = 'Applying filesystem to persistence file...' - if subprocess.call(persistence_mkfs_cmd, shell=True) == 0: - print("\nSuccessfully applied filesystem...\n") + if not config.distro == 'fedora': + print('Executing ==>', persistence_mkfs_cmd) + config.status_text = 'Applying filesystem to persistence file...' + if subprocess.call(persistence_mkfs_cmd, shell=True) == 0: + print("\nSuccessfully applied filesystem...\n") def extract_file(file_path, install_dir): diff --git a/scripts/update_cfg_file.py b/scripts/update_cfg_file.py index 4a95b13..a8980c7 100644 --- a/scripts/update_cfg_file.py +++ b/scripts/update_cfg_file.py @@ -74,8 +74,7 @@ def update_distro_cfg_files(iso_link, usb_disk, distro, persistence=0): iso_basename(iso_link) + '/LiveOS', string) if not persistence == 0: if re.search(r'liveimg', string, re.I): - string = re.sub(r'liveimg', - 'liveimg overlay=UUID=' + usb_uuid, string) + string = re.sub(r'liveimg', 'liveimg overlay=UUID=' + usb_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=' + usb_uuid, string) string = re.sub(r' ro ', ' rw ', string) @@ -185,6 +184,7 @@ def update_distro_cfg_files(iso_link, usb_disk, distro, persistence=0): elif distro == "salix-live": string = re.sub(r'iso_path', '/multibootusb/' + iso_basename(iso_link) + '/' + iso_name(iso_link), string) + #string = re.sub(r'initrd', 'from=/multibootusb/' + iso_basename(iso_link) + '/' + ' initrd', string) elif distro == 'alt-linux': string = re.sub(r':cdrom', ':disk', string) @@ -241,6 +241,8 @@ def update_mbusb_cfg_file(iso_link, usb_uuid, usb_mount, distro): config_file.write("CONFIG " + '/multibootusb/' + iso_basename(config.iso_link) + '/kaspersky.cfg' + "\n") config_file.write("#end " + iso_basename(iso_link) + "\n") config_file.close() + elif distro == 'grub4dos': + update_menu_lst() else: # admin.adminCmd(["mount", "-o", "remount,rw", config.usb_disk]) config_file = open(sys_cfg_file, "a") @@ -248,8 +250,11 @@ def update_mbusb_cfg_file(iso_link, usb_uuid, usb_mount, distro): config_file.write("LABEL " + iso_basename(iso_link) + "\n") config_file.write("MENU LABEL " + iso_basename(iso_link) + "\n") if distro == "salix-live": - config_file.write( - "LINUX " + '/multibootusb/' + iso_basename(iso_link) + '/boot/grub2-linux.img' + "\n") + if os.path.exists(os.path.join(config.usb_mount, 'multibootusb', iso_basename(iso_link), 'boot', 'grub2-linux.img')): + config_file.write( + "LINUX " + '/multibootusb/' + iso_basename(iso_link) + '/boot/grub2-linux.img' + "\n") + else: + config_file.write("BOOT " + '/multibootusb/' + iso_basename(iso_link) + '/' + isolinux_bin_dir(iso_link).replace("\\", "/") + '/' + distro + '.bs' + "\n") elif distro == "pclinuxos": config_file.write("kernel " + '/multibootusb/' + iso_basename(iso_link) + '/isolinux/vmlinuz' + "\n") config_file.write("append livecd=livecd root=/dev/rd/3 acpi=on vga=788 keyb=us vmalloc=256M nokmsboot " @@ -264,24 +269,25 @@ def update_mbusb_cfg_file(iso_link, usb_uuid, usb_mount, distro): config_file.write("INITRD " + "/multibootusb/" + iso_basename(iso_link) + '/' + iso_name(iso_link) + '\n') config_file.write("APPEND iso\n") else: - if distro == "generic": - distro_syslinux_install_dir = isolinux_bin_dir(iso_link) - if not isolinux_bin_dir(iso_link) == "/": - distro_sys_install_bs = os.path.join(usb_mount, isolinux_bin_dir(iso_link)) + '/' + distro + '.bs' + if isolinux_bin_exist(config.iso_link) is True: + if distro == "generic": + distro_syslinux_install_dir = isolinux_bin_dir(iso_link) + if not isolinux_bin_dir(iso_link) == "/": + distro_sys_install_bs = os.path.join(usb_mount, isolinux_bin_dir(iso_link)) + '/' + distro + '.bs' + else: + distro_sys_install_bs = '/' + distro + '.bs' else: - distro_sys_install_bs = '/' + distro + '.bs' - else: - distro_syslinux_install_dir = install_dir - distro_syslinux_install_dir = distro_syslinux_install_dir.replace(usb_mount, '') - distro_sys_install_bs = distro_syslinux_install_dir + '/' + isolinux_bin_dir(iso_link) + '/' + distro + '.bs' + distro_syslinux_install_dir = install_dir + distro_syslinux_install_dir = distro_syslinux_install_dir.replace(usb_mount, '') + distro_sys_install_bs = distro_syslinux_install_dir + '/' + isolinux_bin_dir(iso_link) + '/' + distro + '.bs' - distro_sys_install_bs = "/" + distro_sys_install_bs.replace("\\", "/") # Windows path issue. + distro_sys_install_bs = "/" + distro_sys_install_bs.replace("\\", "/") # Windows path issue. - if config.syslinux_version == '3': - config_file.write("CONFIG /multibootusb/" + iso_basename(iso_link) + '/' + isolinux_bin_dir(iso_link).replace("\\", "/") + '/isolinux.cfg\n') - config_file.write("APPEND /multibootusb/" + iso_basename(iso_link) + '/' + isolinux_bin_dir(iso_link).replace("\\", "/") + '\n') - else: - config_file.write("BOOT " + distro_sys_install_bs.replace("//", "/") + "\n") + if config.syslinux_version == '3': + config_file.write("CONFIG /multibootusb/" + iso_basename(iso_link) + '/' + isolinux_bin_dir(iso_link).replace("\\", "/") + '/isolinux.cfg\n') + config_file.write("APPEND /multibootusb/" + iso_basename(iso_link) + '/' + isolinux_bin_dir(iso_link).replace("\\", "/") + '\n') + else: + config_file.write("BOOT " + distro_sys_install_bs.replace("//", "/") + "\n") config_file.write("#end " + iso_basename(iso_link) + "\n") config_file.close() @@ -300,6 +306,7 @@ def update_mbusb_cfg_file(iso_link, usb_uuid, usb_mount, distro): "/isolinux" + "\n") ''' + def kaspersky_config(distro): if distro == 'kaspersky': return """ @@ -314,3 +321,16 @@ label hwinfo menu label Kaspersky Hardware Info kernel $INSTALL_DIR/boot/rescue append root=live:UUID= live_dir=$INSTALL_DIR/rescue/LiveOS/ subdir=$INSTALL_DIR/rescue/LiveOS/ rootfstype=auto vga=791 init=/linuxrc loop=$INSTALL_DIR/rescue/LiveOS/squashfs.img initrd=$INSTALL_DIR/boot/rescue.igz SLUG_lang=en udev liveimg quiet softlevel=boot nox hwinfo noresume doscsi nomodeset """ + + +def update_menu_lst(): + sys_cfg_file = os.path.join(config.usb_mount, "multibootusb", "syslinux.cfg") + install_dir = os.path.join(config.usb_mount, "multibootusb", iso_basename(config.iso_link)) + menu_lst = iso_menu_lst_path(config.iso_link).replace("\\", "/") + with open(sys_cfg_file, "a") as f: + f.write("#start " + iso_basename(config.iso_link) + "\n") + f.write("LABEL " + iso_basename(config.iso_link) + "\n") + f.write("MENU LABEL " + iso_basename(config.iso_link) + "\n") + f.write("KERNEL grub.exe" + "\n") + f.write('APPEND --config-file=/' + menu_lst + "\n") + f.write("#end " + iso_basename(config.iso_link) + "\n")