ricod1996

boot-sque

Jan 22nd, 2012
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.48 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #       This program is free software; you can redistribute it and/or modify
  4. #       it under the terms of the GNU General Public License as published by
  5. #       the Free Software Foundation; either version 2 of the License, or
  6. #       (at your option) any later version.
  7. #      
  8. #       This program is distributed in the hope that it will be useful,
  9. #       but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. #       GNU General Public License for more details.
  12. #      
  13. #       You should have received a copy of the GNU General Public License
  14. #       along with this program; if not, write to the Free Software
  15. #       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. #       MA 02110-1301, USA.
  17. #      
  18.  
  19. #Script for autmatically synchronize alls apps and their data
  20. #to a specified path on your computer.
  21. #When you plug in your device, the script will start to pull
  22. #all apps and their data to your computer.
  23. #When you haven't set the path where it should be saved, the script
  24. #will ask you to set the path.
  25. #Note: You'll need USB-Debugging enabled and the "adb"-command in your
  26. #path variable.
  27.  
  28. #You can put this script to your automatically starting apps and let
  29. #it run in terminal.
  30.  
  31. scripthelp () {
  32. echo "Usage: $0 [OPTION]"
  33. echo -e "Options: \n\tNo option\tRun the script"
  34. echo -e "\t-c\t\tSet new value for path."
  35. echo -e "\t-r\t\tSet new value for path, then run the script."
  36. echo -e "\t-s\t\tAlso sync apps under /system."
  37. echo -e "\t-p\t\tRestore apps and/or data. Please follow the instructions of the wizard carfully."
  38. echo -e "\t-h\t\tView this help."
  39. exit 0
  40. }
  41.  
  42. config () {
  43. echo "Q: Where should I put the apps and their data?"
  44. read path
  45. echo "$path" > ~/autosync/.config
  46. exit 0
  47. }
  48.  
  49. configrun () {
  50. echo "Q: Where should I put the apps and their data?"
  51. read path
  52. echo "$path" > ~/autosync/.config
  53. }
  54.  
  55. restoreapps () {
  56. path=`cat ~/autosync/.config|head -1`
  57. i=0
  58. for BACKUP in $(ls ${path}); do
  59.     if [ -d $BACKUP ]; then
  60.         let i++
  61.         ALLBACKUPS="$ALLBACKUPS $i $BACKUP"
  62.        
  63.     fi
  64. done
  65. COUNT=$(ls ${path}|wc -l)
  66. CURRENTBACKUP=$(dialog --stdout --menu "Select backup:" 0 0 ${COUNT}${ALLBACKUPS})
  67. dialog --clear
  68. clear
  69. i=0
  70. for APP in $(ls ${path}/$CURRENTBACKUP/data/); do
  71.         let i++
  72.         ALLAPPS="$ALLAPPS $i $APP off" 
  73. done
  74. COUNT=$(ls ${path}/$RESTOREBACKUP/data/|wc -l)
  75. RESTOREBOTH=$(dialog --stdout --checklist "Restore apps AND data:" 0 0 ${COUNT}${ALLAPPS})
  76. dialog --clear
  77. clear
  78. RESTOREAPP=$(dialog --stdout --checklist "Restore ONLY apps:" 0 0 ${COUNT}${ALLAPPS})
  79. dialog --clear
  80. clear
  81. RESTOREDATA=$(dialog --stdout --checklist "Restore ONLY data:" 0 0 ${COUNT}${ALLAPPS})
  82. dialog --clear
  83. clear
  84.  
  85. i=0
  86.  
  87. if [ "$RESTOREBOTH" ]; then
  88.     for CURRENTAPP in $(let i++ && echo "$RESTOREBOTH"|tr "\"" "\0"|cut -f${i}); do
  89.         echo "Restoring app and data for $CURRENTAPP"
  90.         if [ -f ${path}/app/${CURRENTAPP} ]; then
  91.             adb push ${path}/${CURRENTBACKUP}/app/${CURRENTAPP} /data/app > $null 2> $null
  92.         elif [ -f ${path}/systemapp/${CURRENTAPP} ]; then
  93.             adb push ${path}/${CURRENTBACKUP}/systemapp/${CURRENTAPP} /system/app > $null 2> $null
  94.         fi
  95.         adb push ${path}/${CURRENTBACKUP}/data/${CURRENTAPP}/ /data/data/ > $null 2> $null
  96.         echo "Restored $CURRENTAPP"
  97.     done
  98. fi
  99.  
  100. if [ "$RESTOREAPP" ]
  101. then
  102.     for CURRENTAPP in $(let i++ && echo "$RESTOREAPP"|tr "\"" "\0"|cut -f${i}); do
  103.         echo "Restoring app $CURRENTAPP"
  104.         if [ -f ${path}/app/${CURRENTAPP} ]; then
  105.             adb push ${path}/${CURRENTBACKUP}/app/${CURRENTAPP} /data/app > $null 2> $null
  106.         elif [ -f ${path}/systemapp/${CURRENTAPP} ]; then
  107.             adb push ${path}/${CURRENTBACKUP}/systemapp/${CURRENTAPP} /system/app > $null 2> $null
  108.         fi
  109.         echo "Restored $CURRENTAPP"
  110.     done
  111. fi
  112.  
  113. if [ "$RESTOREDATA" ]
  114. then
  115.     for CURRENTAPP in $(let i++ && echo "$RESTOREDATA"|tr "\"" "\0"|cut -f${i}); do
  116.         echo "Restoring data for $CURRENTAPP"
  117.         adb push ${path}/${CURRENTBACKUP}/data/${CURRENTAPP}/ /data/data/ > $null 2> $null
  118.         echo "Restored $CURRENTAPP"
  119.     done
  120. fi
  121. exit 0
  122. }
  123.  
  124. syncmusic () {
  125. }
  126.  
  127. syncvideos () {
  128. }
  129.  
  130. syncimgs () {
  131. }
  132.  
  133. main () {
  134.  
  135. echo "I: Starting the sync process..."
  136. echo "I: Please wait. This may take a while..."
  137.  
  138. path=`cat ~/autosync/.config|head -1`
  139.  
  140. date=`date +%d%m%y`
  141. data="${path}/${date}/data"
  142. app="${path}/${date}/app"
  143. systemapp="${path}/${date}/systemapp"
  144.  
  145. mkdir "${path}/${date}" >/dev/null 2>/dev/null
  146. mkdir "$data" >/dev/null 2>/dev/null
  147. mkdir "$app" >/dev/null 2>/dev/null
  148. mkdir "$systemapp" >/dev/null 2>/dev/null
  149.  
  150. adb pull /data/data "$data" >/dev/null 2>/dev/null
  151. adb pull /data/app "$app" >/dev/null 2>/dev/null
  152. if [ "$system"="1" ]; then
  153.     adb pull /system/app "$systemapp" >/dev/null 2>/dev/null
  154. fi
  155.  
  156. echo "I: Done. Things are stored in ${path}/${date}."
  157. echo "I: If you want to synch again, start the script again."
  158. echo "I: Exiting now..."
  159. exit 0
  160. }
  161.  
  162. echo "I: Waiting for device to connect..."
  163. echo "I: Make soure USB-Debugging is enabled on your phone."
  164.  
  165. adb devices >/dev/null 2>/dev/null
  166. while [ `adb devices|grep -c "device"` = "1" ]; do
  167.     sleep 5
  168. done
  169.  
  170. if [ ! -f ~/autosync/.config ]; then
  171. mkdir ~/autosync/ >/dev/null 2>/dev/null
  172. configrun
  173.     if [ ! -d $path ]; then
  174.         mkdir $path >/dev/null 2>/dev/null
  175.     fi
  176. fi
  177.  
  178. clear
  179. while getopts "crhspmvi" OPT; do
  180.     case $OPT in
  181.         c)  config;;
  182.         r)  configrun;;
  183.         h)  scripthelp;;
  184.         s)  system="1";;
  185.         p)  restoreapps;;
  186.         m)  syncmusic
  187.         v)  syncvideos
  188.         i)  syncimgs
  189.         *)  echo "Type $0 -h for help"; exit 1;;
  190.     esac
  191. done
Advertisement
Add Comment
Please, Sign In to add comment