Advertisement
big_bum

Pushbullet

Nov 19th, 2013
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.91 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ ! -e "api_key" ]; then
  4.     echo "Please enter your API KEY:"
  5.     read API_KEY
  6.     echo $API_KEY > api_key
  7. else API_KEY=$(cat api_key)
  8. fi
  9.  
  10. curl -ss -u $API_KEY: https://api.pushbullet.com/api/devices > /tmp/devices
  11. MANUFACTURER=`grep manufacturer /tmp/devices | sed -e 's/".*://g' -e 's/"//g' | sed -e 's/,//g'`
  12. MODEL=`grep model /tmp/devices | sed -e 's/".*://g' -e 's/"//g' | sed -e 's/,//g'`
  13. ID=`grep "id" /tmp/devices | grep -v "android" | sed -e 's/".*://g' -e 's/"//g'`
  14. echo "Devices:"
  15.  
  16. echo $MANUFACTURER > /tmp/pars
  17. echo $MODEL >> /tmp/pars
  18. echo $ID >> /tmp/pars
  19. cat /tmp/pars | awk '{for (f = 1; f <= NF; f++) { a[NR, f] = $f } } NF > nf { nf = NF } END { for (f = 1; f <= nf; f++) { for (r = 1; r <= NR; r++) { printf a[r, f] (r==NR ? RS : FS) } } }' > /tmp/pars2
  20. OLD_IFS=$IFS
  21. IFS=$'\n'
  22. dev_arr=( $(cat /tmp/pars2) )
  23. IFS=$OLD_IFS
  24.  
  25. for i in $(seq 0 $((${#dev_arr[@]} - 1))); do
  26.     line="${dev_arr[$i]}"
  27.     echo "$i. ${line}"
  28. done
  29.  
  30. echo "Select device to which you want to send"
  31. read device
  32. _device_id=$(echo ${dev_arr[$device]} | awk '{ print $NF }')
  33.  
  34. echo "Select type of push (note/link/file)"
  35. read _type
  36.  
  37. if [ $_type == "note" ]; then
  38.     echo "Enter a title for the note":
  39.     read _title
  40.     echo "Enter the text then press [enter]"
  41.     read _body
  42.     curl -ss https://api.pushbullet.com/api/pushes -u $API_KEY: -d device_id=$_device_id -d type=$_type -d title=$_title -d body=$_body -X POST > /tmp/status
  43. elif [ $_type == "link" ]; then
  44.     echo "Enter the link:"
  45.     read _link
  46.     curl -ss https://api.pushbullet.com/api/pushes -u $API_KEY: -d device_id=$_device_id -d type=$_type -d url=$_link -X POST > /tmp/status
  47. elif [ $_type == "file" ]; then
  48.     echo "Enter the abolute path. The file must not exceed 25MB."
  49.     read _path
  50.     curl -i https://api.pushbullet.com/api/pushes -u $API_KEY: -F device_id=$_device_id -F type=$_type -F file=@$_path > /tmp/status
  51. fi
  52.  
  53. grep "created" /tmp/status 2&>1 > /dev/null
  54. if [ $? -eq 0 ]; then echo "Operation succeded!"
  55. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement