runner-lib 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #! /bin/bash
  2. #
  3. # © 2017 Ansgar Burchardt <ansgar@debian.org>
  4. # License: GPL-2+
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. # find-postgresql-version: () -> str
  19. # locate postgresql version for which both server and debversion
  20. # extension are installed. exits with error if no version is found.
  21. # returns: version, e.g. "9.6"
  22. find-postgresql-version() {
  23. local status
  24. for v in 15 14 13 12 11 10 9.6 9.4; do
  25. status=$(dpkg-query \
  26. -f'${db:Status-Status} ' \
  27. -W postgresql-${v} postgresql-${v}-debversion 2>/dev/null || :)
  28. if [ "${status}" = "installed installed " ]; then
  29. echo ${v}
  30. exit 0
  31. fi
  32. done
  33. echo "No PostgreSQL version with server and debversion extension found." >&2
  34. exit 1
  35. }
  36. pgversion=$(find-postgresql-version)
  37. export DAK_INTEGRATION_TEST=1
  38. if [ "${DAK_ROOT+x}" = "" ]
  39. then
  40. export DAK_ROOT="$(cd $(dirname "${BASH_SOURCE}")/..; pwd)"
  41. fi
  42. # run-script-with-pg: (cmd, args...) -> ''
  43. # Run the given cmd (with optional arguments) with a postgres
  44. # virtual environment running.
  45. run-script-with-pg() {
  46. pg_virtualenv -v "${pgversion}" "$@"
  47. }