eudemonics

half-assed oneplus one/android toolkit v1 OSX linux windows

Aug 16th, 2014
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 31.78 KB | None | 0 0
  1. #!/usr/bin/python
  2. ### HALF ASSED ONE PLUS ONE TOOLKIT v1.0 OFFICIAL RELEASE!
  3. ##### AUTHOR: vvn
  4. ##### RELEASE DATE: august 18, 2014
  5. ##### this is a very half-assed project and i cannot guarantee fast or frequent updates.
  6. ##### USE AT YOUR OWN RISK. i am not responsible for any damage to your device.
  7. ##### IMPORTANT!!! ***requires pyadb.py (also on my pastebin)***
  8. ##### GET PYADB (pyadb.py) HERE: http://pastebin.com/g2Z08JN1
  9. ##### for #8 custom recovery flash, download files (filehost + filename) and put in script directory:
  10. ##### filehost: notworth (dot) it / opo / opotoolkit /
  11. ##### filenames: twrp.img, philz.img, cwm.img
  12. ##### download ZIP file containing scripts, superSU, custom recoveries, and adb/fastboot binaries for OSX/windows:
  13. ##### filehost: notworth (dot) it / opo /
  14. ##### filename: 1plus1-halfassedtoolkit_v1.zip
  15. ##### for #8 flash options, download + unzip (filehost + filename):
  16. ##### filehost: notworth (dot) it / opo /
  17. ##### filenames: XNPH25R.zip, XNPH30O.zip
  18. ##### unzip files as subdirectories inside script location: /scripthome/XNPH25R  /scripthome/XNPH30O
  19. ##### to report bugs or suggestions, email me: vvn (at) eudemonics (dot) org
  20. ##### feel free to share, modify, or whatever.
  21. ##### you can use this with any android device, not just the oneplus one. just change out the files.
  22. ##### some credit would be nice since i worked pretty hard on this.
  23. ##### but what would be even better is if you bought my EP!
  24. ##### stream and buy it here: dreamcorp.bandcamp.com or any major online digital retailer
  25. ##### to run, save this file as opotoolkit.py and save pyadb.py (link above) in same directory
  26. ##### make sure you have the android SDK installed.
  27. ##### download android SDK here: https://developer.android.com/sdk/
  28. ##### you can either put the scripts in the same directory as your android SDK,
  29. ##### or create an environmental path variable for your android SDK directory
  30. ##### python 2.7 is also required. download python here: https://www.python.org/downloads/
  31.  
  32. import subprocess, sys, re, os, os.path, time, datetime
  33. from pyadb import *
  34.  
  35. def main():
  36.    """menu output user input"""
  37.    quotes = [
  38.       ]
  39.    print ('''\033[34m
  40. *************************************************
  41. *** \033[36mHALF-ASSED ONE PLUS ONE TOOLKIT v1.0 BETA \033[34m***
  42. ******************** \033[35mby vvn \033[34m*********************
  43. ************* \033[32mUSE AT YOUR OWN RISK! \033[34m*************
  44. ********** \033[37msupport my work: buy my EP! \033[34m**********
  45. ********* \033[37mhttp://dreamcorp.bandcamp.com \033[34m*********
  46. *************************************************\033[0m\n''')
  47.  
  48.    print("\033[33mDEVICE MUST BE CONNECTED VIA USB WITH ANDROID DEBUGGING ENABLED. \033[0m\n")
  49.    
  50.    print ('''\033[32mMAIN MENU:\033[0m
  51. -\033[31m[1]\033[37m reboot into android, bootloader, or recovery\033[0m
  52. -\033[31m[2]\033[37m wipe device\033[0m
  53. -\033[31m[3]\033[37m boot once into custom recovery without flashing\033[0m
  54. -\033[31m[4]\033[37m install or uninstall APK\033[0m
  55. -\033[31m[5]\033[37m copy files between computer and device, or sync\033[0m
  56. -\033[31m[6]\033[37m backup or restore device\033[0m
  57. -\033[31m[7]\033[37m root device and/or install ZIP in fastboot\033[0m
  58. -\033[31m[8]\033[37m unlock bootloader and/or flash custom image\033[0m
  59. -\033[31m[9]\033[37m run shell command on device\033[0m
  60. -\033[31m[0]\033[37m quit \033[0m\n''')
  61.  
  62.    global option
  63.    option = raw_input('Select an option 0-9 --> ')
  64.    
  65.    while not re.search(r'^[0-9]$', option):
  66.       option = raw_input('Invalid selection. Please select an option 0-9 --> ')
  67.  
  68.    if option:
  69.  
  70.       obj = pyADB()
  71.  
  72.       if option == '1': #reboot      
  73.          rboption = raw_input("please enter 1 to reboot into android. enter 2 to reboot to bootloader. enter 3 to reboot to recovery. --> ")
  74.          while not re.search(r'^[123]$', rboption):
  75.             rboption = raw_input("invalid selection. please enter 1 to reboot into android, 2 for bootloader, and 3 for recovery. --> ")
  76.          rbtype = "android"
  77.          if rboption == '1':
  78.             rbtype = "android"
  79.          elif rboption == '2':
  80.             rbtype = "bootloader"
  81.          elif rboption == '3':
  82.             rbtype ="recovery"
  83.          checkdev = obj.get_state()
  84.          listdev = obj.attached_devices()
  85.          fastdev = obj.fastboot_devices()
  86.          if checkdev is not None:
  87.             print("adb get-status: " + str(checkdev) + "\n")
  88.             print("rebooting via ADB..\n")
  89.             obj.reboot(rbtype)
  90.             time.sleep(0.9)
  91.             main()
  92.          elif listdev >= 0:
  93.             print("adb devices: " + str(listdev) + "\n")
  94.             print("rebooting via ADB...\n")
  95.             obj.reboot(rbtype)
  96.             time.sleep(0.9)
  97.             main()
  98.          elif listdev == 0 and fastdev is not None:
  99.             print("adb devices: " + str(listdev) + "\n")
  100.             print("rebooting via fastboot..\n")
  101.             if rboption == '3':
  102.                rbtype = "bootloader"
  103.             obj.fastreboot(rbtype)
  104.             time.sleep(0.9)
  105.             main()
  106.          elif [[ len(str(fastdev)) > 5 | fastdev > 0 ]] and fastdev is not None:
  107.             print("fastboot devices: " + str(fastdev) + "\n")
  108.             print("rebooting via fastboot...\n")
  109.             if rboption == '3':
  110.                rbtype = "bootloader"
  111.             obj.fastreboot(rbtype)
  112.             time.sleep(0.9)
  113.             main()
  114.          else:
  115.             print("rebooting via fastboot...\n")
  116.             if rboption == '3':
  117.                rbtype = "bootloader"
  118.             fastreboot = obj.fastreboot(rbtype)
  119.             if not fastreboot:
  120.                print("rebooting via ADB after fastboot... \n")
  121.                obj.reboot(rtype)
  122.                if "error" in str(fastreboot):
  123.                   print("rebooting via fastboot second time...\n")
  124.                   obj.fastreboot(rbtype)
  125.             time.sleep(0.9)
  126.             main()
  127.  
  128.       elif option == '2': #wipe
  129.          print("\033[35m***WIPING SOME PARTITIONS WILL ERASE YOUR DATA.***\n please make sure to back up any important data before proceeding!\n\n")
  130.          print('''\033[36mCHOOSE AN OPTION 1-8:\033[32m\n
  131.   [1]\033[37m perform a full system wipe [system, data, and cache partitions]\033[32m
  132.   [2]\033[37m wipe only the system partition\033[32m
  133.   [3]\033[37m wipe only the data partition\033[32m
  134.   [4]\033[37m wipe only the cache partition\033[32m
  135.   [5]\033[37m wipe only the boot partition\033[32m
  136.   [6]\033[37m wipe only the recovery partition\033[32m
  137.   [7]\033[37m flash device to factory images [flash system, boot, and recovery]\033[32m
  138.   [8]\033[37m return to main menu\n\n\033[0m''')
  139.          confirmwipe = raw_input("please enter an option 1-8 --> ")
  140.          while not re.search(r'^[1-8]$', confirmwipe):
  141.             confirmwipe = raw_input('not a valid option. please enter a selection between 1-8 from above choices -->')        
  142.          if confirmwipe == '1':
  143.             obj.wipe('all')
  144.             raw_input("press ENTER to continue.")
  145.             time.sleep(0.9)
  146.             main()
  147.          elif confirmwipe == '2':
  148.             obj.wipe('system')
  149.             raw_input("press ENTER to continue.")
  150.             time.sleep(0.9)
  151.             main()
  152.          elif confirmwipe == '3':
  153.             obj.wipe('data')
  154.             raw_input("press ENTER to continue.")
  155.             time.sleep(0.9)
  156.             main()
  157.          elif confirmwipe == '4':
  158.             obj.wipe('cache')
  159.             raw_input("press ENTER to continue.")
  160.             time.sleep(0.9)
  161.             main()
  162.          elif confirmwipe == '5':
  163.             obj.wipe('boot')
  164.             raw_input("press ENTER to continue.")
  165.             time.sleep(0.9)
  166.             main()
  167.          elif confirmwipe == '6':
  168.             obj.wipe('recovery')
  169.             raw_input("press ENTER to continue.")
  170.             time.sleep(0.9)
  171.             main()
  172.          elif confirmwipe == '7':
  173.             obj.wipe('flashall')
  174.             raw_input("press ENTER to continue.")
  175.             time.sleep(0.9)
  176.             main()
  177.          elif confirmwipe == '8':
  178.             time.sleep(0.9)
  179.             main()
  180.          else:
  181.             print("there was a problem connecting to the device. returning to menu..\n")
  182.             time.sleep(0.9)
  183.             main()
  184.            
  185.                          
  186.       elif option == '3': #boot custom recovery
  187.          recovery = raw_input("enter 1 for TWRP, 2 for ClockworkMod, or 3 for Philz recovery --> ")
  188.          while not re.search(r'^[1-3]$', recovery):
  189.             recovery = raw_input("invalid selection. please choose 1 for TWRP, 2 for CWM, or 3 for Philz --> ")
  190.          obj.reboot("bootloader")
  191.          if recovery == '1':
  192.             obj.bootimg("twrp.img")
  193.          elif recovery == '2':
  194.             obj.bootimg("cwm.img")
  195.          elif recovery == '3':
  196.             obj.bootimg("philz.img")
  197.          else:
  198.             print("unable to connect to device.\n")    
  199.            
  200.          time.sleep(0.9)
  201.          main()
  202.  
  203.       elif option == '4': #install or uninstall APK
  204.          whichinstall = raw_input("please enter 1 to install, 2 to uninstall, or 3 to return to main menu. --> ")
  205.          while not re.search(r'^[1-3]$', whichinstall):
  206.             whichinstall = raw_input("invalid selection. please enter 1 to install, 2 to uninstall, or 3 to return to main menu. --> ")
  207.          if not os.path.exists('apps'):
  208.             os.mkdirs('apps')
  209.          if whichinstall == '1':
  210.             getapk = raw_input("place the APK file to install in the \"apps\" subdirectory, then type the filename --> ")
  211.             apkfile = os.path.join('apps', getapk)
  212.             while not os.path.isfile(apkfile):
  213.                print("\033[37mfile does not exist. please make sure the APK file is in the \"apps\" subdirectory.\033[0m\n")
  214.                getapk = raw_input("enter valid filename for the APK you want to install -->")
  215.                apkfile = os.path.join('apps', getapk)
  216.             print("installing \033[36m" + getapk + "\033[0m...")
  217.             obj.install(apkfile)
  218.             raw_input("press ENTER to continue...")
  219.             time.sleep(0.9)
  220.             main()
  221.            
  222.          if whichinstall == '2':
  223.             getunapk = raw_input("place the APK file you wish to uninstall in the \"apps\" subdirectory, then enter filename --> ")
  224.             unapkfile = os.path.join('apps', getunapk)
  225.             while not os.path.isfile(unapkfile):
  226.                print("\033[37mfile does not exist. please make sure the APK file is in the \"apps\" subdirectory.\033[0m\n")
  227.                getunapk = raw_input("enter valid filename for the APK you want to uninstall -->")
  228.                unapkfile = os.path.join('apps', getunapk)
  229.             keepcheck = raw_input("would you like to keep your app data? Y or N --> ")
  230.             while not re.search(r'^[nyNY]$', keepcheck):
  231.                keepcheck = raw_input("invalid selection. please enter Y to keep app data or N to erase --> ")
  232.             keepargs = "no"
  233.             if re.match(r'(?i)Y', keepcheck):
  234.                keepargs = "keep"
  235.             print("uninstalling \033[36m" + getunapk + "\033[0m...")
  236.             obj.uninstall(unapkfile, keepargs)
  237.             uninstcmd = "pm uninstall -k " + unapkfile
  238.             obj.shell(uninstcmd)
  239.             raw_input("press ENTER to continue...")
  240.             time.sleep(0.9)
  241.             main()
  242.            
  243.          if whichinstall == '3':
  244.             main()
  245.            
  246.          else:
  247.             print("could not connect to device.\n")
  248.             time.sleep(0.9)
  249.             main()
  250.  
  251.       elif option == '5': #copy
  252.          copytype = raw_input("to push file from computer to device, enter T. to pull file from device to computer, enter F. to sync, enter S --> ")
  253.          matchT = re.search(r'(?i)T', copytype)
  254.          matchF = re.search(r'(?i)F', copytype)
  255.          matchS = re.search(r'(?i)S', copytype)
  256.          while not re.search(r'^[(?i)T|(?i)F|(?i)S]$', copytype):
  257.             copytype = raw_input("invalid option. please enter T to push file, F to pull file, or S to sync --> ")
  258.            
  259.          if matchT:
  260.             getpushfile = raw_input("please enter relative path for the file or directory on your computer to copy --> ")
  261.             while not os.path.exists(getpushfile):
  262.                getpushfile = raw_input("file does not exist. please enter valid path --> ")
  263.             getpushremote = raw_input("please enter destination path for copied file(s) on the device --> ")
  264.             obj.push(getpushfile, getpushremote)
  265.             raw_input("press ENTER to continue...")
  266.            
  267.          elif matchF:
  268.             getpullfile = raw_input("please enter path for the file or directory on your device to copy --> ")
  269.             getpulllocal = raw_input("please enter destination path for copied file(s) on your computer --> ")
  270.             if not os.path.exists(getpulllocal):
  271.                os.mkdirs(getpulllocal)
  272.             obj.pull(getpullfile, getpulllocal)
  273.             raw_input("press ENTER to continue...")
  274.            
  275.          elif matchS:
  276.             syncargs = raw_input("enter 1 to set sync directory, or 2 to sync the default system and data directories. --> ")
  277.             while not re.search(r'^[12]$', syncargs):
  278.                syncargs = raw_input("invalid selection. please enter 1 to set sync directory, or 2 to use default. --> ")
  279.             if syncargs == '1':
  280.                syncdir = raw_input("please enter path to the local directory you wish to sync --> ")
  281.                while not os.path.exists(syncdir):
  282.                   syncdir = raw_input("the directory you entered does not exist. please enter valid path --> ")
  283.                obj.sync(syncdir)
  284.                raw_input("press ENTER to continue...")
  285.             elif syncargs == '2':
  286.                obj.sync()
  287.                raw_input("press ENTER to continue...")
  288.             else:
  289.                print("could not connect to device.\n")
  290.          
  291.          else:
  292.             print("could not connect to device.\n")
  293.            
  294.          time.sleep(0.9)
  295.          main()
  296.  
  297.       elif option == '6': #backup
  298.          whichbackup = raw_input("to backup, enter 1. to restore, enter 2 --> ")
  299.          while not re.search(r'^[12]$', whichbackup):
  300.             whichbackup = raw_input("invalid selection. please enter 1 to backup or 2 to restore. --> ")
  301.          if whichbackup == '1':
  302.             backupfile = 'backup-' + str(datetime.date.today()) + '.ab'
  303.             obj.backup(backupfile)
  304.          elif whichbackup == '2':
  305.             restorefile = raw_input("please enter path to backup file on your computer --> ")
  306.             while not os.path.isfile(restorefile):
  307.                restorefile = raw_input("file does not exist. please enter valid path --> ")
  308.             obj.restore(restorefile)
  309.          time.sleep(0.9)
  310.          main()
  311.  
  312.       elif option == '7': #root
  313.      
  314.          def suroot():
  315.             superSU = 'UPDATE-SuperSU-v2.01.zip'
  316.             remotesuperSU = '/sdcard/UPDATE-SuperSU-v2.01.zip'
  317.             obj.push(superSU, remotesuperSU)
  318.             obj.reboot("bootloader")
  319.             time.sleep(0.9)
  320.             obj.bootimg("twrp.img")
  321.             print("on device, choose INSTALL from TWRP menu, then select file \033[36m" + superSU + "\033[0m in the \033[36m/sdcard\033[0m directory.\n")
  322.             raw_input("if install is successful, select REBOOT from TWRP menu on device. press ENTER to continue.")
  323.          
  324.          def towroot():
  325.             obj.install("apps/tr.apk")
  326.             print("\033[36m\nif APK installed successfully, locate TR [towelroot] in app drawer on device and run.\n\033[0m")
  327.             raw_input("tap on MAKE IT RAIN. the results should appear shortly. follow instructions on device, then press ENTER to continue..")
  328.            
  329.          print("\033[36mif the firmware release date for your device is before june 2014, there is a chance the towelroot exploit may work.\n")
  330.          print("\033[32mhowever, superSU is a much safer and more widely confirmed root method for the oneplus one. ATTEMPT AT YOUR OWN RISK!\033[0m\n\n")
  331.          rootcheck = raw_input("which root method would you like to try? enter 1 for towelroot or 2 for superSU [recommended for oneplus one]. --> ")
  332.          while not re.search(r'^[12]$', rootcheck):
  333.             rootcheck = raw_input("invalid selection. enter 1 to install towelroot exploit, or 2 to install superSU package. --> ")
  334.          if rootcheck == '1':
  335.             towroot()
  336.             trysuroot = raw_input("if towelroot failed, press 1 to launch superSU method. otherwise, press ENTER to return to main menu. --> ")
  337.             if trysuroot == '1':
  338.                suroot()
  339.                time.sleep(0.9)
  340.                main()
  341.             else:
  342.                time.sleep(0.9)
  343.                main()
  344.          elif rootcheck == '2':
  345.             bootcustom = raw_input("press 1 to install superSU in TWRP recovery, or 2 to install in fastboot [lower success rate]. --> ")
  346.             while not re.search(r'^[12]$', bootcustom):
  347.                bootcustom = raw_input("invalid choice. please enter 1 to load TWRP or 2 for fastboot. --> ")
  348.             if bootcustom == '1':
  349.                suroot()
  350.             elif bootcustom == '2':
  351.                updatewhich = raw_input("to try installing superSU in fastboot, press 1. else, enter name of ZIP file to install --> ")
  352.                if updatewhich == '1':
  353.                   print("\033[35mattempting to install superSU via fastboot...\n\033[0m")
  354.                   obj.update(superSU)
  355.                   failsu = raw_input("if installation failed, press 1 to try sideload method. otherwise, press ENTER to continue...")
  356.                   if failsu == '1':
  357.                      obj.fastreboot("android")
  358.                      time.sleep(0.9)
  359.                      raw_input("\033[32mmake sure your computer is authorized to access your device over ADB, then press ENTER.\033[0m")
  360.                      obj.reboot("recovery")
  361.                      raw_input("in recovery menu on device, please select APPLY UPDATE, then APPLY FROM ADB. press ENTER when ready.")
  362.                      obj.sideload("UPDATE-SuperSU-v2.01.zip")
  363.                      superfail = raw_input("if update successful, choose REBOOT SYSTEM from device menu then press ENTER key. else, press 1 to install superSU from TWRP -->" )
  364.                      if superfail == '1':
  365.                         suroot()
  366.                      else:
  367.                         obj.get_state()
  368.                   time.sleep(0.9)
  369.                   main()
  370.                  
  371.                else:
  372.                   print("attempting to install " + updatewhich + "...\n\n")
  373.                   while not os.path.isfile(updatewhich):
  374.                      updatewhich = raw_input("invalid file path. please enter correct path of ZIP file to install --> ")
  375.                   obj.update(updatewhich)
  376.                   raw_input("please press ENTER to continue...")
  377.            
  378.             else:
  379.                print("failed to connect to device. returning to main menu.. \n\n")
  380.                
  381.          else:
  382.             print("failed to connect to device. returning to main menu.. \n\n")
  383.                  
  384.          time.sleep(0.9)
  385.          main()
  386.          
  387.       elif option == '8': #flash stock images/partitions
  388.      
  389.          def flashmenu():
  390.             print ('''\n\033[35mSTOCK IMAGES AVAILABLE TO FLASH - THIS WILL REPLACE YOUR CURRENT PARTITION!\n
  391. \033[36m***IF POSSIBLE, FLASH IN SEQUENTIAL ORDER - BOOT.IMG SHOULD GO FIRST***\n
  392. \033[33mLATEST UPDATE XNPH30O SELECTIONS IN YELLOW\n\033[0m
  393. -\033[31m[1]\033[37m XNPH25R stock BOOT.IMG \033[0m
  394. -\033[31m[2]\033[37m XNPH25R stock USERDATA(_64).IMG \033[35m[WIPES USER DATA!]\033[0m
  395. -\033[31m[3]\033[37m XNPH25R stock SYSTEM.IMG \033[0m
  396. -\033[31m[4]\033[37m XNPH25R stock RECOVERY.IMG \033[0m
  397. -\033[31m[5]\033[37m XNPH25R stock CACHE.IMG \033[0m
  398. -\033[31m[6]\033[37m XNPH25R stock radio, modem, aboot, & more \033[34m[flash-radio.sh]\033[0m
  399. -\033[31m[7]\033[33m XNPH30O stock radio, modem, sbl1, aboot \033[34m[flash-extras.sh]\033[0m
  400. -\033[31m[8]\033[33m XNPH30O stock OTA UPDATE #1 \033[0m
  401. -\033[31m[9]\033[33m XNPH30O stock OTA UPDATE #2 - FLASH UPDATE #1 FIRST! \033[0m
  402. -\033[31m[0]\033[37m quit\033[0m\n''')
  403.  
  404.             flashsel = raw_input("\033[32mselect a choice between 0 through 9 from menu \033[0m--> ")
  405.             while not re.search(r'^[0-9]$', flashsel):
  406.                flashsel = raw_input("invalid selection. please choose an option between 0 through 9 --> ")
  407.             print("\n\033[34mrebooting into bootloader...\033[0m\n")
  408.             obj.reboot("bootloader")
  409.            
  410.             if flashsel == '1':
  411.                obj.flashf("boot", "XNPH25R/boot.img")
  412.                raw_input("press ENTER key to continue...")
  413.                flashmenu()
  414.                
  415.             elif flashsel == '2':
  416.                whichsize = raw_input("IMPORTANT!! choose correct storage capacity: enter 1 for 16gb device, or 2 for 64gb device. --> ")
  417.                while not re.search(r'^[12]$', whichsize):
  418.                   whichsize = raw_input("invalid selection. enter 1 for 16gb device, or 2 for 64gb device. --> ")
  419.                if whichsize == '1':
  420.                   obj.flashf("userdata", "XNPH25R/userdata.img")
  421.                elif whichsize == '2':
  422.                   obj.flashf("userdata", "XNPH25R/userdata_64G.img")
  423.                else:
  424.                   print("ERROR: unable to connect to device.\n")  
  425.                raw_input("press ENTER key to return to flash menu...")
  426.                flashmenu()
  427.                
  428.             elif flashsel == '3':
  429.                obj.flashf("system", "XNPH25R/system.img")
  430.                raw_input("press ENTER key to continue...")
  431.                flashmenu()
  432.                
  433.             elif flashsel == '4':
  434.                obj.flashf("recovery", "XNPH25R/recovery.img")
  435.                raw_input("press ENTER key to continue...")
  436.                flashmenu()
  437.             elif flashsel == '5':
  438.                obj.flashf("cache", "XNPH25R/cache.img")
  439.                raw_input("press ENTER key to continue...")
  440.                flashmenu()
  441.             elif flashsel == '6':
  442.                subprocess.check_call(["./flash-radio.sh"], cwd="/XNPH25R")
  443.                raw_input("press ENTER key to continue...")
  444.                flashmenu()
  445.             elif flashsel == '7':
  446.                subprocess.check_call(["./flash-extras.sh"], cwd="/XNPH30O")
  447.                raw_input("press ENTER key to continue...")
  448.                flashmenu()
  449.             elif flashsel == '8':
  450.                obj.update("XNPH30O/XNPH30O-update1-signed.zip")
  451.                failupd = raw_input("if update failed, press 1 to try sideload option. otherwise, press ENTER key to continue...")
  452.                if failupd == '1':
  453.                   obj.fastreboot("android")
  454.                   raw_input("make sure your device is unlocked and your PC is authenticated for ADB access. press ENTER to continue.")
  455.                   print("\033[32mpushing first XNPH30O OTA update file to device..\033[0m\n")
  456.                   obj.push("XNPH30O/XNPH30O-update1-signed.zip", "/sdcard/XNPH30O-update1-signed.zip")
  457.                   raw_input("press ENTER to reboot into recovery.")
  458.                   obj.reboot("recovery")
  459.                   print("choose APPLY UPDATE from recovery menu and select APPLY FROM ADB.\n\n")
  460.                   raw_input("press ENTER to install the *first* XNPH30O OTA update now.")
  461.                   obj.sideload("XNPH30O/XNPH30O-update1-signed.zip")
  462.                   failside = raw_input("if update did not succeed, press 1 to install from device. otherwise, press ENTER to continue..")
  463.                   if failside == '1':
  464.                      print("choose APPLY UPDATE from recovery menu, then select CHOOSE FROM INTERNAL STORAGE.\n")
  465.                      print("select XNPH30O-update1-signed.zip from root of SDCARD directory and install file.\n\n")
  466.                      print("\033[35mif update failed, return to main menu and select option 3 to boot into custom recovery.\033[0m\n\n")
  467.                      menusel = raw_input("press 1 if update was successful, or 2 to return to main menu.")
  468.                      while not re.search(r'^[12]$',menusel):
  469.                         menusel = raw_input("invalid selection. press 1 for flash menu, or 2 to return to main menu.")
  470.                      if menusel == '1':
  471.                         obj.shell("rm -rf /sdcard/XNPH30O-update1-signed.zip")
  472.                         time.sleep(0.9)
  473.                         flashmenu()
  474.                      elif menusel == '2':
  475.                         time.sleep(0.9)
  476.                         main()
  477.                      else:
  478.                         print("error connecting to device. returning to main menu...\n")
  479.                         time.sleep(0.9)
  480.                         main()
  481.                   else:
  482.                      obj.shell("rm -rf /sdcard/XNPH30O-update1-signed.zip")
  483.                      print("\033[32mreturning to flash menu..\033[0m\n\n")
  484.                else:
  485.                   print("\033[32mreturning to flash menu..\033[0m\n\n")
  486.                
  487.                time.sleep(0.9)
  488.                flashmenu()
  489.                
  490.             elif flashsel == '9':
  491.                obj.update("XNPH30O/XNPH30O-update2-signed.zip")
  492.                failupd = raw_input("if update failed, press 1. otherwise, press ENTER key to continue. --> ")
  493.                if failupd == '1':
  494.                   obj.fastreboot("android")
  495.                   obj.push("XNPH30O/XNPH30O-update2-signed.zip", "/sdcard/XNPH30O-update2-signed.zip")
  496.                   time.sleep(2.5)
  497.                   print("\033[34mrebooting into recovery...\n\033[0m")
  498.                   obj.reboot("recovery")
  499.                   print("choose APPLY UPDATE from recovery menu and select APPLY FROM ADB.\n\n")
  500.                   raw_input("press ENTER to install the *second* XNPH30O OTA update now.")
  501.                   obj.sideload("XNPH30O/XNPH30O-update2-signed.zip")
  502.                   failside = raw_input("if update failed, press 1 to update from device storage. otherwise, press ENTER to continue. --> ")
  503.                   if failside == '1':
  504.                      print("choose APPLY UPDATE from recovery menu, then select CHOOSE FROM INTERNAL STORAGE.\n")
  505.                      print("select XNPH30O-update2-signed.zip from root of SDCARD directory and install file.\n\n")
  506.                      print("\033[35mif update fails again, return to main menu and reboot into custom recovery.\033[0m\n\n")
  507.                      menusel = raw_input("press 1 to return to flash menu, or 2 to return to main menu. --> ")
  508.                      while not re.search(r'^[12]$',menusel):
  509.                         menusel = raw_input("invalid selection. press 1 for flash menu, or 2 to return to main menu. --> ")
  510.                      if menusel == '1':
  511.                         time.sleep(0.9)
  512.                         flashmenu()
  513.                      elif menusel == '2':
  514.                         time.sleep(0.9)
  515.                         main()
  516.                      else:
  517.                         print("error connecting to device. returning to main menu...\n")
  518.                         time.sleep(0.9)
  519.                         main()
  520.                   else:
  521.                      obj.shell("rm -rf /sdcard/XNPH30O-update2-signed.zip")
  522.                      print("\033[32mreturning to flash menu..\033[0m\n\n")
  523.                      time.sleep(0.9)
  524.                      flashmenu()
  525.                else:
  526.                   print("\033[32mreturning to flash menu..\033[0m\n\n")
  527.                   time.sleep(0.9)
  528.                   flashmenu()
  529.                flashmenu()
  530.             elif flashsel == '0':
  531.                main()
  532.             else:
  533.                print("unable to connect to device.\n")
  534.              
  535.          def recovflash():
  536.             print("\n")
  537.             flashcont = raw_input("select 1 to continue flashing recovery. select 2 to flash a stock partition image. select 3 to return to flash menu. --> ")
  538.             while not re.search(r'^[123]$', flashcont):
  539.                flashcont = raw_input("invalid selection. select 1 to continue flashing recovery. select 2 to flash a stock partition image. select 3 to return to flash menu. --> ")
  540.             if flashcont == '1':
  541.                recovchoice = raw_input("enter 1 for TWRP, 2 for ClockworkMod, or 3 for Philz recovery --> ")
  542.                while not re.search(r'^[1-3]$', recovchoice):
  543.                   recovchoice = raw_input("invalid selection. please choose 1 for TWRP, 2 for CWM, or 3 for Philz --> ")
  544.                obj.reboot("bootloader")
  545.                if recovchoice == '1':
  546.                   obj.flashf("recovery","twrp.img")
  547.                elif recovchoice == '2':
  548.                   obj.flashf("recovery","cwm.img")
  549.                elif recovchoice == '3':
  550.                   obj.flashf("recovery","philz.img")
  551.                else:
  552.                   print("unable to connect to device.\n")
  553.                  
  554.             elif flashcont == '2':
  555.                flashmenu()  
  556.                                
  557.             elif flashcont == '3':
  558.                main()
  559.                
  560.             else:
  561.                print("unable to connect to device.\n")
  562.            
  563.             time.sleep(0.9)
  564.             flashmenu()
  565.                
  566.          print("\n\033[36mFlashing a CUSTOM RECOVERY requires an UNLOCKED BOOTLOADER.\033[0m\n")
  567.          print("\033[33m***UNLOCKING YOUR BOOTLOADER WILL WIPE YOUR DEVICE!!!***\033[0m\n")
  568.          print("\033[35mIF YOUR DEVICE HOLDS IMPORTANT DATA, BACK UP DEVICE BEFORE YOU CONTINUE!\033[0m\n")
  569.          print("\033[35mIMPORTANT: if you have already unlocked your device and are re-unlocking, you MUST be running the XNPH25R stock firmware or older.\n")
  570.          print("\033[32mif you are running XNPH30O or newer, YOUR RE-UNLOCK ATTEMPTS WILL FAIL. you must return to the previous menu and flash the XNPH25R images to your device.\033[0m\n")
  571.          bunlock = raw_input("enter 1 to continue unlocking bootloader. enter 2 to skip to flashing custom recovery or images.\n enter 3 to re-lock bootloader. or enter 4 to return to menu. --> ")
  572.          while not re.search(r'^[123]$', bunlock):
  573.             bunlock = raw_input("invalid selection. enter 1 to unlock bootloader and wipe device. enter 2 to skip to flashing custom recovery or images.\n enter 3 to re-lock bootloader. or enter 4 to return to menu. --> ")
  574.          
  575.          if bunlock == '1':
  576.             obj.reboot("bootloader")
  577.             obj.unlockboot()
  578.             print("your device should reboot after successfully unlocking the bootloader.\n")
  579.             raw_input("press ENTER to continue...")
  580.             recovflash()
  581.            
  582.          elif bunlock == '2':
  583.             recovflash()
  584.                    
  585.          elif bunlock == '3':
  586.             print("\033[33mREMINDER: to unlock your device again, you MUST downgrade to firmware release XNPH25R or earlier!\033[0m\n")
  587.             btlockconfirm = raw_input("press ENTER to continue, or 1 to exit to the previous menu --> ")
  588.             if btlockconfirm == '1':
  589.                flashmenu()
  590.             else:
  591.                obj.reboot("bootloader")
  592.                obj.lockboot()
  593.                raw_input("press ENTER to reboot your device")
  594.                obj.fastreboot("android")
  595.                
  596.          else:
  597.             flashmenu()
  598.                
  599.          time.sleep(0.9)
  600.          main()
  601.  
  602.       elif option == '9': #run shell command
  603.          shellcmd = raw_input("enter shell command --> ")
  604.          while shellcmd:
  605.             obj.shell(shellcmd)
  606.             shellcmd = raw_input("enter another shell command, or press ENTER to continue --> ")
  607.          time.sleep(0.9)
  608.          main()
  609.          
  610.       elif option == '0': #quit
  611.          sys.exit()
  612.                  
  613.       else:
  614.          print '\n\033[32man unhandled exception occurred. returning to main menu..\033[0m\n'
  615.          time.sleep(0.9)
  616.          main()    
  617.  
  618. main()
  619. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment