Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- self="${0##*/}"
- dev_mac=
- dev_channel=
- service="OPUSH"
- service_readable="OBEX Object Push"
- wait_at_end=
- find_all()
- {
- service=${1:-$service}
- data="$(sdptool search $service)"
- IFS='
- '
- dev_mac=
- for line in $data; do
- if echo "$line" | grep -Ei "^Searching for $service" >/dev/null; then
- dev_mac=`echo $line | grep -Eio "([0-9a-f]{2}:){5}[0-9a-f]{2}"`
- dev_channel=
- fi
- if [ -n "$dev_mac" ]; then
- if echo "$line" | grep -E "^[[:space:]]*Channel:" >/dev/null; then
- dev_channel=`echo $line | grep -Eio "\b[0-9]+\$"`
- fi
- fi
- if [ -n "$dev_mac" -a -n "$dev_channel" ]; then
- echo "[$dev_mac]:$dev_channel"
- dev_mac=
- fi
- done
- }
- while [ -n "$1" ]; do
- case "$1" in
- -h|--help) echo "Options:
- -m MAC address of BT device (omit to search)
- -c channel of service (omit to autodetect)
- -f search for devices
- -w wait on complete"
- exit;;
- -m) shift; dev_mac="$1";;
- -c) shift; dev_channel="$1";;
- -f) find_all; exit;;
- -w) wait_at_end=1;;
- --) shift; break;;
- -*) false; shift;;
- *) break;;
- esac
- shift
- done
- if [ -z "$dev_mac" ]; then
- s=`find /var/lib/bluetooth -mindepth 2 -maxdepth 2 -name lastused -print -quit`
- if [ -n "$s" ]
- then
- echo "Known devices:" >&2
- join <(sort /var/lib/bluetooth/*/lastused) <(sort /var/lib/bluetooth/*/names)
- else
- echo "There is not any known device." >&2
- fi
- echo
- echo "Scanning devices..." >&2
- oldIFS=$IFS
- IFS=$'\n'
- oldCOLUMNS=$COLUMNS
- COLUMNS=1
- scan="$(hcitool scan | sed -e 1d)"
- # scandb=$(echo "$scan" | sed -n \$=) # [ "0$REPLY" -ge 1 -a "0$REPLY" -le $scandb ]
- # dev_names=$(echo "$scan" | sed -e 's/^\s\+\S\+\s\+//g')
- select mac_and_name in $scan
- do
- if [ -n "$mac_and_name" ]; then
- dev_mac=`echo "$mac_and_name" | grep -Eiom1 "([0-9a-f]{2}:){5}[0-9a-f]{2}"`
- break
- fi
- done
- IFS=$oldIFS
- COLUMNS=$oldCOLUMNS
- fi
- if [ -z "$dev_channel" -a -n "$dev_mac" ]; then
- echo -n "Detect channel... " >&2
- dev_channel=`sdptool browse $dev_mac | awk "/$service_readable/,/^\$/" | grep -Em1 "Channel" | grep -Eio "\b[0-9]+\$"`
- echo $dev_channel
- fi
- while [ -n "$1" -a -n "$dev_mac" -a -n "$dev_channel" ]; do
- if [ "${1// /}" != "${1}" ]; then
- echo "$self: spaces in filename not allowed" >&2
- exit 1
- fi
- path="$1"
- fname="${1##*/}"
- printf "c\np $path $fname\nd\nq\n" | obex_test -b $dev_mac $dev_channel
- # | awk '{if(/^Made some progress/){printf "!"}else{print}}'
- # PUT failed 0x43! --> megszakította
- # PUT failed 0x60! --> nincs elég hely
- shift
- done
- # [ -n "$DISPLAY" ] && xmessage
- test "$wait_at_end" = 1 && read -s -p "Terminated. Press Enter. "
- exit
Advertisement
Add Comment
Please, Sign In to add comment