daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Aug 19th, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/bash
  2.  
  3. ###TABLE OF CONTENTS#####
  4. ##  MAIN MENU - (MAIN00)
  5. ## FASTBOOT MENU - (FAST00)
  6. ##BACKUP - (BACKUP00)
  7. ##RESTORE - (RESTORE00)
  8. #FASTBOOT MENU (FAST00)
  9.  
  10. #Different options the user has in the bootloader
  11. #Displays the custom boot.img full path and custom recovery path
  12. function func_fastboot_menu () {
  13.     echo "Fastboot menu!"
  14.     echo "Kernel selected : $var_custom_kernel | Recovery Selected : $var_recovery_img"
  15.     echo "1: Select custom kernel!"
  16.     echo "2: Select custom recovery!"
  17.     echo "3: Boot custom kernel! (boot.img)"
  18.     echo "4: Boot custom recovery! (recovery.img)"
  19.     echo "5: Flash custom kernel! (boot.img)"
  20.     echo "6: Flash custom recovery! (recovery.img)"
  21.     echo "R: Reboot device into fastboot!"
  22.     echo "D: Show devices connected via fastboot!"
  23.     echo "M: Return to main menu!"
  24.    
  25.     read var_fastboot_option
  26.     case $var_fastboot_option in
  27.     #User selects location of the custom boot.img, script checks if it exists, and if so
  28.     # assigns it to the $var_custom_kernel variable
  29.         1) echo "Please select kernel location (boot.img)!"
  30.             read var_custom_kernel
  31.                 if [ -f $var_custom_kernel ]
  32.                 then
  33.                     echo "file exists!"
  34.                     echo "$var_custom_kernel selected!"
  35.                     func_fastboot_menu
  36.                 else
  37.                     echo "Invalid option!"
  38.                     echo "Please try again!"
  39.                     func_fastboot_menu
  40.                 fi;;
  41. #Same as above except with the recovery partition
  42.         2) echo "Please select recovery location! (recovery.img)"
  43.             read var_recovery_img
  44.                 if [ -f $var_recovery_img ]
  45.                 then
  46.                     echo "file exists!"
  47.                     echo "$var_recovery_img selected!"
  48.                     func_fastboot_menu
  49.                 else
  50.                     echo "Invalid option!"
  51.                     echo "Please try again!"
  52.                     func_fastboot_menu
  53.                 fi;;
  54. #Boots the custom boot.img before flashing it to the boot partition
  55.         3) echo "Booting custom kernel!"
  56.             fastboot boot $var_custom_kernel
  57.                 func_fastboot_menu;;
  58. #Same as 3 except /w the recovery partition
  59.         4) echo "Booting custom reccovery! | $var_recovery_img"
  60.             fastboot boot $var_recovery_img
  61.             func_fastboot_menu;;
  62. #Actually preforms the flash, checks if user is certain, and if user inputs yes
  63. # then preforms the flash of boot.img
  64.         5) echo "Are you sure you wish to flash $var_custom_kernel to device?"
  65.             echo "Type 'yes' to continue"
  66.                 read var_confirm
  67.                     if [ $var_confirm == yes ]
  68.                     then
  69.                         echo "Flashing $var_custom_kernel to device"
  70.                             fastboot flash boot $var_custom_kernel
  71.                         echo "boot.img flashed to device!"
  72.                             func_fastboot_menu
  73.                 else
  74.                     echo "Returning to menu"
  75.                     func_fastboot_menu
  76.                 fi;;
  77. #Same as 5 but with the recovery partition         
  78.         6) echo "Are you sure you wish to flash $var_recovery_img to device?"
  79.             echo "Type 'yes' to continue"
  80.             read var_confirm
  81.                 if [ $var_confirm == yes ]
  82.                 then
  83.                     echo "Flashing $var_recovery_img to device"
  84.                     fastboot flash recovery $var_recovery_img
  85.                     echo "$var_recovery_img flashed to device!"
  86.                     func_fastboot_menu
  87.                 else
  88.                     echo "Returning to menu"
  89.                     func_fastboot_menu
  90.                 fi;;
  91. #duhh          
  92.         D) echo "Displaying devices connected via fastboot!"
  93.             fastboot devices
  94.             func_fastboot_menu;;
  95.        
  96.         d) echo "Displaying devices connected via fastboot!"
  97.             fastboot devices
  98.             func_fastboot_menu;;
  99.        
  100.         R) echo "Rebooting device into bootloader!"
  101.             func_fastboot_reboot;;
  102.        
  103.         r) echo "Rebooting device into bootloader!"
  104.             func_fastboot_reboot;;
  105. #Returns to main menu but not before promopting the user on if they want to reboot
  106. #thus exiting fastboot
  107.         M) echo "Do you wish to restart device and return to ADB menu? (y/n)"
  108.             read var_reboot
  109.                 if [ $var_reboot == y ]
  110.                 then
  111.                     echo "Rebooting and returning to menu!"
  112.                     fastboot reboot
  113.                     func_menu
  114.                 else
  115.                     echo "Returning to main menu without reboot"
  116.                     func_menu
  117.                 fi;;
  118.             m) echo "Do you wish to restart device and return to ADB menu? (y/n)"
  119.                 read var_reboot
  120.                 if [ $var_reboot == y ]
  121.                 then
  122.                     echo "Rebooting and returning to menu!"
  123.                     fastboot reboot
  124.                     func_menu
  125.                 else
  126.                     echo "Returning to main menu without reboot"
  127.                     func_menu
  128.                 fi;;
  129.         esac
  130.        
  131.        
  132. }
  133. #function that reboots device into recovery thus enabling fastboot
  134. function func_fastboot_reboot () {
  135.     echo "Reboot device to bootloader? (Y/N)"
  136.         read var_reboot_fastboot
  137.             case $var_reboot_fastboot in
  138.        
  139.         Y) echo "Rebooting to bootloader!"
  140.             adb reboot bootloader
  141.             func_fastboot_menu;;
  142.            
  143.         y) echo "Rebooting to bootloader!"
  144.             adb reboot bootloader
  145.             func_fastboot_menu;;
  146.            
  147.         n) echo "Continuing to fastboot menu!"
  148.             func_fastboot_menu;;
  149.        
  150.         N) echo "Continuing to fastboot menu!"
  151.             func_fastboot_menu;;
  152.  
  153.         *) echo "Invalid input!"
  154.             func_fastboot_reboot;;
  155.  
  156.     esac
  157. }
  158.  
  159. #Asks user where the full system backup is stored, and if it exists, flashes it
  160. # to the device (RESTORE00)
  161. function func_full_restore () {
  162.     echo "Please select android backup to restore!"
  163.         read var_backup
  164.     echo "$var_backup chosen!"
  165.         if [ -f $var_backup ]
  166.         then
  167.             echo "$var_backup exists!"
  168.             echo "Continuing operation!"
  169.             adb restore $var_backup
  170.             echo "Done!"
  171.             func_menu
  172.         else
  173.             echo "File does not exist!"
  174.             echo "Please try again."
  175.             func_full_restore
  176.         fi
  177. }
  178.  
  179. #Prompts user for location and name of their full system backup then preforms it if user
  180. #inputs yes (BACKUP00)
  181. function func_fullbackup () {
  182.     echo "Starting backup!"
  183.     echo "Please select location to save backup!"
  184.         read fullbak_path
  185.     echo "$fullbak_path chosen!"
  186.     echo "Please select name of backup!"
  187.         read fullbak_name
  188.     echo "$fullbak_name chosen!"
  189.     echo "Confirm backup $fullbak_path/$fullbak_name (Y/N)"
  190.         read var_confirm
  191.         case $var_confirm in
  192.            
  193.             y) adb backup -apk -shared -all -f $fullbak_path/$fullbak_name.ab
  194.                 echo "Done!"
  195.                 func_menu;;
  196.                
  197.             Y) adb backup -apk -shared -all -f $fullbak_path/$fullbak_name.ab
  198.                 echo "Done!"
  199.                 func_menu;;
  200.                
  201.             n) echo "returning to menu!"
  202.                 func_menu;;
  203.            
  204.             N) echo "returning to menu!"
  205.                 func_menu;;
  206.             *) echo "Invalid input!";;
  207.         esac
  208. }
  209.  
  210. #BACKUP SPECIFIC APPLICATION!
  211.  
  212. function func_apk_backup () {
  213. echo "APK backup menu!"
  214. echo "Selected package: $var_apk_path | Destination path: $var_apkbak_location"
  215. echo "1: list APKs"
  216. echo "2: list APK path"
  217. echo "3: APK destination path"
  218. echo "4: Extract APK"
  219. echo "M: Main Menu"
  220.  
  221. read n
  222.     case $n in
  223.         1) echo "Listing APKs"
  224.             adb shell pm list packages
  225.             func_apk_backup;;
  226.         2) echo "Which APK path would you like to view?"
  227.             read var_apk_path
  228.             adb shell pm path $var_apk_path
  229.             func_apk_backup;;
  230.         3) echo "Please select location to save apk to"
  231.                 read var_apkbak_location
  232.                 echo "$var_apkbak_location selected as destination!"
  233.                 func_apk_backup;;
  234.        
  235.         4) echo "Pulling $var_apk_path to $var_apkbak_location"
  236.             adb pull $var_apk_path $var_apkbak_location
  237.             echo "Done, returning to menu!"
  238.             func_apk_backup;;
  239.         esac
  240.            
  241.                
  242.  
  243. }
  244.  
  245. #MAIN MENU (MAIN00)
  246. function func_menu () {
  247.  
  248. echo "Welcome to TJ's ADB backup helper!"
  249. echo "Please select an option!"
  250. echo "1: View connected devices"
  251. echo "2: Full system backup!"
  252. echo "3: Backup specfic application!"
  253. echo "4: Full system restore!"
  254. echo "5: Fastboot menu!"
  255. echo "Q: Quit!"
  256.  
  257. read n
  258.     case $n in
  259.    
  260.     1)  echo "Displaying devices!"
  261.         adb devices
  262.         func_menu;;
  263.    
  264.     2)  echo "Preforming full backup!"
  265.         func_fullbackup;;
  266.  
  267.     3) echo "Specific apk backup selected!"
  268.         func_apk_backup;;
  269.        
  270.     4) echo "System restore chosen!"
  271.         func_full_restore;;
  272.        
  273.     5) echo "Fastboot menu chosen!"
  274.         func_fastboot_reboot;;
  275.    
  276.     q) echo "quitting!"
  277.         exit;;
  278.    
  279.     Q) echo "quitting!"
  280.         exit;;
  281.     esac
  282. }
  283.  
  284. func_menu
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top