2016-11-06 11:18:53 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Name: distro.py
|
|
|
|
# Purpose: Module to detect if distro types supported by multibootusb (by extracting specific files)
|
|
|
|
# Authors: Sundar
|
|
|
|
# Licence: This file is a part of multibootusb package. You can redistribute it or modify
|
|
|
|
# under the terms of GNU General Public License, v.2 or above
|
|
|
|
|
|
|
|
import os
|
|
|
|
import platform
|
|
|
|
import re
|
|
|
|
from .iso import *
|
|
|
|
from .isodump3 import ISO9660
|
|
|
|
from .gen import *
|
2016-11-27 00:46:12 +00:00
|
|
|
from . import _7zip
|
2016-11-06 11:18:53 +00:00
|
|
|
from . import config
|
|
|
|
|
|
|
|
|
|
|
|
def distro(iso_cfg_ext_dir, iso_link):
|
|
|
|
"""
|
|
|
|
Detect if distro is supported by multibootusb.
|
|
|
|
:param iso_cfg_ext_dir: Directory where *.cfg files are extracted.
|
|
|
|
:return: Detected distro name as string.
|
|
|
|
"""
|
|
|
|
iso9660fs = ISO9660(iso_link)
|
2016-11-27 00:46:12 +00:00
|
|
|
# iso_file_list = iso9660fs.readDir("/")
|
|
|
|
iso_file_list = _7zip.list_iso(iso_link)
|
2016-11-06 11:18:53 +00:00
|
|
|
if platform.system() == "Linux" or platform.system() == "Windows":
|
|
|
|
for path, subdirs, files in os.walk(iso_cfg_ext_dir):
|
|
|
|
for name in files:
|
2017-04-18 08:30:26 +00:00
|
|
|
if name.endswith(('.cfg', '.CFG', '.txt', '.TXT', '.lst')):
|
2016-11-06 11:18:53 +00:00
|
|
|
try:
|
|
|
|
# errors='ignore' is required as some files also contain non utf character
|
2017-05-03 18:08:26 +00:00
|
|
|
string = open(os.path.join(path, name), errors='ignore').read()
|
2016-11-06 11:18:53 +00:00
|
|
|
except IOError:
|
|
|
|
return "Read Error."
|
|
|
|
else:
|
|
|
|
if any("f4ubcd" in s.lower() for s in iso_file_list):
|
|
|
|
return "f4ubcd"
|
|
|
|
if re.search(r'ubcd', string, re.I):
|
|
|
|
return "ubcd"
|
|
|
|
elif re.search(r'Super Grub Disk', string, re.I):
|
2016-11-20 10:58:02 +00:00
|
|
|
return "sgrubd2"
|
2016-11-06 11:18:53 +00:00
|
|
|
elif re.search(r'hbcd', string, re.I):
|
|
|
|
return "hbcd"
|
|
|
|
elif re.search(r'systemrescuecd', string, re.I):
|
|
|
|
return "systemrescuecd"
|
|
|
|
elif re.search(r'pmagic|partedmagic', string, re.I) and isolinux_bin_exist(iso_link):
|
|
|
|
return "parted-magic"
|
|
|
|
elif re.search(r'mgalive', string, re.I): # mounting fat filesystem hard coded in to initrd.
|
|
|
|
# Can be modified only under linux.
|
|
|
|
return "mageialive"
|
|
|
|
elif re.search(r'archisolabel|misolabel', string, re.I):
|
|
|
|
return "arch"
|
|
|
|
elif re.search(r'chakraisolabel', string, re.I):
|
|
|
|
return "chakra"
|
2017-02-01 16:34:39 +00:00
|
|
|
elif re.search(r'kdeosisolabel', string, re.I):
|
|
|
|
return "kaos"
|
2016-11-06 11:18:53 +00:00
|
|
|
elif re.search(r'boot=live', string, re.I) and isolinux_bin_exist(iso_link):
|
|
|
|
return "debian"
|
2017-04-16 16:49:18 +00:00
|
|
|
elif re.search(r'grml', string, re.I) and re.search(r'live-media-path=', string, re.I):
|
|
|
|
return "grml"
|
2017-02-06 17:27:58 +00:00
|
|
|
elif re.search(r'debian-installer', string, re.I) and not any("casper" in s.lower() for s in iso_file_list):
|
2016-11-06 11:18:53 +00:00
|
|
|
return "debian-install"
|
|
|
|
elif re.search(r'solydx', string, re.I):
|
|
|
|
return "solydx"
|
|
|
|
elif re.search(r'knoppix', string, re.I):
|
|
|
|
return "knoppix"
|
2017-04-10 16:00:38 +00:00
|
|
|
elif re.search(r'root=live:CDLABEL=', string, re.I) or re.search(r'root=live:LABEL=', string, re.I):
|
2016-11-06 11:18:53 +00:00
|
|
|
return "fedora"
|
|
|
|
elif re.search(r'redhat', string, re.I):
|
|
|
|
return "redhat"
|
|
|
|
elif re.search(
|
2016-12-26 17:53:21 +00:00
|
|
|
r'slitaz|dban |ophcrack|tinycore|rescue.cpi|xpud|untangle|4mlinux|partition wizard|android-x86.png|'
|
2017-04-22 18:37:00 +00:00
|
|
|
r'riplinux|lebel dummy|http://pogostick.net/~pnh/ntpasswd/|AVG Rescue CD|lkrn', string, re.I):
|
|
|
|
return "slitaz"
|
|
|
|
elif re.search(r'minimal Slackware|Slackware-HOWTO', string, re.I):
|
|
|
|
# for minimal slackware detection
|
2016-11-06 11:18:53 +00:00
|
|
|
return "slitaz"
|
2017-04-22 18:37:00 +00:00
|
|
|
# elif re.search(r'suse', string, re.I):
|
|
|
|
# return "suse"
|
|
|
|
elif re.search(r'class opensuse', string, re.I):
|
|
|
|
return "opensuse-install"
|
2016-11-06 11:18:53 +00:00
|
|
|
elif re.search(r'boot=casper', string, re.I):
|
|
|
|
return "ubuntu"
|
|
|
|
elif re.search(r'wifislax', string, re.I):
|
|
|
|
return "wifislax"
|
|
|
|
elif re.search(r'slax', string, re.I):
|
|
|
|
return "slax"
|
2017-04-22 18:37:00 +00:00
|
|
|
elif re.search(r'sms.jpg|vector |autoexec', string, re.I) and isolinux_bin_exist(iso_link):
|
2016-11-06 11:18:53 +00:00
|
|
|
return "sms"
|
|
|
|
elif re.search(r'antix', string, re.I):
|
|
|
|
return "antix"
|
|
|
|
elif re.search(r'porteus', string, re.I):
|
|
|
|
return "porteus"
|
|
|
|
elif re.search(r'livecd=livecd|PCLinuxOS', string, re.I):
|
|
|
|
return "pclinuxos"
|
|
|
|
elif re.search(r'looptype=squashfs', string, re.I):
|
|
|
|
return "gentoo"
|
|
|
|
elif re.search(r'finnix', string, re.I):
|
|
|
|
return "finnix"
|
|
|
|
elif re.search(r'wifiway', string, re.I):
|
|
|
|
return "wifiway"
|
2017-04-16 05:07:12 +00:00
|
|
|
elif re.search(r'puppy|quirky|fatdog', string, re.I):
|
2016-11-06 11:18:53 +00:00
|
|
|
return "puppy"
|
|
|
|
elif re.search(r'ipcop', string, re.I):
|
|
|
|
return "ipcop"
|
|
|
|
elif re.search(r'ipfire', string, re.I):
|
|
|
|
return "ipfire"
|
|
|
|
elif re.search(r'zenwalk|slack|salix', string, re.I) and re.search(r'live', string, re.I):
|
|
|
|
return "salix-live"
|
|
|
|
elif re.search(r'zenwalk|slack|salix', string, re.I):
|
2017-04-22 18:37:00 +00:00
|
|
|
print(os.path.join(path, name))
|
2016-11-06 11:18:53 +00:00
|
|
|
return "zenwalk"
|
|
|
|
elif re.search(r'ubuntu server', string, re.I):
|
|
|
|
return "ubuntu-server"
|
2017-04-18 08:30:26 +00:00
|
|
|
elif re.search(r'CentOS', string, re.I):
|
|
|
|
return "centos"
|
2016-11-06 11:18:53 +00:00
|
|
|
elif re.search(r'Trinity Rescue Kit', string, re.I):
|
|
|
|
return "trinity-rescue"
|
|
|
|
elif re.search(r'alpine', string, re.I):
|
|
|
|
return "alpine"
|
|
|
|
elif re.search(r'http://support.kaspersky.com', string, re.I):
|
|
|
|
return "kaspersky"
|
2016-11-23 17:33:07 +00:00
|
|
|
elif re.search(r'ALT Linux', string, re.I):
|
|
|
|
return "alt-linux"
|
2016-11-27 00:46:12 +00:00
|
|
|
elif re.search(r'Sergei Strelec', string, re.I):
|
|
|
|
return "Windows"
|
2016-11-30 16:29:03 +00:00
|
|
|
elif re.search(r'ReactOS', string, re.I):
|
|
|
|
return "ReactOS"
|
2016-12-26 17:53:21 +00:00
|
|
|
elif re.search(r'fsecure', string, re.I):
|
|
|
|
return "fsecure"
|
2017-02-05 09:59:07 +00:00
|
|
|
elif re.search(r'default rwp', string, re.I):
|
|
|
|
return "pc-unlocker"
|
2017-04-29 09:20:21 +00:00
|
|
|
elif re.search(r'/system/stage1', string, re.I):
|
|
|
|
return 'pc-tool'
|
2017-04-29 11:10:11 +00:00
|
|
|
elif re.search(r'vba32rescue', string, re.I):
|
|
|
|
return 'grub2only'
|
2017-02-05 09:59:07 +00:00
|
|
|
|
2016-11-06 11:18:53 +00:00
|
|
|
|
|
|
|
distro = detect_iso_from_file_list(iso_link)
|
|
|
|
if distro:
|
|
|
|
return distro
|
|
|
|
# FIXME: See the below comments.
|
2017-05-03 18:08:26 +00:00
|
|
|
# else:
|
|
|
|
# # FIXME: The idea of detecting as generic is to work like a unetbootin if other methods fails.
|
|
|
|
# # This simply extracts distro to root of the USB and install syslinux on isolinux.bin directory.
|
|
|
|
# # All works fine but unable to boot the distro successfully. Also, see the generic section from
|
|
|
|
# # syslinux, update_cfg and install_distro modules.
|
|
|
|
# if self.isolinux_bin_exist():
|
|
|
|
# return "generic"
|
2016-11-06 11:18:53 +00:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def detect_iso_from_file_list(iso_link):
|
|
|
|
"""
|
|
|
|
Fallback detection script from the content of an ISO.
|
2016-11-20 10:58:02 +00:00
|
|
|
:return: supported distro as string
|
2016-11-06 11:18:53 +00:00
|
|
|
"""
|
|
|
|
if os.path.exists(iso_link):
|
2016-11-20 10:58:02 +00:00
|
|
|
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):
|
2016-11-06 11:18:53 +00:00
|
|
|
return "Windows"
|
|
|
|
elif any("config.isoclient" in s.lower() for s in iso_file_list):
|
|
|
|
return "opensuse"
|
|
|
|
elif any("dban" in s.lower() for s in iso_file_list):
|
|
|
|
return "slitaz"
|
|
|
|
elif any("memtest.img" in s.lower() for s in iso_file_list):
|
2017-04-20 09:49:15 +00:00
|
|
|
return "memtest"
|
2017-04-10 16:00:38 +00:00
|
|
|
elif any("mt86.png" in s.lower() for s in iso_file_list) and any("isolinux" in s.lower() for s in iso_file_list):
|
|
|
|
return 'raw_iso'
|
2016-11-27 00:46:12 +00:00
|
|
|
elif any("menu.lst" in s.lower() for s in iso_file_list):
|
|
|
|
return "grub4dos"
|
2017-02-05 09:59:07 +00:00
|
|
|
elif any("bootwiz.cfg" in s.lower() for s in iso_file_list) and any("bootmenu_logo.png" in s.lower() for s in iso_file_list):
|
|
|
|
return "grub4dos_iso"
|
2016-11-06 11:18:53 +00:00
|
|
|
else:
|
2016-12-26 17:53:21 +00:00
|
|
|
log(iso_file_list)
|
2016-11-06 11:18:53 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
iso_cfg_ext_dir = os.path.join(multibootusb_host_dir(), "iso_cfg_ext_dir")
|
2017-02-05 09:59:07 +00:00
|
|
|
iso_link = 'Downloads/clonezilla-live-2.4.2-32-amd64.iso'
|
2016-11-06 11:18:53 +00:00
|
|
|
iso_extract_file(iso_link, iso_cfg_ext_dir, 'cfg')
|
2016-12-26 17:53:21 +00:00
|
|
|
log(distro(iso_cfg_ext_dir))
|