|
| 1 | +"""Script to flash a google pixel 3a. |
| 2 | +
|
| 3 | +Example usage: |
| 4 | +
|
| 5 | +
|
| 6 | +""" |
| 7 | +import click |
| 8 | +from subprocess import call |
| 9 | + |
| 10 | +from utils import run_fastboot_command |
| 11 | + |
| 12 | + |
| 13 | +@click.command() |
| 14 | +@click.option('--recovery', help='Path to the recovery file to flash. (Can be TWRP)') |
| 15 | +@click.option('--image', help='Path to the lineage os image to flash.') |
| 16 | +def install_lineage_os(recovery: str, image: str): |
| 17 | + unlocking_bootloader_result = unlock_bootloader() |
| 18 | + |
| 19 | + |
| 20 | +def reboot_device(): |
| 21 | + """Reboot the connected device.""" |
| 22 | + click.echo("\nRunning: fastboot reboot") |
| 23 | + if call('fastboot' + ' reboot', shell=True) < 0: |
| 24 | + click.echo("*** Reboot command failed! ***") |
| 25 | + return 4 |
| 26 | + return 0 |
| 27 | + |
| 28 | + |
| 29 | +def reboot_device_into_bootloader(): |
| 30 | + """Reboot the connected device back into fastboot.""" |
| 31 | + click.echo("\nRunning: fastboot reboot-bootloader") |
| 32 | + if call('fastboot reboot bootloader', shell=True) < 0: |
| 33 | + click.echo("*** Reboot-bootloader command failed! ***") |
| 34 | + return 4 |
| 35 | + return 0 |
| 36 | + |
| 37 | + |
| 38 | +def unlock_bootloader(): |
| 39 | + """Function to unlock the bootloader.""" |
| 40 | + # reboot into fastboot mode |
| 41 | + reboot_res = reboot_device_into_bootloader() |
| 42 | + if reboot_res == 4: |
| 43 | + click.echo("Unlocking the bootloader failed. Exiting.") |
| 44 | + return False |
| 45 | + # list devices |
| 46 | + devices = run_fastboot_command(cmd="devices") |
| 47 | + click.echo(f"Found: {devices}") |
| 48 | + # actually unlock the bootloader |
| 49 | + unlock_res = run_fastboot_command(cmd="flashing unlock") |
| 50 | + click.echo(f"{unlock_res}") |
| 51 | + # reboot device |
| 52 | + reboot_res = reboot_device() |
| 53 | + if reboot_res == 4: |
| 54 | + click.echo("Unlocking the bootloader failed while final reboot. Exiting.") |
| 55 | + return False |
| 56 | + click.echo("Bootloader is now unlocked!") |
| 57 | + click.echo(">>Since the device resets completely, you will need to re-enable USB debugging to continue.") |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +if __name__ == '__main__': |
| 62 | + install_lineage_os() |
0 commit comments