Commit 7a9aad94 authored by rgaudin's avatar rgaudin
Browse files

Fixed #258: replaced diskpart with etcher flash of a clean MBR (single 1M FAT32 partition)

parent b83f06b9
......@@ -12,6 +12,7 @@ a = Analysis(['kiwix-hotspot/__main__.py'],
('kiwix-hotspot-logo.png', '.'),
('ansiblecube', 'ansiblecube'),
('etcher-cli', 'etcher-cli'),
('mbr.img', '.'),
('vexpress-boot', 'vexpress-boot')],
hiddenimports=['gui', 'cli', 'image', 'cache'],
hookspath=['additional-hooks'],
......
......@@ -19,6 +19,7 @@ a = Analysis(['kiwix-hotspot/__main__.py'],
('kiwix-hotspot-logo.png', '.'),
('ansiblecube', 'ansiblecube'),
('etcher-cli', 'etcher-cli'),
('mbr.img', '.'),
('vexpress-boot', 'vexpress-boot')],
hiddenimports=['gui', 'cli', 'image', 'cache'],
hookspath=['additional-hooks'],
......
......@@ -25,6 +25,7 @@ a = Analysis(['kiwix-hotspot/__main__.py'],
('imdisk.png', '.'),
('etcher.gif', '.'),
('kiwix-hotspot-logo.png', '.'),
('mbr.img', '.'),
('ansiblecube', 'ansiblecube'),
('vexpress-boot', 'vexpress-boot'),
('C:\Program Files\qemu', 'qemu'),
......
......@@ -24,6 +24,7 @@ a = Analysis(['kiwix-hotspot/__main__.py'],
('contents.json', '.'),
('imdisk.png', '.'),
('etcher.gif', '.'),
('mbr.img', '.'),
('kiwix-hotspot-logo.png', '.'),
('ansiblecube', 'ansiblecube'),
('vexpress-boot', 'vexpress-boot'),
......
......@@ -170,28 +170,9 @@ class EtcherWriterThread(threading.Thread):
logger.step("Copy image to sd card using etcher-cli")
from_cli = logger is None or type(logger) == CLILogger
# on macOS, GUI sudo captures stdout so we use a log file
log_to_file = not from_cli and sys.platform == "darwin"
if log_to_file:
log_file = tempfile.NamedTemporaryFile(suffix=".log", delete=False)
cmd = [
os.path.join(data.data_dir, "etcher-cli", "etcher"),
"-c",
"-y",
"-u",
"-d",
device_fpath,
image_fpath,
]
# handle sudo or GUI alternative for linux and macOS
if sys.platform in ("linux", "darwin"):
cmd = get_admin_command(
cmd,
from_gui=not from_cli,
log_to=log_file.name if log_to_file else None,
)
cmd, log_to_file, log_file = get_etcher_command(
image_fpath, device_fpath, logger
)
process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **startup_info_args()
......@@ -225,7 +206,10 @@ class EtcherWriterThread(threading.Thread):
if log_to_file:
log_file.close()
os.unlink(log_file.name)
try:
os.unlink(log_file.name)
except Exception as exp:
logger.err(str(exp))
try:
logger.std(". has process exited?")
......@@ -322,3 +306,42 @@ def restore_sleep_policy(reference, logger):
reference.kill()
reference.wait(5)
return
def get_etcher_command(image_fpath, device_fpath, logger):
from_cli = logger is None or type(logger) == CLILogger
# on macOS, GUI sudo captures stdout so we use a log file
log_to_file = not from_cli and sys.platform == "darwin"
if log_to_file:
log_file = tempfile.NamedTemporaryFile(suffix=".log", delete=False)
else:
log_file = None
cmd = [
os.path.join(data.data_dir, "etcher-cli", "etcher"),
"-c",
"-y",
"-u",
"-d",
device_fpath,
image_fpath,
]
# handle sudo or GUI alternative for linux and macOS
if sys.platform in ("linux", "darwin"):
cmd = get_admin_command(
cmd, from_gui=not from_cli, log_to=log_file.name if log_to_file else None
)
return cmd, log_to_file, log_file
def flash_image_with_etcher(image_fpath, device_fpath, logger):
cmd, log_to_file, log_file = get_etcher_command(image_fpath, device_fpath, logger)
subprocess_pretty_check_call(cmd, logger)
if log_to_file:
log_file.close()
try:
os.unlink(log_file.name)
except Exception as exp:
logger.err(str(exp))
......@@ -37,11 +37,7 @@ from backend.mount import (
)
from backend.util import EtcherWriterThread
from backend.mount import can_write_on, allow_write_on, restore_mode
from backend.util import (
subprocess_pretty_check_call,
prevent_sleep,
restore_sleep_policy,
)
from backend.util import flash_image_with_etcher, prevent_sleep, restore_sleep_policy
from backend.sysreq import host_matches_requirements, requirements_url
......@@ -121,26 +117,12 @@ def run_installation(
# Prepare SD Card
if sd_card:
logger.step("Prepare SD-card ({})".format(sd_card))
if sys.platform == "darwin":
subprocess_pretty_check_call(
["diskutil", "unmountDisk", sd_card], logger
)
elif sys.platform == "win32":
logger.step("Format SD card {}".format(sd_card))
matches = re.findall(r"\\\\.\\PHYSICALDRIVE(\d*)", sd_card)
if len(matches) != 1:
raise ValueError("Error while getting physical drive number")
device_number = matches[0]
r, w = os.pipe()
os.write(w, str.encode("select disk {}\n".format(device_number)))
os.write(w, b"clean\n")
os.close(w)
logger.std("diskpart select disk {} and clean".format(device_number))
subprocess_pretty_check_call(["diskpart"], logger, stdin=r)
logger.std("sleeping for 15s to acknowledge diskpart changes")
time.sleep(15)
logger.step("Flash clean MBR onto SD-card ({})".format(sd_card))
flash_image_with_etcher(
image_fpath=os.path.join(data.data_dir, "mbr.img"),
device_fpath=sd_card,
logger=logger,
)
# Download Base image
logger.stage("master")
......
File added
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment