Skip to content

Instantly share code, notes, and snippets.

@errordeveloper
Last active December 10, 2015 09:39
Show Gist options
  • Save errordeveloper/4416171 to your computer and use it in GitHub Desktop.
Save errordeveloper/4416171 to your computer and use it in GitHub Desktop.
#!/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"
@errordeveloper
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment