本站源代码
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

74 lines
2.3KB

  1. #!/bin/bash
  2. set -eu
  3. client_configure() {
  4. sudo chmod 600 $PQSSLCERTTEST_PATH/postgresql.key
  5. }
  6. pgdg_repository() {
  7. local sourcelist='sources.list.d/postgresql.list'
  8. curl -sS 'https://www.postgresql.org/media/keys/ACCC4CF8.asc' | sudo apt-key add -
  9. echo deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main $PGVERSION | sudo tee "/etc/apt/$sourcelist"
  10. sudo apt-get -o Dir::Etc::sourcelist="$sourcelist" -o Dir::Etc::sourceparts='-' -o APT::Get::List-Cleanup='0' update
  11. }
  12. postgresql_configure() {
  13. sudo tee /etc/postgresql/$PGVERSION/main/pg_hba.conf > /dev/null <<-config
  14. local all all trust
  15. hostnossl all pqgossltest 127.0.0.1/32 reject
  16. hostnossl all pqgosslcert 127.0.0.1/32 reject
  17. hostssl all pqgossltest 127.0.0.1/32 trust
  18. hostssl all pqgosslcert 127.0.0.1/32 cert
  19. host all all 127.0.0.1/32 trust
  20. hostnossl all pqgossltest ::1/128 reject
  21. hostnossl all pqgosslcert ::1/128 reject
  22. hostssl all pqgossltest ::1/128 trust
  23. hostssl all pqgosslcert ::1/128 cert
  24. host all all ::1/128 trust
  25. config
  26. xargs sudo install -o postgres -g postgres -m 600 -t /var/lib/postgresql/$PGVERSION/main/ <<-certificates
  27. certs/root.crt
  28. certs/server.crt
  29. certs/server.key
  30. certificates
  31. sort -VCu <<-versions ||
  32. $PGVERSION
  33. 9.2
  34. versions
  35. sudo tee -a /etc/postgresql/$PGVERSION/main/postgresql.conf > /dev/null <<-config
  36. ssl_ca_file = 'root.crt'
  37. ssl_cert_file = 'server.crt'
  38. ssl_key_file = 'server.key'
  39. config
  40. echo 127.0.0.1 postgres | sudo tee -a /etc/hosts > /dev/null
  41. sudo service postgresql restart
  42. }
  43. postgresql_install() {
  44. xargs sudo apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confnew' install <<-packages
  45. postgresql-$PGVERSION
  46. postgresql-server-dev-$PGVERSION
  47. postgresql-contrib-$PGVERSION
  48. packages
  49. }
  50. postgresql_uninstall() {
  51. sudo service postgresql stop
  52. xargs sudo apt-get -y --purge remove <<-packages
  53. libpq-dev
  54. libpq5
  55. postgresql
  56. postgresql-client-common
  57. postgresql-common
  58. packages
  59. sudo rm -rf /var/lib/postgresql
  60. }
  61. $1
上海开阖软件有限公司 沪ICP备12045867号-1