mirror of
https://github.com/mbusb/multibootusb
synced 2024-11-01 15:40:16 +00:00
code cleanup
This commit is contained in:
parent
cc1c238835
commit
36661a767d
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)
|
||||
|
@ -13,7 +13,6 @@ from .iso import *
|
||||
from .isodump3 import ISO9660
|
||||
from .gen import *
|
||||
from . import _7zip
|
||||
from . import config
|
||||
|
||||
|
||||
def distro(iso_cfg_ext_dir, iso_link):
|
||||
@ -22,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):
|
||||
|
@ -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)
|
||||
|
@ -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')
|
||||
@ -274,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():
|
||||
|
@ -16,7 +16,6 @@ from PyQt5 import QtWidgets
|
||||
from .gui.ui_multibootusb import Ui_MainWindow
|
||||
from .gen import *
|
||||
from . import iso
|
||||
from . import usb
|
||||
from . import config
|
||||
from . import progressbar
|
||||
|
||||
@ -180,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,9 +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 re
|
||||
from .gen import *
|
||||
from .isodump3 import ISO9660
|
||||
|
@ -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
|
||||
|
@ -10,7 +10,6 @@ import os
|
||||
import platform
|
||||
import tarfile
|
||||
import subprocess
|
||||
from . import usb
|
||||
from . import iso
|
||||
from . import gen
|
||||
from . import config
|
||||
@ -44,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.")
|
||||
|
@ -255,7 +255,8 @@ class FormatLabel(Timer):
|
||||
context[name] = value
|
||||
else:
|
||||
context[name] = transform(value)
|
||||
except: pass
|
||||
except:
|
||||
raise
|
||||
|
||||
return self.format_string % context
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user