Fix error codes
This commit is contained in:
parent
206a3c7c70
commit
83f6ba25fe
17
README.md
17
README.md
|
@ -1,2 +1,19 @@
|
||||||
# Linux on Nabu Deployer
|
# Linux on Nabu Deployer
|
||||||
#### Python tool for installing linux on xiaomi pad 5
|
#### Python tool for installing linux on xiaomi pad 5
|
||||||
|
|
||||||
|
#### Exit codes:
|
||||||
|
| Code | Description |
|
||||||
|
|:----:|:-----------------------------|
|
||||||
|
| 166 | Invalid RootFS image |
|
||||||
|
| 167 | RootFS image not found! |
|
||||||
|
| 168 | Invalid args |
|
||||||
|
| 169 | Failed to start adb server |
|
||||||
|
| 170 | Device not found |
|
||||||
|
| 171 | More then one device |
|
||||||
|
| 172 | Fastboot device timed out |
|
||||||
|
| 173 | Recovery device timed out |
|
||||||
|
| 174 | Incompatible partition table |
|
||||||
|
| 175 | Postinstall failed |
|
||||||
|
| 176 | Failed to patch boot image |
|
||||||
|
| 253 | User cancel |
|
||||||
|
| 254 | Is it nabu? |
|
|
@ -113,12 +113,13 @@ def main() -> int:
|
||||||
logger.debug(f"RootFS magic: {rootfs_magic}")
|
logger.debug(f"RootFS magic: {rootfs_magic}")
|
||||||
if rootfs_magic not in ["application/octet-stream", "inode/blockdevice"]:
|
if rootfs_magic not in ["application/octet-stream", "inode/blockdevice"]:
|
||||||
console.log("Invalid RootFS image")
|
console.log("Invalid RootFS image")
|
||||||
return 1
|
return 166
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
console.log("RootFS image not found!")
|
console.log("RootFS image not found!")
|
||||||
return 1
|
return 167
|
||||||
else:
|
else:
|
||||||
console.log(parser.parse_args("-h".split()))
|
console.log(parser.parse_args("-h".split()))
|
||||||
|
return 168
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -135,13 +136,13 @@ def main() -> int:
|
||||||
console.log("Failed to start adb server")
|
console.log("Failed to start adb server")
|
||||||
console.log("Adb binary not found in path")
|
console.log("Adb binary not found in path")
|
||||||
adb = None
|
adb = None
|
||||||
return 1
|
return 169
|
||||||
else:
|
else:
|
||||||
if proc.wait() != 0:
|
if proc.wait() != 0:
|
||||||
console.log("Failed to start adb server")
|
console.log("Failed to start adb server")
|
||||||
console.log(stdout)
|
console.log(stdout)
|
||||||
adb = None
|
adb = None
|
||||||
return 1
|
return 169
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -213,33 +214,6 @@ def main() -> int:
|
||||||
"Size of linux partition (leave empty to skip if possible)",
|
"Size of linux partition (leave empty to skip if possible)",
|
||||||
default="", show_default=False
|
default="", show_default=False
|
||||||
)
|
)
|
||||||
if linux_part_size == "":
|
|
||||||
linux_part_size = None
|
|
||||||
break
|
|
||||||
elif re.match(r"^\d+%$", linux_part_size) and 20 <= int(linux_part_size[:-1]) <= 90:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
console.log("Incorrect linux partition size. It can be [20; 90]%")
|
|
||||||
linux_part_size = None
|
|
||||||
|
|
||||||
fb_list = list_fb_devices()
|
|
||||||
adb_list = list(map(lambda x: x.serial, adb.list()))
|
|
||||||
if args.device_serial:
|
|
||||||
if args.device_serial in fb_list or args.device_serial in adb_list:
|
|
||||||
serial = args.device_serial
|
|
||||||
else:
|
|
||||||
console.log(f"Device with serial {args.device_serial} not found")
|
|
||||||
return 1
|
|
||||||
elif len(fb_list) == 1 and len(adb_list) == 0:
|
|
||||||
serial = fb_list[0]
|
|
||||||
elif len(adb_list) == 1 and len(fb_list) == 0:
|
|
||||||
serial = adb_list[0]
|
|
||||||
elif len(adb_list + fb_list) == 0:
|
|
||||||
console.log("No devices available. Please check your device connection")
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
console.log("More then one device detected. Use -d flag to set device")
|
|
||||||
return 1
|
|
||||||
|
|
||||||
for msg in [
|
for msg in [
|
||||||
f"Username: {username}",
|
f"Username: {username}",
|
||||||
|
@ -250,23 +224,8 @@ def main() -> int:
|
||||||
console.log(msg)
|
console.log(msg)
|
||||||
|
|
||||||
if Prompt.ask("Is it ok?", default="n", choices=["y", "n"]) == "n":
|
if Prompt.ask("Is it ok?", default="n", choices=["y", "n"]) == "n":
|
||||||
return 1
|
return 253
|
||||||
|
|
||||||
if serial not in fb_list:
|
|
||||||
console.log("ADB Device detected. Rebooting it to bootloader")
|
|
||||||
adb.device(serial).shell("reboot bootloader")
|
|
||||||
with console.status("[cyan]Waiting for fastboot device", spinner="line", spinner_style="white"):
|
|
||||||
wait_for_bootloader(serial)
|
|
||||||
console.log("Device connected")
|
|
||||||
else:
|
|
||||||
console.log("Device connected")
|
|
||||||
|
|
||||||
if not check_device(serial):
|
|
||||||
console.log("Is it nabu?")
|
|
||||||
reboot_fb_device(serial)
|
|
||||||
return 2
|
|
||||||
|
|
||||||
parts_status = check_parts(serial)
|
|
||||||
if linux_part_size:
|
if linux_part_size:
|
||||||
if Prompt.ask(
|
if Prompt.ask(
|
||||||
f"Repartition {'requested' if parts_status else 'needed'}. All data will be ERASED",
|
f"Repartition {'requested' if parts_status else 'needed'}. All data will be ERASED",
|
||||||
|
@ -279,39 +238,41 @@ def main() -> int:
|
||||||
try:
|
try:
|
||||||
adb.wait_for(serial, state="recovery")
|
adb.wait_for(serial, state="recovery")
|
||||||
except adbutils.errors.AdbTimeout():
|
except adbutils.errors.AdbTimeout():
|
||||||
console.log("Could not detect recovery device")
|
console.log("Device timed out! Exiting")
|
||||||
return 1
|
return 173
|
||||||
repartition(serial, int(linux_part_size.replace("%", "")), percents=True)
|
repartition(serial, int(linux_part_size.replace("%", "")), percents=True)
|
||||||
console.log("Repartition complete")
|
console.log("Repartition complete")
|
||||||
|
console.log("To boot android you need to manually format data in your ROM recovery")
|
||||||
|
|
||||||
adbutils.device(serial).shell("reboot bootloader")
|
adbutils.device(serial).shell("reboot bootloader")
|
||||||
console.log("Rebooting into bootloader")
|
console.log("Rebooting into bootloader")
|
||||||
wait_for_bootloader(serial)
|
|
||||||
console.log("Booting OrangeFox recovery")
|
|
||||||
boot_ofox(serial)
|
|
||||||
with console.status("[cyan]Waiting for device", spinner="line", spinner_style="white"):
|
with console.status("[cyan]Waiting for device", spinner="line", spinner_style="white"):
|
||||||
try:
|
try:
|
||||||
fastboot.wait_for_bootloader(serial)
|
fastboot.wait_for_bootloader(serial)
|
||||||
|
except exceptions.DeviceNotFound:
|
||||||
|
console.log("Device timed out! Exiting")
|
||||||
|
return 172
|
||||||
else:
|
else:
|
||||||
console.log("Repartition canceled. Exiting")
|
console.log("Repartition canceled. Exiting")
|
||||||
return 1
|
return 253
|
||||||
|
|
||||||
if not parts_status and not linux_part_size:
|
if not parts_status and not linux_part_size:
|
||||||
console.log("Incompatible partition table detected. Repartition needed. Exiting")
|
console.log("Incompatible partition table detected. Repartition needed. Exiting")
|
||||||
return 1
|
return 174
|
||||||
|
|
||||||
console.log("Cleaning linux and esp")
|
console.log("Cleaning linux and esp")
|
||||||
clean_device(serial)
|
fastboot.clean_device(serial)
|
||||||
|
|
||||||
console.log("Booting OrangeFox recovery")
|
console.log("Booting OrangeFox recovery")
|
||||||
|
|
||||||
boot_ofox(serial)
|
fastboot.boot_ofox(serial)
|
||||||
|
|
||||||
with console.status("[cyan]Waiting for device", spinner="line", spinner_style="white"):
|
with console.status("[cyan]Waiting for device", spinner="line", spinner_style="white"):
|
||||||
try:
|
try:
|
||||||
adb.wait_for(serial, state="recovery")
|
adb.wait_for(serial, state="recovery")
|
||||||
except adbutils.errors.AdbTimeout():
|
except adbutils.errors.AdbTimeout():
|
||||||
console.log("Could not detect recovery device")
|
console.log("Device timed out! Exiting")
|
||||||
return 1
|
return 173
|
||||||
|
|
||||||
adbd = adb.device(serial)
|
adbd = adb.device(serial)
|
||||||
|
|
||||||
|
@ -326,8 +287,9 @@ def main() -> int:
|
||||||
)
|
)
|
||||||
nc_thread.start()
|
nc_thread.start()
|
||||||
sleep(3)
|
sleep(3)
|
||||||
|
|
||||||
console.log("Flashing RootFS")
|
console.log("Flashing RootFS")
|
||||||
with adbd.create_connection("tcp", server_port) as conn:
|
with adbd.create_connection(adbutils.Network.TCP, server_port) as conn:
|
||||||
with get_progress() as pbar:
|
with get_progress() as pbar:
|
||||||
task = pbar.add_task("[cyan]Uploading RootFS", total=op.getsize(rootfs))
|
task = pbar.add_task("[cyan]Uploading RootFS", total=op.getsize(rootfs))
|
||||||
with open(rootfs, "rb") as rootfs:
|
with open(rootfs, "rb") as rootfs:
|
||||||
|
@ -348,7 +310,7 @@ def main() -> int:
|
||||||
else:
|
else:
|
||||||
console.log("Postinstall failed. Rebooting to system")
|
console.log("Postinstall failed. Rebooting to system")
|
||||||
adbd.reboot()
|
adbd.reboot()
|
||||||
return 4
|
return 174
|
||||||
|
|
||||||
console.log("Installing UEFI")
|
console.log("Installing UEFI")
|
||||||
bootshim = files.BootShim.get()
|
bootshim = files.BootShim.get()
|
||||||
|
@ -363,8 +325,9 @@ def main() -> int:
|
||||||
console.log("Patching boot image")
|
console.log("Patching boot image")
|
||||||
match adbd.shell2("uefi-patch").returncode:
|
match adbd.shell2("uefi-patch").returncode:
|
||||||
case 1:
|
case 1:
|
||||||
console.log("Failed to patch boot")
|
console.log("Failed to patch boot. Rebooting")
|
||||||
return 1
|
adbd.reboot()
|
||||||
|
return 176
|
||||||
case 2:
|
case 2:
|
||||||
console.log("Boot image already patched. Skipping")
|
console.log("Boot image already patched. Skipping")
|
||||||
adbd.reboot()
|
adbd.reboot()
|
||||||
|
@ -405,14 +368,5 @@ def main() -> int:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def run() -> None:
|
|
||||||
global adb
|
|
||||||
status = main()
|
|
||||||
if adb is not None:
|
|
||||||
with console.status("[cyan]Stopping adb server", spinner="line", spinner_style="white"):
|
|
||||||
adb.server_kill()
|
|
||||||
exit(status)
|
|
||||||
|
|
||||||
|
|
||||||
if "__main__" == __name__:
|
if "__main__" == __name__:
|
||||||
run()
|
exit(main())
|
||||||
|
|
Reference in a new issue