|
| 1 | +"""Script to flash a Samsung Galaxy A3. |
| 2 | +
|
| 3 | +Following: https://lineageosroms.com/a3xelte/#basic-requirements |
| 4 | +
|
| 5 | +Example usage: |
| 6 | + poetry run python scripts/lineageos-on-galaxy-a3.py --recovery images/samsung-galaxy-a3/twrp-3.6.2_9-0-a3xelte.img --image images/samsung-galaxy-a3/lineage-18.1-20220819-UNOFFICIAL-a7xelte.zip |
| 7 | +""" |
| 8 | +import click |
| 9 | +from time import sleep |
| 10 | +from subprocess import call |
| 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 | + """Main function to install lineage os.""" |
| 18 | + click.echo("Install lineage os on Samsung Galaxy A3.") |
| 19 | + # Steps 1: Unlock the bootloader |
| 20 | + unlock_result = unlocking_bootloader_result = unlock_bootloader() |
| 21 | + if not unlock_result: |
| 22 | + click.echo("Unlocking the bootloader failed. Exiting.") |
| 23 | + return False |
| 24 | + |
| 25 | + # Step 2: Temporarily booting a custom recovery using fastboot |
| 26 | + boot_recovery_result = boot_recovery(recovery) |
| 27 | + if not boot_recovery_result: |
| 28 | + click.echo("Flashing recovery failed. Exiting.") |
| 29 | + return False |
| 30 | + |
| 31 | + # Step 3: Installing LineageOS from recovery |
| 32 | + install_result = install_os(image) |
| 33 | + if not install_result: |
| 34 | + click.echo("Installing LineageOS failed. Exiting.") |
| 35 | + return False |
| 36 | + |
| 37 | + click.echo( |
| 38 | + "Installing lineageOS was successful! Have fun with your device! :)") |
| 39 | + return True |
| 40 | + |
| 41 | + |
| 42 | +def install_os(image: str): |
| 43 | + """Installing LineageOS from recovery with the image filepath given in image.""" |
| 44 | + # manuall wipeing and stuff |
| 45 | + click.echo("Now tap 'Wipe'.") |
| 46 | + sleep(2) |
| 47 | + click.echo("Then tap 'Format Data' and continue with the formatting process. This will remove encryption and delete all files stored in the internal storage.") |
| 48 | + sleep(2) |
| 49 | + click.echo("Return to the previous menu and tap 'Advanced Wipe', then select the 'Cache' and 'System' partitions and then 'Swipe to Wipe'.") |
| 50 | + confirmed = click.confirm("Confirm to continue", |
| 51 | + default=True, abort=False, prompt_suffix=': ', show_default=True, err=False) |
| 52 | + |
| 53 | + # sideload lineage os image with ADB |
| 54 | + confirmed = click.confirm( |
| 55 | + "On the device, select “Advanced”, “ADB Sideload”, then swipe to begin sideload. Then confirm here", |
| 56 | + default=True, abort=False, prompt_suffix=': ', show_default=True, err=False |
| 57 | + ) |
| 58 | + click.echo("\nRunning: adb sideload <image>") |
| 59 | + if call(f'adb sideload {image}', shell=True) < 0: |
| 60 | + click.echo("*** Sideloading image failed! ***") |
| 61 | + return False |
| 62 | + |
| 63 | + # (Optionally): If you want to install any additional add-ons, repeat the sideload steps above for those packages in sequence. |
| 64 | + |
| 65 | + confirmed = click.confirm("Confirm to continue", |
| 66 | + default=True, abort=False, prompt_suffix=': ', show_default=True, err=False) |
| 67 | + |
| 68 | + click.echo("\nRebooting") |
| 69 | + if call(f'adb reboot', shell=True) < 0: |
| 70 | + return False |
| 71 | + |
| 72 | + click.echo( |
| 73 | + "Flashing finished. Now press 'back' (arrow) and then 'Reboot system now' to finish the installation.") |
| 74 | + return True |
| 75 | + |
| 76 | + |
| 77 | +def boot_recovery(recovery: str): |
| 78 | + """ |
| 79 | + Temporarily booting a custom recovery using fastboot. |
| 80 | +
|
| 81 | + Using the recovery found in the path 'recovery'. |
| 82 | + """ |
| 83 | + # check if heimdall is installed. |
| 84 | + heimdall_res = check_heimdall() |
| 85 | + if heimdall_res == 4: |
| 86 | + click.echo("No heimdall found. Exiting.") |
| 87 | + return False |
| 88 | + |
| 89 | + # reboot into download mode |
| 90 | + click.confirm("Turn on your device and wait until its fully booted.", |
| 91 | + default=True, abort=False, prompt_suffix=': ', show_default=True, err=False) |
| 92 | + click.echo("\nBooting into download mode:") |
| 93 | + if call(f'adb reboot download', shell=True) < 0: |
| 94 | + click.echo("*** Booting into download mode failed! ***") |
| 95 | + return False |
| 96 | + sleep(5) |
| 97 | + |
| 98 | + # install TWRP recovery from image |
| 99 | + click.echo("\nFlash custom recovery") |
| 100 | + if call(f"heimdall flash --no-reboot --RECOVERY {recovery}", shell=True) < 0: |
| 101 | + click.echo("*** Flashing custom recovery failed! ***") |
| 102 | + return False |
| 103 | + click.echo( |
| 104 | + "A blue transfer bar will appear on the device showing the recovery image being flashed.") |
| 105 | + sleep(5) |
| 106 | + click.echo("Once it's done, unplug the USB cable from your device.") |
| 107 | + click.echo("Manually reboot into recovery. Press the Volume Down + Power buttons for 8~10 seconds until the screen turns black & release the buttons immediately when it does, then boot to recovery with the device powered off, hold Volume Up + Home + Power.") |
| 108 | + confirmed = click.confirm("Confirm to continue", |
| 109 | + default=True, abort=False, prompt_suffix=': ', show_default=True, err=False) |
| 110 | + |
| 111 | + click.echo("Recovery flashed successfully.") |
| 112 | + return True |
| 113 | + |
| 114 | + |
| 115 | +def unlock_bootloader(): |
| 116 | + """Function to unlock the bootloader.""" |
| 117 | + confirmed = click.confirm("Turn on developer options and OEM Unlock on your phone.", |
| 118 | + default=True, abort=False, prompt_suffix=': ', show_default=True, err=False) |
| 119 | + #click.echo("Now, turn of your phone. Then press Volume Up and Power key for a couple of seconds. All your data will be deleted!") |
| 120 | + #click.echo("Release both keys when the SAMSUNG Galaxy A3 Core logo pops up.") |
| 121 | + # click.confirm("After that choose Reboot to bootloader by using Volume keys to scroll down and the Power button to confirm that. ", |
| 122 | + # default=True, abort=False, prompt_suffix=': ', show_default=True, err=False) |
| 123 | + return confirmed |
| 124 | + |
| 125 | + |
| 126 | +def check_heimdall(): |
| 127 | + """Check if heimdall is installed properly.""" |
| 128 | + if call("heimdall info", shell=True) != 0: |
| 129 | + click.echo("*** Heimdall is not properly installed. Exiting.") |
| 130 | + return 4 |
| 131 | + return 0 |
| 132 | + |
| 133 | + |
| 134 | +if __name__ == '__main__': |
| 135 | + install_lineage_os() |
0 commit comments