package_cloud_wrapper.sh 1.7 KB

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