Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ ! -e "api_key" ]; then
- echo "Please enter your API KEY:"
- read API_KEY
- echo $API_KEY > api_key
- else API_KEY=$(cat api_key)
- fi
- curl -ss -u $API_KEY: https://api.pushbullet.com/api/devices > /tmp/devices
- MANUFACTURER=`grep manufacturer /tmp/devices | sed -e 's/".*://g' -e 's/"//g' | sed -e 's/,//g'`
- MODEL=`grep model /tmp/devices | sed -e 's/".*://g' -e 's/"//g' | sed -e 's/,//g'`
- ID=`grep "id" /tmp/devices | grep -v "android" | sed -e 's/".*://g' -e 's/"//g'`
- echo "Devices:"
- echo $MANUFACTURER > /tmp/pars
- echo $MODEL >> /tmp/pars
- echo $ID >> /tmp/pars
- 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
- OLD_IFS=$IFS
- IFS=$'\n'
- dev_arr=( $(cat /tmp/pars2) )
- IFS=$OLD_IFS
- for i in $(seq 0 $((${#dev_arr[@]} - 1))); do
- line="${dev_arr[$i]}"
- echo "$i. ${line}"
- done
- echo "Select device to which you want to send"
- read device
- _device_id=$(echo ${dev_arr[$device]} | awk '{ print $NF }')
- echo "Select type of push (note/link/file)"
- read _type
- if [ $_type == "note" ]; then
- echo "Enter a title for the note":
- read _title
- echo "Enter the text then press [enter]"
- read _body
- 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
- elif [ $_type == "link" ]; then
- echo "Enter the link:"
- read _link
- 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
- elif [ $_type == "file" ]; then
- echo "Enter the abolute path. The file must not exceed 25MB."
- read _path
- curl -i https://api.pushbullet.com/api/pushes -u $API_KEY: -F device_id=$_device_id -F type=$_type -F file=@$_path > /tmp/status
- fi
- grep "created" /tmp/status 2&>1 > /dev/null
- if [ $? -eq 0 ]; then echo "Operation succeded!"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement