Advertisement
jekarl

LATCH reg file

Nov 2nd, 2014
543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.56 KB | None | 0 0
  1. #!/bin/bash
  2. ####Check procps package, requirement to execute this script
  3. if  opkg list | grep procps > /dev/null
  4. then
  5.     echo 'Found procps'
  6. else
  7.     echo 'Updating package list...'
  8.     opkg update > /dev/null
  9.     echo 'Installing procps package...'
  10.     opkg install procps > /dev/null
  11. fi
  12. ####Check coreutils package, requirement to execute this script
  13. if  opkg list | grep coreutils-base64 > /dev/null
  14. then
  15.     echo 'Found coreutils-base64'
  16. else
  17.     echo 'Updating package list...'
  18.     opkg update > /dev/null
  19.     echo 'Installing coreutils-base64 package...'
  20.     opkg install coreutils-base64 > /dev/null
  21. fi
  22. ####Check wget package, requirement to execute this script
  23. if  opkg list | grep wget > /dev/null
  24. then
  25.     echo 'Found wget'
  26. else
  27.     echo 'Updating package list...'
  28.     opkg update > /dev/null
  29.     echo 'Installing wget...'
  30.     opkg install wget > /dev/null
  31. fi
  32. ####Check openssl-util package, requirement to execute this script
  33. if  opkg list | grep openssl-util > /dev/null
  34. then
  35.     echo 'Found openssl-util'
  36. else
  37.     echo 'Updating package list...'
  38.     opkg update > /dev/null
  39.     echo 'Installing openssl-util package...'
  40.     opkg install openssl-util > /dev/null
  41.  
  42. fi
  43. ####Check bash package, requirement to execute this script (please, check the version is not Shellshocked ;) )
  44. if  opkg list | grep bash > /dev/null
  45. then
  46.     echo 'Found bash'
  47. else
  48.     echo 'Updating package list...'
  49.     opkg update > /dev/null
  50.     echo 'Installing bash package...'
  51.     opkg install bash > /dev/null
  52. fi
  53. ####End packages check...
  54. if [ "$2" == "debug" ]; then set -x; fi
  55. applicationId="INSERT app ID HERE"
  56. secretkey="INSERT secret key HERE"
  57. URL="/api/0.6/pair/$1"
  58. LATCH="/root/home/latch.accounts"
  59. if [ -z "$1" ]; then
  60.  echo -e "\nUsage: SITE LATCH-REG <pair-key>\n"
  61.  exit 0
  62. fi
  63. if [ `grep "^$USER:" $LATCH | wc -l` -ne 0 ]; then
  64.  echo -e "\nAlready registered\n"
  65.  exit 0
  66. fi
  67. requestSignature+="GET\n"
  68. date=`date -u '+%Y-%m-%d %H:%M:%S'`
  69. requestSignature+="$date\n\n$URL"
  70. signed=`echo -en "$requestSignature" | openssl dgst -sha1 -hmac "$secretkey" -binary|sed -e 's|.*= \(.*\)|\1|g'`
  71. b64signed=`echo -n "$signed"|base64`
  72. auth_header="Authorization:11PATHS $applicationId $b64signed"
  73. date_header="X-11Paths-Date: $date"
  74. JSON=`wget -q --no-check-certificate -O - --header "$auth_header" --header "$date_header" "https://latch.elevenpaths.com$URL"`
  75. accountid=`echo "$JSON" | sed -e 's|.*accountId":"\(.*\)"}.*|\1|'| sed -e 's|\(.*\)".*|\1|g'`
  76.  
  77. if [ -z $accountid ]; then
  78.  echo "Error."
  79. else
  80.  echo "$USER:$accountid" >> $LATCH
  81.  echo -e "\nDone.\n"
  82. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement