install.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. die() { echo "error: $@" 1>&2 ; exit 1; }
  3. # Getting operating system
  4. os=`uname -s`
  5. os=${os,,}
  6. # Getting architecture
  7. arch=`uname -m`
  8. case "$arch" in
  9. "armv7l")
  10. arch="arm"
  11. ;;
  12. "x86_64")
  13. arch="amd64"
  14. ;;
  15. esac
  16. release_url="https://api.github.com/repos/ncarlier/webhookd/releases/latest"
  17. artefact_url=`curl -s $release_url | grep browser_download_url | head -n 1 | cut -d '"' -f 4`
  18. [ -z "$artefact_url" ] && die "Unable to extract artefact URL"
  19. base_download_url=`dirname $artefact_url`
  20. download_url=$base_download_url/webhookd-$os-${arch}.tgz
  21. download_file=/tmp/webhookd-$os-${arch}.tgz
  22. bin_target=${1:-$HOME/.local/bin}
  23. echo "Downloading $download_url to $download_file ..."
  24. curl -o $download_file --fail -L $download_url
  25. [ $? != 0 ] && die "Unable to download binary for your architecture."
  26. echo "Extracting $download_file to $bin_target ..."
  27. [ -d $bin_target ] || mkdir -p $bin_target
  28. tar xvzf ${download_file} -C $bin_target
  29. [ $? != 0 ] && die "Unable to extract archive."
  30. echo "Cleaning..."
  31. rm $download_file \
  32. $bin_target/LICENSE \
  33. $bin_target/README.md \
  34. $bin_target/CHANGELOG.md
  35. [ $? != 0 ] && die "Unable to clean installation files."
  36. echo "Installation done. Type '$bin_target/webhookd' to start the server."