Last active
December 10, 2015 09:39
-
-
Save errordeveloper/4416171 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -xe | |
if [ -z $1 ] | |
then | |
echo "Usage: $0 <product_secret> [<iface>]" | |
exit -1 | |
fi | |
if [ -z $2 ] | |
then | |
# get default network interface | |
iface=`/usr/sbin/netstat -rn | /usr/bin/awk '/^default/{print $6;exit}'` | |
else | |
iface=$2 | |
fi | |
# get MAC address | |
serial=`/sbin/ifconfig $iface | /usr/bin/awk '/ether/{print $2;exit}'` | |
# the secret needs to be treated as binary data, not a string | |
# this can be done with `ehco -e` in Bash, but not in plain Bourne shell | |
secret=$(echo -ne "$(/usr/bin/sed 's/.\{2\}/\\x&/g' <<< $1)") | |
result=$(/usr/bin/openssl sha1 -binary -hex -hmac "${secret}" <<< "${serial}") | |
curl -v "https://api.xively.com/v2/devices/${result}/activate.csv" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
...some OpenSSL alternatives: