#!/bin/bash
if [ "$1" == "debug" ]; then set -x; fi
applicationId="9nwGgQXXXXXXXXXX"
secretkey="lsqXXXXXsJrdMcXXXXXXXXXXXXX"
LATCH="/ftp-data/latch.accounts"
account=`grep "^$USER:" $LATCH |cut -d: -f2`
URL="/api/0.6/unpair/$account"
if [ -z "$account" ]; then echo -e "Error."; exit 0; fi
requestSignature+="GET\\n"
date=`date -u \'+%Y-%m-%d %H:%M:%S\'`
requestSignature+="$date\\n\\n$URL"
signed=`echo -en "$requestSignature" | openssl dgst -sha1 -hmac "$secretkey" -binary|sed -e \'s|.*= \\(.*\\)|\\
1|g\'`
b64signed=`echo -n "$signed"|base64`
auth_header="Authorization:11PATHS $applicationId $b64signed"
date_header="X-11Paths-Date: $date"
JSON=`wget -q --no-check-certificate -O - --header "$auth_header" --header "$date_header" "https://latch.el
evenpaths.com$URL"`
grep -v "^$USER:" $LATCH > /tmp/$$.tmp
mv /tmp/$$.tmp $LATCH
echo -e "\\nDone.\\n"