mirror of
https://github.com/mbusb/multibootusb
synced 2024-11-01 15:40:16 +00:00
Merge branch 'devel' of https://github.com/mbusb/multibootusb into devel
This commit is contained in:
commit
7d45a6dfba
23
install.py
23
install.py
@ -8,7 +8,9 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
import urllib.request, urllib.error, urllib.parse
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import subprocess
|
||||
|
||||
|
||||
@ -22,7 +24,7 @@ class Install():
|
||||
|
||||
def mbusb(self):
|
||||
try:
|
||||
from PyQt5 import QtGui
|
||||
# from PyQt5 import QtGui
|
||||
if subprocess.call("python3 setup.py install --record ./.install_files.txt", shell=True) == 0:
|
||||
print("Installation finished.")
|
||||
print("Find multibootusb under system menu or run from terminal using the following command...")
|
||||
@ -52,7 +54,8 @@ class Install():
|
||||
print("You can uninstall multibootusb at any time using follwing command (with root/sudo previlage)")
|
||||
print("\nsudo ./uninstall.sh\n")
|
||||
|
||||
def internet_on(self):
|
||||
@staticmethod
|
||||
def internet_on():
|
||||
try:
|
||||
ret = urllib.request.urlopen('https://www.google.com', timeout=1)
|
||||
print("Interconnection exist.")
|
||||
@ -64,7 +67,8 @@ class Install():
|
||||
|
||||
return result
|
||||
|
||||
def supported_pac_manager(self):
|
||||
@staticmethod
|
||||
def supported_pac_manager():
|
||||
pac_managers = ["pacman", "yum", "apt-get", "zypper", "urpmi"]
|
||||
result = "0"
|
||||
for pac_man in pac_managers:
|
||||
@ -76,10 +80,12 @@ class Install():
|
||||
return False
|
||||
|
||||
|
||||
def install_dependency_package(self):
|
||||
@staticmethod
|
||||
def install_dependency_package():
|
||||
if subprocess.call("which pacman", shell=True) == 0:
|
||||
subprocess.call("pacman -Sy --noconfirm", shell=True)
|
||||
if subprocess.call("pacman -S --needed --noconfirm p7zip python-pyqt5 mtools python3-six parted util-linux python-dbus") == 0: # Thank you Neitsab for "--needed" argument.
|
||||
# Thank you Neitsab for "--needed" argument.
|
||||
if subprocess.call("pacman -S --needed --noconfirm p7zip python-pyqt5 mtools python3-six parted util-linux python-dbus") == 0:
|
||||
result = True
|
||||
elif subprocess.call("which yum", shell=True) == 0:
|
||||
subprocess.call("yum check-update", shell=True)
|
||||
@ -98,10 +104,7 @@ class Install():
|
||||
if subprocess.call("urpmi install -auto mtools util-linux p7zip python3-pyudev python3-six parted python3-qt5", shell=True) == 0:
|
||||
result = True
|
||||
|
||||
if result is not True:
|
||||
return False
|
||||
else:
|
||||
result
|
||||
return bool(result)
|
||||
|
||||
install = Install()
|
||||
|
||||
|
@ -102,7 +102,7 @@ def runAsAdmin(cmdLine=None, wait=True):
|
||||
cmd = '"%s"' % (cmdLine[0],)
|
||||
# XXX TODO: isn't there a function or something we can call to massage command line params?
|
||||
params = " ".join(['"%s"' % (x,) for x in cmdLine[1:]])
|
||||
cmdDir = ''
|
||||
# cmdDir = ''
|
||||
showCmd = win32con.SW_SHOWNORMAL
|
||||
#showCmd = win32con.SW_HIDE
|
||||
lpVerb = 'runas' # causes UAC elevation prompt.
|
||||
@ -146,19 +146,22 @@ def adminCmd(cmd, fork=False, gui=False):
|
||||
else:
|
||||
if os.system('which pkexec') == 0:
|
||||
if gui:
|
||||
cmd = ['export DISPLAY=$DISPLAY; export XAUTHORITY=$XAUTHORITY; '] + cmd # By default, pkexec disallows X11 apps. Restore DISPLAY & XAUTHORITY to allow it. man 1 pkexec/"SECURITY NOTES" section
|
||||
# By default, pkexec disallows X11 apps. Restore DISPLAY & XAUTHORITY
|
||||
# to allow it. man 1 pkexec/"SECURITY NOTES" section
|
||||
cmd = ['export DISPLAY=$DISPLAY; export XAUTHORITY=$XAUTHORITY; '] + cmd
|
||||
sudo_cmd = ['pkexec', '/bin/sh', '-c']
|
||||
elif os.system('which gksudo') == 0:
|
||||
elif os.system('which gksudo') == 0:
|
||||
sudo_cmd = ["gksudo", "--", "/bin/sh", "-c"]
|
||||
elif os.system('which gksu') == 0:
|
||||
elif os.system('which gksu') == 0:
|
||||
sudo_cmd = ["gksu"]
|
||||
elif os.system('which kdesudo') == 0:
|
||||
sudo_cmd = ["kdesudo", "-t", "-c"] # http://www.unix.com/man-page/debian/1/kdesudo/
|
||||
elif os.system('which kdesu') == 0:
|
||||
elif os.system('which kdesu') == 0:
|
||||
sudo_cmd = ["kdesu", "-t", "-c"] # http://linux.die.net/man/1/kdesu
|
||||
else:
|
||||
QtWidgets.QMessageBox.information('No root...',
|
||||
'Could not find any of: pkexec, sudo, gksu, kdesu, gksudo, or kdesudo. Please install one then restart multibootusb.')
|
||||
'Could not find any of: pkexec, sudo, gksu, kdesu, gksudo, or kdesudo.\n'
|
||||
'Please install one then restart multibootusb.')
|
||||
sys.exit(0)
|
||||
final_cmd = ' '.join(sudo_cmd + ['"' + ' '.join(cmd).replace('"', '\\"') + '"'])
|
||||
gen.log("Executing ==> " + final_cmd)
|
||||
|
@ -1,5 +1,4 @@
|
||||
import os
|
||||
import platform
|
||||
import inspect
|
||||
from . import config
|
||||
|
||||
@ -8,8 +7,8 @@ try:
|
||||
except:
|
||||
try:
|
||||
from .colorama import init as colorama_init, Fore, Back, Style
|
||||
except:
|
||||
pass
|
||||
except Exception as e:
|
||||
raise e
|
||||
finally:
|
||||
try:
|
||||
colorama_init(autoreset=True)
|
||||
@ -38,7 +37,8 @@ def fnCall():
|
||||
Prints filename:line:function for parent and grandparent.
|
||||
"""
|
||||
|
||||
if not config.debug: return
|
||||
if not config.debug:
|
||||
return
|
||||
|
||||
print(colors.OKGREEN + colors.BOLD + "=== DEBUG === | %s:%d:%s() called from %s:%d:%s()" % (
|
||||
inspect.stack()[1][1].split(os.sep)[-1],
|
||||
@ -48,4 +48,3 @@ def fnCall():
|
||||
inspect.stack()[2][2],
|
||||
inspect.stack()[2][3],
|
||||
)+colors.RESET)
|
||||
|
||||
|
@ -7,14 +7,12 @@
|
||||
# under the terms of GNU General Public License, v.2 or above
|
||||
|
||||
import os
|
||||
import string
|
||||
import platform
|
||||
import re
|
||||
from .iso import *
|
||||
from .isodump3 import ISO9660
|
||||
from .gen import *
|
||||
from . import _7zip
|
||||
from . import config
|
||||
|
||||
|
||||
def distro(iso_cfg_ext_dir, iso_link):
|
||||
@ -23,8 +21,8 @@ def distro(iso_cfg_ext_dir, iso_link):
|
||||
:param iso_cfg_ext_dir: Directory where *.cfg files are extracted.
|
||||
:return: Detected distro name as string.
|
||||
"""
|
||||
iso9660fs = ISO9660(iso_link)
|
||||
# iso_file_list = iso9660fs.readDir("/")
|
||||
# iso9660fs = ISO9660(iso_link)
|
||||
# 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):
|
||||
@ -32,7 +30,7 @@ def distro(iso_cfg_ext_dir, iso_link):
|
||||
if name.endswith(('.cfg', '.CFG', '.txt', '.TXT', '.lst')):
|
||||
try:
|
||||
# errors='ignore' is required as some files also contain non utf character
|
||||
string = open(os.path.join(path, name), errors='ignore').read()
|
||||
string = open(os.path.join(path, name), errors='ignore').read()
|
||||
except IOError:
|
||||
return "Read Error."
|
||||
else:
|
||||
@ -143,15 +141,13 @@ def distro(iso_cfg_ext_dir, iso_link):
|
||||
if distro:
|
||||
return distro
|
||||
# FIXME: See the below comments.
|
||||
'''
|
||||
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"
|
||||
'''
|
||||
# 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"
|
||||
else:
|
||||
return None
|
||||
|
||||
|
@ -194,7 +194,7 @@ def copy_mbusb_dir_usb(usb_disk):
|
||||
:param usb_mount_path: Path to USB mount.
|
||||
:return:
|
||||
"""
|
||||
from .iso import iso_size
|
||||
# from .iso import iso_size
|
||||
from .usb import details
|
||||
|
||||
usb_details = details(usb_disk)
|
||||
@ -243,17 +243,17 @@ def read_input_yes():
|
||||
return False
|
||||
|
||||
|
||||
def strings(filename, min=4):
|
||||
def strings(filename, _min=4):
|
||||
with open(filename, errors="ignore") as f:
|
||||
result = ""
|
||||
for c in f.read():
|
||||
if c in string.printable:
|
||||
result += c
|
||||
continue
|
||||
if len(result) >= min:
|
||||
if len(result) >= _min:
|
||||
yield result
|
||||
result = ""
|
||||
if len(result) >= min: # catch result at EOF
|
||||
if len(result) >= _min: # catch result at EOF
|
||||
yield result
|
||||
|
||||
|
||||
@ -392,7 +392,7 @@ def write_to_file(filepath, text):
|
||||
Simple function to write a text file
|
||||
:param filepath: Path to file
|
||||
:param text: Text to be written on to file
|
||||
:return:
|
||||
:return:
|
||||
"""
|
||||
with open(filepath, 'w') as f:
|
||||
f.write(text.strip())
|
||||
|
@ -37,10 +37,10 @@ def mbusb_update_grub_cfg():
|
||||
|
||||
grub_cfg_path = None
|
||||
syslinux_menu = None
|
||||
sys_cfg_path = None
|
||||
# sys_cfg_path = None
|
||||
loopback_cfg_path = None
|
||||
mbus_grub_cfg_path = os.path.join(config.usb_mount, 'multibootusb', 'grub', 'grub.cfg')
|
||||
iso_grub_cfg = iso.iso_file_path(config.image_path, 'grub.cfg')
|
||||
# iso_grub_cfg = iso.iso_file_path(config.image_path, 'grub.cfg')
|
||||
if iso.isolinux_bin_dir(config.image_path) is not False:
|
||||
iso_sys_cfg_path = os.path.join(iso.isolinux_bin_dir(config.image_path), 'syslinux.cfg')
|
||||
iso_iso_cfg_path = os.path.join(iso.isolinux_bin_dir(config.image_path), 'isolinux.cfg')
|
||||
@ -147,19 +147,16 @@ def grub_custom_menu(mbus_grub_cfg_path, distro):
|
||||
if distro in ['sgrubd2', 'raw_iso']:
|
||||
grub_raw_iso(mbus_grub_cfg_path)
|
||||
|
||||
'''
|
||||
with open(mbus_grub_cfg_path, 'a') as f:
|
||||
f.write("#start " + iso.iso_basename(config.image_path) + "\n")
|
||||
f.write(grub_raw_iso())
|
||||
f.write("#end " + iso.iso_basename(config.image_path) + "\n")
|
||||
|
||||
|
||||
elif iso_size_mb < 750.0:
|
||||
grub_raw_iso(mbus_grub_cfg_path)
|
||||
'''
|
||||
# with open(mbus_grub_cfg_path, 'a') as f:
|
||||
# f.write("#start " + iso.iso_basename(config.image_path) + "\n")
|
||||
# f.write(grub_raw_iso())
|
||||
# f.write("#end " + iso.iso_basename(config.image_path) + "\n")
|
||||
#
|
||||
#
|
||||
# elif iso_size_mb < 750.0:
|
||||
# grub_raw_iso(mbus_grub_cfg_path)
|
||||
|
||||
else:
|
||||
|
||||
return False
|
||||
|
||||
|
||||
@ -207,10 +204,10 @@ def extract_kernel_line(search_text, match_line, isolinux_dir):
|
||||
"""
|
||||
Function to check if kernel/linux line present in isolinux.cfg file is valid.
|
||||
If valid, then convert them in to grub accepted format
|
||||
:param search_text: Type of text is to be searched. Typically kernel or linux
|
||||
:param search_text: Type of text is to be searched. Typically kernel or linux
|
||||
:param match_line: Line containing kernel ot linux from isolinux supported .cfg files
|
||||
:param isolinux_dir: Path to isolinux directory of an ISO
|
||||
:return: Valid grub2 accepted kernel/linux line after conversion. If nothing found return ''.
|
||||
:return: Valid grub2 accepted kernel/linux line after conversion. If nothing found return ''.
|
||||
"""
|
||||
kernel_line = ''
|
||||
|
||||
@ -250,8 +247,8 @@ def extract_kernel_line(search_text, match_line, isolinux_dir):
|
||||
def iso2grub2(iso_dir):
|
||||
"""
|
||||
Function to convert syslinux configuration to grub2 accepted configuration format. Features implemented are similar
|
||||
to that of grub2 'loopback.cfg'. This 'loopback.cfg' file can be later on caled directly from grub2. The main
|
||||
advantage of this function is to generate the 'loopback.cfg' file automatically without manual involvement.
|
||||
to that of grub2 'loopback.cfg'. This 'loopback.cfg' file can be later on caled directly from grub2. The main
|
||||
advantage of this function is to generate the 'loopback.cfg' file automatically without manual involvement.
|
||||
:param iso_dir: Path to distro install directory for looping through '.cfg' files.
|
||||
:param file_out: Path to 'loopback.cfg' file. By default it is set to root of distro install directory.
|
||||
:return:
|
||||
@ -277,11 +274,11 @@ def iso2grub2(iso_dir):
|
||||
if ext_text:
|
||||
for m in ext_text:
|
||||
menuentry = ''
|
||||
kernel = ''
|
||||
# kernel = ''
|
||||
kernel_line = ''
|
||||
boot_options = ''
|
||||
initrd_line = ''
|
||||
initrd = ''
|
||||
# initrd = ''
|
||||
|
||||
# Extract line containing 'menu label' and convert to menu entry of grub2
|
||||
if 'menu label' in m.group().lower():
|
||||
@ -308,7 +305,7 @@ def iso2grub2(iso_dir):
|
||||
for _lines in kernel_text:
|
||||
kernel_line = extract_kernel_line(_lines[0][1], _lines[0][0],
|
||||
iso_bin_dir)
|
||||
if kernel_line is '':
|
||||
if kernel_line == '':
|
||||
continue
|
||||
else:
|
||||
break
|
||||
@ -322,7 +319,7 @@ def iso2grub2(iso_dir):
|
||||
for _lines in initrd_text:
|
||||
initrd_line = extract_kernel_line(_lines[0][1], _lines[0][0],
|
||||
iso_bin_dir)
|
||||
if initrd_line is '':
|
||||
if initrd_line == '':
|
||||
continue
|
||||
else:
|
||||
break
|
||||
|
@ -12,13 +12,10 @@ import subprocess
|
||||
import collections
|
||||
import platform
|
||||
import signal
|
||||
from PyQt5 import QtGui
|
||||
from PyQt5 import QtWidgets
|
||||
from PyQt5 import QtCore
|
||||
from .gui.ui_multibootusb import Ui_MainWindow
|
||||
from .gen import *
|
||||
from . import iso
|
||||
from . import usb
|
||||
from . import config
|
||||
from . import progressbar
|
||||
|
||||
@ -28,15 +25,14 @@ if platform.system() == "Windows":
|
||||
|
||||
def dd_linux():
|
||||
import time
|
||||
input = "if=" + config.image_path
|
||||
_input = "if=" + config.image_path
|
||||
in_file_size = float(os.path.getsize(config.image_path))
|
||||
output = "of=" + config.usb_disk
|
||||
_output = "of=" + config.usb_disk
|
||||
os.system("umount " + config.usb_disk + "1")
|
||||
command = ['dd', input, output, "bs=1M", "oflag=sync"]
|
||||
command = ['dd', _input, _output, "bs=1M", "oflag=sync"]
|
||||
log("Executing ==> " + " ".join(command))
|
||||
dd_process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
|
||||
|
||||
# bar = progressbar.ProgressBar(redirect_stdout=True)
|
||||
pbar = progressbar.ProgressBar(
|
||||
maxval=100,
|
||||
widgets=[
|
||||
@ -73,10 +69,10 @@ def dd_win():
|
||||
windd = resource_path(os.path.join("data", "tools", "dd", "dd.exe"))
|
||||
if os.path.exists(resource_path(os.path.join("data", "tools", "dd", "dd.exe"))):
|
||||
log("dd exist")
|
||||
input = "if=" + config.image_path
|
||||
_input = "if=" + config.image_path
|
||||
in_file_size = float(os.path.getsize(config.image_path) / 1024 / 1024)
|
||||
output = "of=\\\.\\" + config.usb_disk
|
||||
command = [windd, input, output, "bs=1M", "--progress"]
|
||||
_output = "of=\\\.\\" + config.usb_disk
|
||||
command = [windd, _input, _output, "bs=1M", "--progress"]
|
||||
log("Executing ==> " + " ".join(command))
|
||||
dd_process = subprocess.Popen(command, universal_newlines=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
shell=False)
|
||||
@ -127,19 +123,8 @@ class Imager(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.ui.imager_iso_size.setText("ISO Size: " + self.iso_size + " MB")
|
||||
log("ISO Size is " + self.iso_size + " MB")
|
||||
|
||||
# def onImagerComboChange(self):
|
||||
# config.imager_usb_disk = str(self.ui.comboBox_2.currentText())
|
||||
# if bool(config.imager_usb_disk):
|
||||
# self.ui.imager_disk_label.setText(self.imager_usb_detail(config.imager_usb_disk, partition=0).usb_type)
|
||||
# self.ui.imager_total_size.setText(usb.bytes2human(int(self.imager_usb_detail(config.imager_usb_disk, partition=0).total_size)))
|
||||
#
|
||||
# if platform.system() == "Linux":
|
||||
# self.ui.label_imager_uuid.setText("Disk Model:")
|
||||
# self.ui.imager_uuid.setText(str(self.imager_usb_detail(config.imager_usb_disk, partition=0).model))
|
||||
# else:
|
||||
# self.ui.imager_uuid.setText(self.imager_usb_detail(config.imager_usb_disk, partition=0).model)
|
||||
|
||||
def imager_list_usb(self, partition=1):
|
||||
@staticmethod
|
||||
def imager_list_usb(partition=1):
|
||||
"""
|
||||
Function to detect whole USB disk. It uses lsblk package on Linux.
|
||||
:param partition: What to return. By default partition is set.
|
||||
@ -148,7 +133,7 @@ class Imager(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
disk = []
|
||||
if platform.system() == "Linux":
|
||||
output = subprocess.check_output("lsblk -i", shell=True)
|
||||
if not partition == 1:
|
||||
if partition != 1:
|
||||
for line in output.splitlines():
|
||||
line = line.split()
|
||||
if (line[2].strip()) == b'1' and (line[5].strip()) == b'disk':
|
||||
@ -159,15 +144,15 @@ class Imager(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
if (line[2].strip()) == b'1' and line[5].strip() == b'part':
|
||||
disk.append(str("/dev/" + str(line[0].strip()[2:])))
|
||||
else:
|
||||
if partition == 1 or not partition == 1:
|
||||
oFS = win32com.client.Dispatch("Scripting.FileSystemObject")
|
||||
oDrives = oFS.Drives
|
||||
for drive in oDrives:
|
||||
if drive.DriveType == 1 and drive.IsReady:
|
||||
disk.append(drive)
|
||||
oFS = win32com.client.Dispatch("Scripting.FileSystemObject")
|
||||
oDrives = oFS.Drives
|
||||
for drive in oDrives:
|
||||
if drive.DriveType == 1 and drive.IsReady:
|
||||
disk.append(drive)
|
||||
return disk
|
||||
|
||||
def imager_usb_detail(self, usb_disk, partition=1):
|
||||
@staticmethod
|
||||
def imager_usb_detail(usb_disk, partition=1):
|
||||
"""
|
||||
Function to detect details of USB disk using lsblk
|
||||
:param usb_disk: path to usb disk
|
||||
@ -180,7 +165,7 @@ class Imager(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
output = subprocess.check_output("lsblk -ib " + usb_disk, shell=True)
|
||||
for line in output.splitlines():
|
||||
line = line.split()
|
||||
if not partition == 1:
|
||||
if partition != 1:
|
||||
if line[2].strip() == b'1' and line[5].strip() == b'disk':
|
||||
total_size = line[3]
|
||||
if not total_size:
|
||||
@ -194,7 +179,7 @@ class Imager(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
selected_usb_part = str(usb_disk)
|
||||
oFS = win32com.client.Dispatch("Scripting.FileSystemObject")
|
||||
d = oFS.GetDrive(oFS.GetDriveName(oFS.GetAbsolutePathName(selected_usb_part)))
|
||||
selected_usb_device = d.DriveLetter
|
||||
# selected_usb_device = d.DriveLetter
|
||||
label = (d.VolumeName).strip()
|
||||
if not label.strip():
|
||||
label = "No label."
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import platform
|
||||
import threading
|
||||
import subprocess
|
||||
@ -47,7 +46,7 @@ def install_distro():
|
||||
|
||||
if config.distro == "opensuse":
|
||||
iso.iso_extract_file(config.image_path, install_dir, 'boot')
|
||||
status_text = "Copying ISO..."
|
||||
config.status_text = "Copying ISO..."
|
||||
if platform.system() == "Windows":
|
||||
subprocess.call(["xcopy", config.image_path, usb_mount], shell=True) # Have to use xcopy as python file copy is dead slow.
|
||||
elif platform.system() == "Linux":
|
||||
@ -137,7 +136,7 @@ def install_progress():
|
||||
thrd = threading.Thread(target=install_distro, name="install_progress")
|
||||
# thrd.daemon()
|
||||
# install_size = usb_size_used / 1024
|
||||
install_size = iso_size(config.image_path) / 1024
|
||||
# install_size = iso_size(config.image_path) / 1024
|
||||
final_size = (usb_size_used + iso_size(config.image_path)) + config.persistence
|
||||
thrd.start()
|
||||
pbar = progressbar.ProgressBar(maxval=100).start() # bar = progressbar.ProgressBar(redirect_stdout=True)
|
||||
@ -162,7 +161,7 @@ def install_patch():
|
||||
os.sync()
|
||||
iso_cfg_ext_dir = os.path.join(multibootusb_host_dir(), "iso_cfg_ext_dir")
|
||||
isolinux_path = os.path.join(iso_cfg_ext_dir, isolinux_bin_path(config.image_path))
|
||||
iso_linux_bin_dir = isolinux_bin_dir(config.image_path)
|
||||
# iso_linux_bin_dir = isolinux_bin_dir(config.image_path)
|
||||
config.syslinux_version = isolinux_version(isolinux_path)
|
||||
iso_file_list = iso.iso_file_list(config.image_path)
|
||||
os.path.join(config.usb_mount, "multibootusb", iso_basename(config.image_path), isolinux_bin_dir(config.image_path))
|
||||
|
@ -7,10 +7,7 @@
|
||||
# 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 sys
|
||||
import os
|
||||
import string
|
||||
import platform
|
||||
import re
|
||||
from .gen import *
|
||||
from .isodump3 import ISO9660
|
||||
@ -56,11 +53,7 @@ def isolinux_bin_exist(iso_link):
|
||||
"""
|
||||
if os.path.exists(iso_link):
|
||||
iso_file_list = _7zip.list_iso(iso_link)
|
||||
if any("isolinux.bin" in s.lower() for s in iso_file_list):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
return bool(any("isolinux.bin" in s.lower() for s in iso_file_list))
|
||||
|
||||
|
||||
def iso_size(iso_link):
|
||||
@ -74,10 +67,7 @@ def is_bootable(iso_link):
|
||||
"""
|
||||
iso9660fs = ISO9660(iso_link)
|
||||
isBootable = iso9660fs.checkISOBootable()
|
||||
if isBootable:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
return bool(isBootable)
|
||||
|
||||
|
||||
def isolinux_bin_dir(iso_link):
|
||||
@ -162,14 +152,14 @@ def isolinux_version(isolinux_bin_path):
|
||||
return str(number)
|
||||
|
||||
|
||||
def iso_extract_file(iso_link, dest_dir, filter):
|
||||
def iso_extract_file(iso_link, dest_dir, _filter):
|
||||
"""
|
||||
Extract the specific file(s) from an ISO
|
||||
:param dest_dir: Path to destination directory.
|
||||
:param filter: Filter to extract particular file(s)
|
||||
:return: Extract file(s) to destination.
|
||||
"""
|
||||
_7zip.extract_iso(iso_link, dest_dir, filter)
|
||||
_7zip.extract_iso(iso_link, dest_dir, _filter)
|
||||
|
||||
|
||||
def extract_cfg_file(iso_link):
|
||||
@ -232,4 +222,3 @@ if __name__ == '__main__':
|
||||
iso_extract_full(iso_path, 'test')
|
||||
iso_extract_file(iso_path, 'test', 'isolinux.bin')
|
||||
log(isolinux_version(test_iso_bin_path))
|
||||
|
||||
|
@ -7,8 +7,6 @@
|
||||
# under the terms of GNU General Public License, v.2 or above
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
from . import usb
|
||||
from . import gen
|
||||
from .iso import *
|
||||
@ -29,15 +27,13 @@ def read_input_uninstall():
|
||||
|
||||
|
||||
def cli_install_distro():
|
||||
'''
|
||||
if platform.system() == 'Linux':
|
||||
if os.getuid() != 0:
|
||||
exit("You need to have root privileges to run this script.\nPlease try again using 'sudo'. Exiting.")
|
||||
elif platform.system() == 'Windows':
|
||||
|
||||
if admin.isUserAdmin():
|
||||
admin.elevate()
|
||||
'''
|
||||
# if platform.system() == 'Linux':
|
||||
# if os.getuid() != 0:
|
||||
# exit("You need to have root privileges to run this script.\nPlease try again using 'sudo'. Exiting.")
|
||||
# elif platform.system() == 'Windows':
|
||||
#
|
||||
# if admin.isUserAdmin():
|
||||
# admin.elevate()
|
||||
|
||||
log('Starting multibootusb from Command line...')
|
||||
if usb.is_block(config.usb_disk) is False:
|
||||
@ -65,7 +61,7 @@ def iso_install(iso_image):
|
||||
"""
|
||||
Script for installing iso image to a disk. This can be called by other script for auto install of many distros
|
||||
:param iso_image: Path to ISO image
|
||||
:return:
|
||||
:return:
|
||||
"""
|
||||
if size_not_enough(iso_image, config.usb_disk) is True:
|
||||
log(config.usb_disk + ' does not have enough space...')
|
||||
|
@ -11,10 +11,10 @@ from . import config
|
||||
|
||||
def pc_tool_config(syslinux=True, grub=False):
|
||||
"""
|
||||
Menu entry for PC Tool ISO
|
||||
:param syslinux:
|
||||
:param grub:
|
||||
:return:
|
||||
Menu entry for PC Tool ISO
|
||||
:param syslinux:
|
||||
:param grub:
|
||||
:return:
|
||||
"""
|
||||
if syslinux is True:
|
||||
return """KERNEL /system/stage1
|
||||
|
@ -6,12 +6,10 @@
|
||||
# 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 sys
|
||||
import os
|
||||
import platform
|
||||
import tarfile
|
||||
import subprocess
|
||||
from . import usb
|
||||
from . import iso
|
||||
from . import gen
|
||||
from . import config
|
||||
@ -45,7 +43,7 @@ def persistence_distro(distro, iso_link):
|
||||
assert distro is not None
|
||||
assert iso_link is not None
|
||||
|
||||
iso_size = iso.iso_size(iso_link)
|
||||
# iso_size = iso.iso_size(iso_link)
|
||||
|
||||
if distro in ["ubuntu", "debian", "debian-install", "fedora"]:
|
||||
gen.log("Persistence option is available.")
|
||||
@ -92,7 +90,7 @@ def create_persistence():
|
||||
if subprocess.call(persistence_dd_cmd, shell=True) == 0:
|
||||
gen.log("\nSuccessfully created persistence file...\n")
|
||||
|
||||
if not config.distro == 'fedora':
|
||||
if config.distro != 'fedora':
|
||||
gen.log('Applying filesystem to persistence file...')
|
||||
config.status_text = 'Applying filesystem to persistence file. Please wait...'
|
||||
gen.log('Executing ==> ' + persistence_mkfs_cmd)
|
||||
@ -111,4 +109,3 @@ def extract_file(file_path, install_dir):
|
||||
tar = tarfile.open(file_path, "r:bz2")
|
||||
tar.extractall(install_dir)
|
||||
tar.close()
|
||||
|
||||
|
@ -255,7 +255,8 @@ class FormatLabel(Timer):
|
||||
context[name] = value
|
||||
else:
|
||||
context[name] = transform(value)
|
||||
except: pass
|
||||
except:
|
||||
raise
|
||||
|
||||
return self.format_string % context
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
import os
|
||||
import subprocess
|
||||
import platform
|
||||
from .admin import adminCmd
|
||||
from PyQt5 import QtWidgets
|
||||
from .gui.ui_multibootusb import Ui_MainWindow
|
||||
from .gen import *
|
||||
@ -27,7 +26,7 @@ class Qemu(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
QtWidgets.QMainWindow.__init__(self)
|
||||
self.ui = Ui_MainWindow()
|
||||
self.ui.setupUi(self)
|
||||
|
||||
|
||||
def on_Qemu_Boot_iso_Click(self):
|
||||
"""
|
||||
Main function to boot a selected ISO.
|
||||
@ -102,9 +101,7 @@ class Qemu(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
cmd = qemu + ' -hda ' + qemu_usb_disk + ram + ' -vga std'
|
||||
try:
|
||||
log('Executing ==> ' + cmd)
|
||||
# adminCmd([qemu, '-hda', usb_disk[:-1], '-m', ram, '-vga std'], gui=True)
|
||||
subprocess.Popen(cmd, shell=True)
|
||||
# adminCmd(qemu_cmd, gui=True)
|
||||
except:
|
||||
QtWidgets.QMessageBox.information(self, 'Error...', 'Error booting USB\n\nUnable to start QEMU.')
|
||||
|
||||
@ -133,8 +130,9 @@ class Qemu(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
return None
|
||||
else:
|
||||
return selected_ram
|
||||
|
||||
def check_qemu_exist(self):
|
||||
|
||||
@staticmethod
|
||||
def check_qemu_exist():
|
||||
"""
|
||||
Check if QEMU is available on host system.
|
||||
:return: path to QEMU program or None otherwise.
|
||||
@ -150,7 +148,7 @@ class Qemu(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
elif platform.system() == "Windows":
|
||||
qemu = resource_path(os.path.join("data", "tools", "qemu", "qemu-system-x86_64.exe"))
|
||||
log(qemu)
|
||||
|
||||
|
||||
if qemu:
|
||||
log("QEMU: using " + qemu)
|
||||
else:
|
||||
@ -158,24 +156,21 @@ class Qemu(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
|
||||
return qemu
|
||||
|
||||
|
||||
def get_physical_disk_number(self, usb_disk):
|
||||
@staticmethod
|
||||
def get_physical_disk_number(usb_disk):
|
||||
"""
|
||||
Get the physical disk number as detected ny Windows.
|
||||
:param usb_disk: USB disk (Like F:)
|
||||
:return: Disk number.
|
||||
"""
|
||||
import wmi
|
||||
c = wmi.WMI ()
|
||||
for physical_disk in c.Win32_DiskDrive ():
|
||||
for partition in physical_disk.associators ("Win32_DiskDriveToDiskPartition"):
|
||||
for logical_disk in partition.associators ("Win32_LogicalDiskToPartition"):
|
||||
c = wmi.WMI()
|
||||
for physical_disk in c.Win32_DiskDrive():
|
||||
for partition in physical_disk.associators("Win32_DiskDriveToDiskPartition"):
|
||||
for logical_disk in partition.associators("Win32_LogicalDiskToPartition"):
|
||||
if logical_disk.Caption == usb_disk:
|
||||
"""
|
||||
log physical_disk.Caption
|
||||
log partition.Caption
|
||||
log logical_disk.Caption
|
||||
"""
|
||||
# log physical_disk.Caption
|
||||
# log partition.Caption
|
||||
# log logical_disk.Caption
|
||||
log("Physical Device Number is " + partition.Caption[6:-14])
|
||||
return str(partition.Caption[6:-14])
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
# under the terms of GNU General Public License, v.2 or above
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import platform
|
||||
from .gen import *
|
||||
@ -39,7 +38,7 @@ def set_boot_flag(usb_disk):
|
||||
return False
|
||||
|
||||
|
||||
def syslinux_default(usb_disk, version=4):
|
||||
def syslinux_default(usb_disk):
|
||||
"""
|
||||
Install Syslinux of a selected drive
|
||||
:param usb_disk: '/dev/sdx' on linux and 'E:' on Windows
|
||||
@ -152,7 +151,7 @@ def syslinux_distro_dir(usb_disk, iso_link, distro):
|
||||
if platform.system() == "Linux":
|
||||
syslinux_path = os.path.join(multibootusb_host_dir(), "syslinux", "bin", "syslinux") + config.syslinux_version
|
||||
if os.access(syslinux_path, os.X_OK) is False:
|
||||
subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0
|
||||
subprocess.call('chmod +x ' + syslinux_path, shell=True)
|
||||
sys_cmd = syslinux_path + option + quote(distro_syslinux_install_dir) + ' ' + usb_disk
|
||||
dd_cmd = 'dd if=' + usb_disk + ' ' + 'of=' + quote(distro_sys_install_bs) + ' count=1'
|
||||
log("Executing ==> " + sys_cmd)
|
||||
@ -194,7 +193,7 @@ def syslinux_distro_dir(usb_disk, iso_link, distro):
|
||||
ext_cmd = syslinux_path + " --install " + distro_syslinux_install_dir
|
||||
dd_cmd = 'dd if=' + usb_disk + ' ' + 'of=' + quote(distro_sys_install_bs) + ' count=1'
|
||||
if os.access(syslinux_path, os.X_OK) is False:
|
||||
subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0
|
||||
subprocess.call('chmod +x ' + syslinux_path, shell=True)
|
||||
log("Executing ==> " + ext_cmd)
|
||||
if subprocess.call(ext_cmd, shell=True) == 0:
|
||||
log("\nSyslinux install on distro directory is successful...\n")
|
||||
|
@ -11,7 +11,8 @@ __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
# from __future__ import print_function
|
||||
import os, re
|
||||
import os
|
||||
import re
|
||||
|
||||
|
||||
def node_mountpoint(node):
|
||||
@ -133,16 +134,6 @@ class UDisks2(object):
|
||||
|
||||
def mount(self, device_node_path):
|
||||
d = self.device(device_node_path)
|
||||
|
||||
# euid = os.environ['SUDO_UID']
|
||||
# egid = os.environ['SUDO_GID']
|
||||
#
|
||||
# if euid and egid:
|
||||
# user, group = int(euid), int(egid)
|
||||
# else:
|
||||
# user, group = os.getuid(), os.getgid()
|
||||
#
|
||||
# mount_options = ['rw', 'noexec', 'nosuid', 'nodev', 'uid=%d' % user, 'gid=%d' % group]
|
||||
mount_options = ['rw', 'noexec', 'nosuid', 'nodev']
|
||||
|
||||
try:
|
||||
@ -158,8 +149,8 @@ class UDisks2(object):
|
||||
mp = node_mountpoint(str(device_node_path))
|
||||
if mp is None:
|
||||
raise
|
||||
finally:
|
||||
return mp
|
||||
|
||||
return mp
|
||||
|
||||
def unmount(self, device_node_path):
|
||||
d = self.device(device_node_path)
|
||||
|
@ -147,7 +147,7 @@ def uninstall_distro():
|
||||
gen.log('EFI image does not exist. Copying now...')
|
||||
shutil.copy2(gen.resource_path(os.path.join("data", "EFI", "BOOT", "bootx64.efi")),
|
||||
os.path.join(config.usb_mount, 'EFI', 'BOOT'))
|
||||
elif not gen.grub_efi_exist(efi_grub_img) is True:
|
||||
elif not gen.grub_efi_exist(efi_grub_img):
|
||||
gen.log('EFI image overwritten by distro install. Replacing it now...')
|
||||
shutil.copy2(gen.resource_path(os.path.join("data", "EFI", "BOOT", "bootx64.efi")),
|
||||
os.path.join(config.usb_mount, 'EFI', 'BOOT'))
|
||||
|
@ -26,10 +26,7 @@ def update_distro_cfg_files(iso_link, usb_disk, distro, persistence=0):
|
||||
usb_mount = usb_details['mount_point']
|
||||
usb_uuid = usb_details['uuid']
|
||||
usb_label = usb_details['label']
|
||||
patch = None
|
||||
iso_cfg_ext_dir = os.path.join(multibootusb_host_dir(), "iso_cfg_ext_dir")
|
||||
if isolinux_bin_exist(config.image_path):
|
||||
isolinux_path = os.path.join(iso_cfg_ext_dir, isolinux_bin_path(iso_link)[1:])
|
||||
# iso_cfg_ext_dir = os.path.join(multibootusb_host_dir(), "iso_cfg_ext_dir")
|
||||
config.status_text = "Updating config files..."
|
||||
install_dir = os.path.join(usb_mount, "multibootusb", iso_basename(iso_link))
|
||||
log('Updating distro specific config files...')
|
||||
@ -399,7 +396,7 @@ label hwinfo
|
||||
|
||||
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.image_path))
|
||||
# install_dir = os.path.join(config.usb_mount, "multibootusb", iso_basename(config.image_path))
|
||||
menu_lst = iso_menu_lst_path(config.image_path).replace("\\", "/")
|
||||
with open(sys_cfg_file, "a") as f:
|
||||
f.write("#start " + iso_basename(config.image_path) + "\n")
|
||||
|
@ -20,7 +20,7 @@ if platform.system() == 'Linux':
|
||||
if platform.system() == 'Windows':
|
||||
import psutil
|
||||
import win32com.client
|
||||
import wmi
|
||||
# import wmi
|
||||
import pythoncom
|
||||
|
||||
|
||||
@ -84,7 +84,7 @@ def disk_usage(mount_path):
|
||||
raise NotImplementedError("Platform not supported.")
|
||||
|
||||
|
||||
def list_devices(partition=1, fixed=False):
|
||||
def list_devices(fixed=False):
|
||||
"""
|
||||
List inserted USB devices.
|
||||
:return: USB devices as list.
|
||||
@ -97,7 +97,7 @@ def list_devices(partition=1, fixed=False):
|
||||
try:
|
||||
import pyudev
|
||||
except Exception as e:
|
||||
gen.log('Pydev is not installed on host system. Using the inbuilt one.')
|
||||
gen.log('PyUdev is not installed on host system, using built-in.')
|
||||
from . import pyudev
|
||||
context = pyudev.Context()
|
||||
|
||||
@ -209,12 +209,9 @@ def details_udev(usb_disk_part):
|
||||
import pyudev
|
||||
except:
|
||||
from . import pyudev
|
||||
"""
|
||||
Try with PyUdev to get the details of USB disks.
|
||||
This is the easiest and reliable method to find USB details.
|
||||
Also, it is a standalone package and no dependencies are required.
|
||||
"""
|
||||
# gen.log "Using PyUdev for detecting USB details..."
|
||||
# Try with PyUdev to get the details of USB disks.
|
||||
# This is the easiest and reliable method to find USB details.
|
||||
# Also, it is a standalone package and no dependencies are required.
|
||||
context = pyudev.Context()
|
||||
try:
|
||||
device = pyudev.Device.from_device_file(context, usb_disk_part)
|
||||
@ -280,7 +277,7 @@ def details_udisks2(usb_disk_part):
|
||||
device = bd.Get('org.freedesktop.UDisks2.Block', 'Device', dbus_interface='org.freedesktop.DBus.Properties')
|
||||
device = bytearray(device).replace(b'\x00', b'').decode('utf-8')
|
||||
uuid = bd.Get('org.freedesktop.UDisks2.Block', 'IdUUID', dbus_interface='org.freedesktop.DBus.Properties')
|
||||
file_system = bd.Get('org.freedesktop.UDisks2.Block', 'IdType', dbus_interface='org.freedesktop.DBus.Properties')
|
||||
file_system = bd.Get('org.freedesktop.UDisks2.Block', 'IdType', dbus_interface='org.freedesktop.DBus.Properties')
|
||||
mount_point = bd.Get('org.freedesktop.UDisks2.Filesystem', 'MountPoints', dbus_interface='org.freedesktop.DBus.Properties')
|
||||
if mount_point:
|
||||
# mount_point = str(bytearray(mount_point[0]).decode('utf-8').replace(b'\x00', b''))
|
||||
@ -367,18 +364,17 @@ def win_disk_details(disk_drive):
|
||||
size_total = shutil.disk_usage(mount_point)[0]
|
||||
size_used = shutil.disk_usage(mount_point)[1]
|
||||
size_free = shutil.disk_usage(mount_point)[2]
|
||||
'''
|
||||
|
||||
# The below code works only from vista and above. I have removed it as many people reported that the software
|
||||
# was not working under windows xp. Even then, it is significantly slow if 'All Drives' option is checked.
|
||||
# Removing the code doesn't affect the functionality as it is only used to find vendor id and model of the drive.
|
||||
c = wmi.WMI()
|
||||
for physical_disk in c.Win32_DiskDrive(InterfaceType="USB"):
|
||||
for partition in physical_disk.associators("Win32_DiskDriveToDiskPartition"):
|
||||
for logical_disk in partition.associators("Win32_LogicalDiskToPartition"):
|
||||
if logical_disk.Caption == disk_drive:
|
||||
vendor = (physical_disk.PNPDeviceID.split('&VEN_'))[1].split('&PROD_')[0]
|
||||
model = (physical_disk.PNPDeviceID.split('&PROD_'))[1].split('&REV_')[0]
|
||||
'''
|
||||
# c = wmi.WMI()
|
||||
# for physical_disk in c.Win32_DiskDrive(InterfaceType="USB"):
|
||||
# for partition in physical_disk.associators("Win32_DiskDriveToDiskPartition"):
|
||||
# for logical_disk in partition.associators("Win32_LogicalDiskToPartition"):
|
||||
# if logical_disk.Caption == disk_drive:
|
||||
# vendor = (physical_disk.PNPDeviceID.split('&VEN_'))[1].split('&PROD_')[0]
|
||||
# model = (physical_disk.PNPDeviceID.split('&PROD_'))[1].split('&REV_')[0]
|
||||
|
||||
return {'uuid': uuid, 'file_system': file_system, 'label': label, 'mount_point': mount_point,
|
||||
'size_total': size_total, 'size_used': size_used, 'size_free': size_free,
|
||||
|
Loading…
Reference in New Issue
Block a user