#!/usr/bin/env sh ## OnePlus X (16 GB) [2015] - ARMv7l (ARM / armhf / ARM 32-bit) ## Flash/Patch path: OOS 3.1.4 (Android 6) -> LOS 14.1 (Android 7) + TWRP v3.4 + Magisk v27 ## ## When flashing OOS, it will put on latest (official) firmware as well as system and recovery ## This is why OOS ZIP is so large over LOS (as it only has system) ## Firmware = partitions? = bootloader/fastboot, bootanimation, radio, etc ## ## Device needs to have USB debugging mode enabled via developer options already ## Settings -> System -> About phone -> Build number: 7x taps ## Settings -> Search: "USB Debugging" -> Enable -> Always allow: RSA key fingerprint ## _Menu structure changes between Android 10 + 11_ ## ## If device bootloader is locked, when unlocking will reboot the device, breaking this script ## Re-run script (may need to re-enabled USB Debugging) ## ## Unlike OnePlus One: ## - Able to install LOS & Magisk in the same session (without rebooting in-between) ## - Need to sleep at times, as TWRP can be slow (not sure if my hardware or TWRP version/software) ## ## Kali NetHunter: ## - No pre-imaged images - need to build ourselves: $ ./build.py -d oneplusx-cm ## - Renaming Magisk APK to ZIP bypasses Digest verification ## - NetHunter isn't (yet?) supported on LOS 14.1 (only CM 13, and can't find "official" ROM =() ## ## Misc terms: ## - OOS recovery refers to bootloader as fastboot ## - OOS system refers to bootloader as bootloader ## ## ./$0 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ## wait_device wait_device() { #set +x; while ! adb devices | grep -q recovery; do echo "[i] Waiting on the device to be in recovery mode"; sleep 2; done; sleep 2; set -x #set +x; while ! adb devices | grep -qw 'device$'; do echo "[i] Waiting for the first time install/setup wizard to be completed, and for USB debugging to be re-enable via developer options"; sleep 5; done; sleep 2; set -x #set +x; while ! adb devices | grep -qw 'device$'; do echo "[i] Waiting on device to be in system mode, with USB debugging enabled"; sleep 2; done; sleep 2; set -x ## Gets to be too verbose set +x; mode="${1:-recovery}" case "${mode}" in recovery) device="recovery" msg="[i] Waiting on the device to be in recovery mode"; i=2;; setup) device=device msg="[i] Waiting for the first time install/setup wizard to be completed, and for USB debugging to be re-enable via developer options"; i=5;; system) device=device msg="[i] Waiting on device to be in system mode"; i=2;; *) echo "[-] Unknown mode: ${mode}" >&2 && exit 1;; esac while ! adb devices | grep -q "${device}$"; do echo "${msg}" sleep "${i}"s done; ## Fix: TWRP does not appear to be running. Waiting for TWRP to start . . . sleep 5s ## Be verbose again set -x } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ## Be verbose - show commands set -x ## Path may need altering ## REF: https://download.g0tmi1k.com/android/oneplusx-onyx/ cd ~/oneplusx-onyx/ ## Bootloader adb reboot bootloader fastboot oem device-info fastboot oem unlock # If device was previously locked, will see a prompt. Select Yes and it wipe all data before rebooting. Plus will break this script! # > FAILED (remote: 'oem unlock is disabled') -> Need to have "Enable: OEEM unlocking" via developer options being enabled #adb reboot bootloader # Solution to the above issue (or just re-run!) ## Team Win Recovery Project (TWRP) ## Can't automate OOS's recovery due to lack of CLI options (so will need todo this a few times) ## Will be overwritten when flashing OOS fastboot flash recovery twrp-3.4.0-0-onyx.img # Need to have "disabled: updated recovery" via developer options when enabled fastboot boot twrp-3.4.0-0-onyx.img # Doesn't always work (may need to completely power off and boot into recovery - hold power & volume down, until on/vibrate) ## Stock/Vendor ROM (OxygenOS - OOS) wait_device recovery adb push OnePlusXOxygen_14_OTA_019_all_201611071506_03f73e21449d4d31.zip /sdcard/oos-3.1.4.zip; adb shell 'twrp install /sdcard/oos-3.1.4.zip' # Will replace TWRP/recovery adb reboot ## (Re-)Enable developer mode wait_device setup ## Team Win Recovery Project (TWRP) ...again adb reboot bootloader # TWRP can't install IMG files from CLI (yet), otherwise could install itself from itself! fastboot flash recovery twrp-3.4.0-0-onyx.img # Re-flash TWRP, as OOS replaced theirs fastboot boot twrp-3.4.0-0-onyx.img # Workaround, as can't do: $ fastboot reboot recovery ## LineageOS (LOS) + Magisk wait_device recovery ## If doing OOS -> LOS the following needs to be wiped: adb shell 'twrp wipe data' # Fix: Can't install this package on top of incompatible data. Please try another package or run a factory reset sleep 5s # TWRP seams to hang between wiping adb shell 'twrp wipe system' # Fix: E1001: Failed to update system image # TWRP is a 'dated' version, and CLI doesn't have: $ twrp format [...] adb reboot recovery # Reboot is a hard requirement for the E1001 issue sleep 5s # Sleep is to allow the device to restart (as not changing modes this time!) wait_device recovery adb push lineage-14.1-20181110-nightly-onyx-signed.zip /sdcard/los-14.1.zip; adb shell 'twrp install /sdcard/los-14.1.zip' ## Magisk adb push Magisk-v27.0.apk /sdcard/Magisk-27.zip; adb shell 'twrp install /sdcard/Magisk-27.zip' # APK -> ZIP isn't a mistake # v28.0 doesn't work with TWRP, but does work with: $ adb install Magisk-v28.0.apk adb reboot ## (Re-)Enable developer mode #wait_device setup ## Kali NetHunter ## REF: https://gitlab.com/kalilinux/nethunter/build-scripts/kali-nethunter-kernels/-/raw/main/devices.yml #wait_device system #adb push *nethunter*oneplusx*.zip /sdcard/nh-6.zip #adb shell 'twrp install /sdcard/nh-6.zip' # Opt'ing to to install via Magisk instead #adb shell 'su -c magisk --install-module /sdcard/nh-6.zip' # Needs Internet access to complete first time app launch of Magisk (aka update) then patch boot and finally reboot tp apply before this command fully work exit 0 - - - ## OxygenOS (OOS) 3 -> LineageOS (LOS) 14.1 **Without wiping /data**: ```console $ adb shell 'cat /tmp/recovery.log' [...] about to run program [/tmp/install/bin/otasigcheck.sh] with 1 args You have an installed system that isn't signed with this build's key, aborting... run_program: child exited with status 124 script aborted: Can't install this package on top of incompatible data. Please try another package or run a factory reset Can't install this package on top of incompatible data. Please try another package or run a factory reset Updater process ended with ERROR: 7 ``` **Without wiping /system**: ```console $ adb shell 'cat /tmp/recovery.log' [...] about to run program [/tmp/install/bin/otasigcheck.sh] with 1 args Patching system image unconditionally... performing update Patching system image unconditionally... blockimg version is 4 maximum stash entries 0 creating stash /cache/recovery/5a79362318d00cf4c316e86435b3ed38dd35082d/ script aborted: E1001: Failed to update system image. E1001: Failed to update system image. error: 1001 cause: 101 Updater process ended with ERROR: 7 ``` - - - ## Magisk .APK vs .ZIP ```console $ adb push Magisk-v27.0.apk /sdcard/Magisk-v27.0.apk; adb shell 'twrp install /sdcard/Magisk-v27.0.apk' Magisk-v27.0.apk: 1 file pushed, 0 skipped. 7.1 MB/s (12498796 bytes in 1.673s) Installing zip file '/sdcard/Magisk-v27.0.apk' Checking for Digest file... No digest file found for '/sdcard/Magisk-v27.0.apk'. Please unselect Enable Digest verification to restore. E:Aborting zip install: Digest verification failed Error installing zip file '/sdcard/Magisk-v27.0.apk' Done processing script file $ $ adb push Magisk-v27.0.apk /sdcard/Magisk-v27.0.zip; adb shell 'twrp install /sdcard/Magisk-v27.0.zip' Magisk-v27.0.apk: 1 file pushed, 0 skipped. 7.5 MB/s (12498796 bytes in 1.583s) Installing zip file '/sdcard/Magisk-v27.0.zip' Checking for Digest file... Unmounting System... *********************** Magisk 27.0 Installer *********************** - Mounting /system - No vbmeta partition, patch vbmeta in boot image - Target image: /dev/block/mmcblk0p7 - Device platform: armeabi-v7a - Constructing environment - Adding addon.d survival script - Unpacking boot image - Checking ramdisk status - Magisk patched boot image detected - Patching ramdisk - Repacking boot image - Flashing new boot image - Unmounting partitions - Done Done processing script file $ ```