Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ####Check procps package, requirement to execute this script
- if opkg list | grep procps > /dev/null
- then
- echo 'Found procps'
- else
- echo 'Updating package list...'
- opkg update > /dev/null
- echo 'Installing procps package...'
- opkg install procps > /dev/null
- fi
- ####Check coreutils package, requirement to execute this script
- if opkg list | grep coreutils-base64 > /dev/null
- then
- echo 'Found coreutils-base64'
- else
- echo 'Updating package list...'
- opkg update > /dev/null
- echo 'Installing coreutils-base64 package...'
- opkg install coreutils-base64 > /dev/null
- fi
- ####Check wget package, requirement to execute this script
- if opkg list | grep wget > /dev/null
- then
- echo 'Found wget'
- else
- echo 'Updating package list...'
- opkg update > /dev/null
- echo 'Installing wget...'
- opkg install wget > /dev/null
- fi
- ####Check openssl-util package, requirement to execute this script
- if opkg list | grep openssl-util > /dev/null
- then
- echo 'Found openssl-util'
- else
- echo 'Updating package list...'
- opkg update > /dev/null
- echo 'Installing openssl-util package...'
- opkg install openssl-util > /dev/null
- fi
- ####Check bash package, requirement to execute this script (please, check the version is not Shellshocked ;) )
- if opkg list | grep bash > /dev/null
- then
- echo 'Found bash'
- else
- echo 'Updating package list...'
- opkg update > /dev/null
- echo 'Installing bash package...'
- opkg install bash > /dev/null
- fi
- ####End packages check...
- if [ "$2" == "debug" ]; then set -x; fi
- applicationId="INSERT app ID HERE"
- secretkey="INSERT secret key HERE"
- URL="/api/0.6/pair/$1"
- LATCH="/root/home/latch.accounts"
- if [ -z "$1" ]; then
- echo -e "\nUsage: SITE LATCH-REG <pair-key>\n"
- exit 0
- fi
- if [ `grep "^$USER:" $LATCH | wc -l` -ne 0 ]; then
- echo -e "\nAlready registered\n"
- 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.elevenpaths.com$URL"`
- accountid=`echo "$JSON" | sed -e 's|.*accountId":"\(.*\)"}.*|\1|'| sed -e 's|\(.*\)".*|\1|g'`
- if [ -z $accountid ]; then
- echo "Error."
- else
- echo "$USER:$accountid" >> $LATCH
- echo -e "\nDone.\n"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement