Advertisement
eudemonics

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

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