forked from ritiek/one-liner-SSH-to-Raspberry-Pi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsshpi.sh
22 lines (18 loc) · 933 Bytes
/
sshpi.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
# -------------------------------------------------------------
# replace the below with your weaved username & password
EMAIL="weaved_email"
PASS="weaved_pass"
PI_UID="raspberry_UID"
# -------------------------------------------------------------
TOKEN="$(curl -sS -X GET -H "content-type:application/json" -H "apikey:WeavedDemoKey\$2015" https://api.weaved.com/v22/api/user/login/$EMAIL/$PASS | cut -d'"' -f 8)"
HOST_IP="$(curl -sS -X GET ipinfo.io/ip/)"
HTTP_HOST="$(curl -sS -X POST -H "content-type:application/json" -H "apikey:WeavedDemoKey\$2015" -H "token:$TOKEN" --data '{"deviceaddress":"'$PI_UID'", "hostip":"$HOST_IP","wait":"true"}' https://api.weaved.com/v22/api/device/connect | cut -d'"' -f 22 | tr -d '\\')"
HTTP_HOST=${HTTP_HOST#"http://"}
HOST=$(echo $HTTP_HOST | cut -d':' -f 1)
PORT=$(echo $HTTP_HOST | cut -d':' -f 2)
if [ "$#" -ne 1 ]; then
echo $HOST:$PORT
else
echo $HOST -p $PORT
fi