Skip to content

Instantly share code, notes, and snippets.

@jjrh
Last active June 23, 2019 08:50
Show Gist options
  • Select an option

  • Save jjrh/10000417 to your computer and use it in GitHub Desktop.

Select an option

Save jjrh/10000417 to your computer and use it in GitHub Desktop.
Pulls the pictures from my phone over adb, archives them into a directory, prompts to delete them off the phone.
#!/bin/bash
PATH=$PATH:/home/jjrh/temp/cyanogenmod_11/android-sdk-linux/platform-tools
ARCHIVE_DIR="/home/jjrh/toki_pictures/archives/"
backup ()
{
if [ $(adb shell ls -l $1 | wc -l) -gt 0 ]
then
d=$(date +%F)
mkdir $ARCHIVE_DIR/$d 2> /dev/null
adb pull $1 $ARCHIVE_DIR/$d
else
echo "directory is empty, doing nothing..."
exit
fi
}
remove_dir ()
{
echo ""
while true; do
read -p "Should I remove the contents of $1? [y/n]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
list=$(adb shell ls $1)
for f in `adb shell ls /sdcard/DCIM/Camera/`; do
c="/sdcard/DCIM/Camera/$f"
c=$(printf $c | tr -d '\r')
echo "removing $c"
adb shell rm $c
done
echo "done"
}
if [ $(adb devices | wc -l) -lt 3 ]
then
adb devices
echo "------------------------------------"
echo "uh is your phone plugged in?"
else
backup "/sdcard/DCIM/Camera/"
remove_dir "/sdcard/DCIM/Camera/"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment