#!/bin/bash
adb usb
sleep 5
mkdir android
cd android
a=`adb devices -l|grep "no perm"`
case "x$a" in
  "x")
    # ok
    ;;
  *)
    echo Please activate file transfer over USB and authorize if necessary
    exit
    ;;  
esac
a=`adb devices -l|grep -v "List of"`
case "x$a" in
  "x")
    echo Please connect device
    exit
    ;;  
esac
adb backup -noapk -noshared -all -f backup-file.adb
if [ ! -s backup-file.adb ] ; then
  echo backup aborted
  exit
fi
printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" > backup-file.tgz
#dd if=backup-file.adb bs=24 skip=1 >> backup-file.tgz # its too slow
tail -c +25 backup-file.adb >> backup-file.tgz
#tar -zxf backup-file.tgz
