package_cloud_wrapper.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env bash
  2. #
  3. # This is a tool to help removal of packages from packagecloud.io
  4. # It utilizes the package_cloud utility provided from packagecloud.io
  5. #
  6. # Depends on:
  7. # 1) package cloud gem (detects absence and installs it)
  8. #
  9. # Requires:
  10. # 1) PKG_CLOUD_TOKEN variable exported
  11. # 2) To properly install package_cloud when not found, it requires: ruby gcc gcc-c++ ruby-devel
  12. #
  13. # Copyright: SPDX-License-Identifier: GPL-3.0-or-later
  14. #
  15. # Author : Pavlos Emm. Katsoulakis (paul@netdata.cloud)
  16. #shellcheck disable=SC2068,SC2145
  17. set -e
  18. PKG_CLOUD_CONFIG="$HOME/.package_cloud_configuration.cfg"
  19. # If we are not in netdata git repo, at the top level directory, fail
  20. TOP_LEVEL=$(basename "$(git rev-parse --show-toplevel)")
  21. CWD=$(git rev-parse --show-cdup)
  22. if [ -n "$CWD" ] || [ ! "${TOP_LEVEL}" == "netdata" ]; then
  23. echo "Run as .github/scripts/$(basename "$0") from top level directory of netdata git repository"
  24. echo "Docker build process aborted"
  25. exit 1
  26. fi
  27. # Install dependency if not there
  28. if ! command -v package_cloud > /dev/null 2>&1; then
  29. echo "No package cloud gem found, installing"
  30. sudo gem install -V package_cloud || (echo "Package cloud installation failed. you might want to check if required dependencies are there (ruby gcc gcc-c++ ruby-devel)" && exit 1)
  31. else
  32. echo "Found package_cloud gem, continuing"
  33. fi
  34. # Check for required token and prepare config
  35. if [ -z "${PKG_CLOUD_TOKEN}" ]; then
  36. echo "Please set PKG_CLOUD_TOKEN to be able to use ${0}"
  37. exit 1
  38. fi
  39. echo "{\"url\":\"https://packagecloud.io\",\"token\":\"${PKG_CLOUD_TOKEN}\"}" > "${PKG_CLOUD_CONFIG}"
  40. echo "Executing package_cloud with config ${PKG_CLOUD_CONFIG} and parameters $@"
  41. package_cloud $@ --config="${PKG_CLOUD_CONFIG}"
  42. rm -rf "${PKG_CLOUD_CONFIG}"
  43. echo "Done!"