Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- # MA 02110-1301, USA.
- #
- #Script for autmatically synchronize alls apps and their data
- #to a specified path on your computer.
- #When you plug in your device, the script will start to pull
- #all apps and their data to your computer.
- #When you haven't set the path where it should be saved, the script
- #will ask you to set the path.
- #Note: You'll need USB-Debugging enabled and the "adb"-command in your
- #path variable.
- #You can put this script to your automatically starting apps and let
- #it run in terminal.
- scripthelp () {
- echo "Usage: $0 [OPTION]"
- echo -e "Options: \n\tNo option\tRun the script"
- echo -e "\t-c\t\tSet new value for path."
- echo -e "\t-r\t\tSet new value for path, then run the script."
- echo -e "\t-s\t\tAlso sync apps under /system."
- echo -e "\t-p\t\tRestore apps and/or data. Please follow the instructions of the wizard carfully."
- echo -e "\t-h\t\tView this help."
- exit 0
- }
- config () {
- echo "Q: Where should I put the apps and their data?"
- read path
- echo "$path" > ~/autosync/.config
- exit 0
- }
- configrun () {
- echo "Q: Where should I put the apps and their data?"
- read path
- echo "$path" > ~/autosync/.config
- }
- restoreapps () {
- path=`cat ~/autosync/.config|head -1`
- i=0
- for BACKUP in $(ls ${path}); do
- if [ -d $BACKUP ]; then
- let i++
- ALLBACKUPS="$ALLBACKUPS $i $BACKUP"
- fi
- done
- COUNT=$(ls ${path}|wc -l)
- CURRENTBACKUP=$(dialog --stdout --menu "Select backup:" 0 0 ${COUNT}${ALLBACKUPS})
- dialog --clear
- clear
- i=0
- for APP in $(ls ${path}/$CURRENTBACKUP/data/); do
- let i++
- ALLAPPS="$ALLAPPS $i $APP off"
- done
- COUNT=$(ls ${path}/$RESTOREBACKUP/data/|wc -l)
- RESTOREBOTH=$(dialog --stdout --checklist "Restore apps AND data:" 0 0 ${COUNT}${ALLAPPS})
- dialog --clear
- clear
- RESTOREAPP=$(dialog --stdout --checklist "Restore ONLY apps:" 0 0 ${COUNT}${ALLAPPS})
- dialog --clear
- clear
- RESTOREDATA=$(dialog --stdout --checklist "Restore ONLY data:" 0 0 ${COUNT}${ALLAPPS})
- dialog --clear
- clear
- i=0
- if [ "$RESTOREBOTH" ]; then
- for CURRENTAPP in $(let i++ && echo "$RESTOREBOTH"|tr "\"" "\0"|cut -f${i}); do
- echo "Restoring app and data for $CURRENTAPP"
- if [ -f ${path}/app/${CURRENTAPP} ]; then
- adb push ${path}/${CURRENTBACKUP}/app/${CURRENTAPP} /data/app > $null 2> $null
- elif [ -f ${path}/systemapp/${CURRENTAPP} ]; then
- adb push ${path}/${CURRENTBACKUP}/systemapp/${CURRENTAPP} /system/app > $null 2> $null
- fi
- adb push ${path}/${CURRENTBACKUP}/data/${CURRENTAPP}/ /data/data/ > $null 2> $null
- echo "Restored $CURRENTAPP"
- done
- fi
- if [ "$RESTOREAPP" ]
- then
- for CURRENTAPP in $(let i++ && echo "$RESTOREAPP"|tr "\"" "\0"|cut -f${i}); do
- echo "Restoring app $CURRENTAPP"
- if [ -f ${path}/app/${CURRENTAPP} ]; then
- adb push ${path}/${CURRENTBACKUP}/app/${CURRENTAPP} /data/app > $null 2> $null
- elif [ -f ${path}/systemapp/${CURRENTAPP} ]; then
- adb push ${path}/${CURRENTBACKUP}/systemapp/${CURRENTAPP} /system/app > $null 2> $null
- fi
- echo "Restored $CURRENTAPP"
- done
- fi
- if [ "$RESTOREDATA" ]
- then
- for CURRENTAPP in $(let i++ && echo "$RESTOREDATA"|tr "\"" "\0"|cut -f${i}); do
- echo "Restoring data for $CURRENTAPP"
- adb push ${path}/${CURRENTBACKUP}/data/${CURRENTAPP}/ /data/data/ > $null 2> $null
- echo "Restored $CURRENTAPP"
- done
- fi
- exit 0
- }
- syncmusic () {
- }
- syncvideos () {
- }
- syncimgs () {
- }
- main () {
- echo "I: Starting the sync process..."
- echo "I: Please wait. This may take a while..."
- path=`cat ~/autosync/.config|head -1`
- date=`date +%d%m%y`
- data="${path}/${date}/data"
- app="${path}/${date}/app"
- systemapp="${path}/${date}/systemapp"
- mkdir "${path}/${date}" >/dev/null 2>/dev/null
- mkdir "$data" >/dev/null 2>/dev/null
- mkdir "$app" >/dev/null 2>/dev/null
- mkdir "$systemapp" >/dev/null 2>/dev/null
- adb pull /data/data "$data" >/dev/null 2>/dev/null
- adb pull /data/app "$app" >/dev/null 2>/dev/null
- if [ "$system"="1" ]; then
- adb pull /system/app "$systemapp" >/dev/null 2>/dev/null
- fi
- echo "I: Done. Things are stored in ${path}/${date}."
- echo "I: If you want to synch again, start the script again."
- echo "I: Exiting now..."
- exit 0
- }
- echo "I: Waiting for device to connect..."
- echo "I: Make soure USB-Debugging is enabled on your phone."
- adb devices >/dev/null 2>/dev/null
- while [ `adb devices|grep -c "device"` = "1" ]; do
- sleep 5
- done
- if [ ! -f ~/autosync/.config ]; then
- mkdir ~/autosync/ >/dev/null 2>/dev/null
- configrun
- if [ ! -d $path ]; then
- mkdir $path >/dev/null 2>/dev/null
- fi
- fi
- clear
- while getopts "crhspmvi" OPT; do
- case $OPT in
- c) config;;
- r) configrun;;
- h) scripthelp;;
- s) system="1";;
- p) restoreapps;;
- m) syncmusic
- v) syncvideos
- i) syncimgs
- *) echo "Type $0 -h for help"; exit 1;;
- esac
- done
Advertisement
Add Comment
Please, Sign In to add comment