Advertisement
ricod1996

autosync

Jan 15th, 2012
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.90 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-h\t\tView this help."
  37.     exit 0
  38. }
  39.  
  40. config () {
  41.     echo "Q: Where should I put the apps and their data?"
  42.     read path
  43.     echo "$path" > ~/autosync/.config
  44.     exit 0
  45. }
  46.  
  47. configrun () {
  48.     echo "Q: Where should I put the apps and their data?"
  49.     read path
  50.     echo "$path" > ~/autosync/.config
  51. }
  52. clear
  53. while getopts "crh" OPT
  54. do
  55.     case $OPT in
  56.         c)  config;;
  57.         r)  configrun;;
  58.         h)  scripthelp;;
  59.         *)  echo "$0: Wrong option!"
  60.             scripthelp;;
  61.     esac
  62. done
  63.  
  64. echo "I: Waiting for device to connect..."
  65. echo "I: Make soure USB-Debugging is enabled on your phone."
  66. adb devices >/dev/null 2>/dev/null
  67. while [ `adb devices|grep -c "device"` = "1" ]
  68. do
  69.     sleep 5
  70. done
  71.  
  72. if [ ! -f ~/autosync/.config ]
  73. then
  74. mkdir ~/autosync/ >/dev/null 2>/dev/null
  75. configrun
  76.     if [ ! -d $path ]
  77.     then
  78.         mkdir $path >/dev/null 2>/dev/null
  79.     fi
  80. fi
  81. echo "I: Starting the sync process..."
  82. echo "I: Please wait. This may take a while..."
  83.  
  84. path=`cat ~/autosync/.config|head -1`
  85.  
  86. date=`date +%d%m%y`
  87. data="${path}/${date}/data"
  88. app="${path}/${date}/app"
  89.  
  90. mkdir "${path}/${date}" >/dev/null 2>/dev/null
  91. mkdir "$data" >/dev/null 2>/dev/null
  92. mkdir "$app" >/dev/null 2>/dev/null
  93.  
  94. adb pull /data/data "$data" >/dev/null 2>/dev/null
  95. adb pull /data/app "$app" >/dev/null 2>/dev/null
  96.  
  97. echo "I: Done. Things are stored in ${path}/${date}."
  98. echo "I: If you want to synch again, start the script again."
  99. echo "I: Exiting now..."
  100. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement