Skip to content

Commit 72b51bb

Browse files
committed
Add first script for google pixel 3a and enable unlcoking the bootloader
1 parent 69c5c9c commit 72b51bb

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

poetry.lock

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license = "GPLv3"
77

88
[tool.poetry.dependencies]
99
python = "^3.8"
10+
click = "^8.1.3"
1011

1112
[tool.poetry.dev-dependencies]
1213

scripts/__init__.py

Whitespace-only changes.

scripts/lineageos-on-pixel3a.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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()

scripts/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""Reusable functions for flashing."""
2+
from subprocess import check_output, STDOUT
3+
4+
5+
def run_fastboot_command(cmd: str) -> str:
6+
"""Run a fastboot command and return the result as string."""
7+
return check_output(['fastboot', cmd], stderr=STDOUT).decode()

0 commit comments

Comments
 (0)