#!/bin/bash

# 2011-01-11    <miehl@w3hs.net>

# CALL       : {script name} <device MAC>
# DESCRIPTION: Quick and dirty hack to download pictures from a Sony Ericsson T610 via Bluetooth.

# TODO
# 1) Do the job without using a temporary file
# 2) Extract file names in a less complicated way

# MANUAL COMMANDS
# obexftp -b 00:0F:01:AB:CD:FF -l "Pictures"
# <determine file names>
# obexftp -b 00:0F:01:AB:CD:FF -g "Pictures/foobar.jpg"


#mac=$1
mac="00:0F:01:AB:CD:FF"

# create temp file
tempfile=$(mktemp /tmp/tfile.XXXXXXXXXX) || echo "Failed to create temp file"

# get list of stored pictures
obexftp -b ${mac} -l "Pictures" | sed -n -e /name/,/size/p | sed -e s/"<file name=\""// | awk '{print $1}' > ${tempfile}

# get files
while read line   
do   
    # remove " from the end of the picture name
    line=$(echo ${line%\"})
    # get pictures
    obexftp -b ${mac} -g "Pictures/${line}"
done <${tempfile}


##LPHOTODIR = "/home/"
#MPHOTODIR = "Pictures"
##MPHOTODIR = "Bilder"
#BDADDR = "00:0F:01:AB:CD:FF"
#
##cd ${LPHOTODIR}
#for f in $(bls -r ${BDADDR} ${MPHOTODIR} ); do
#  if [ ! -e "${f##*/}" ]; then
#    obexftp -b ${BDADDR} -g ${f}
#  fi
#done
##cd ~

