database.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright (C) 2017 [email protected]
  2. # Copyright (C) 2008 1&1 Internet AG
  3. #
  4. # This file is part of kamailio, a free SIP server.
  5. #
  6. # kamailio 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. # kamailio 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, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. . include/common
  20. KAMUSER="kamailio"
  21. MYSQL="mysql kamailio --show-warnings --batch --user="${KAMUSER}" --password=kamailiorw -e"
  22. export PGPASSWORD="kamailiorw"
  23. PSQL="psql -A -t -n -q -h localhost -U kamailio kamailio -c"
  24. ISQL="isql -b -v -d0x0 kamailio kamailio kamailiorw"
  25. check_mysql() {
  26. $MYSQL "select * from location;" > /dev/null
  27. if ! [ "$?" -eq 0 ] ; then
  28. echo "can't read from database"
  29. return 1
  30. fi;
  31. $MYSQL "insert into location (user_agent) values ('___test___');" > /dev/null
  32. if ! [ "$?" -eq 0 ] ; then
  33. echo "can't write to database"
  34. return 1
  35. fi;
  36. $MYSQL "delete from location where user_agent ='___test___';" > /dev/null
  37. return 0
  38. }
  39. check_postgres() {
  40. $PSQL "select * from location;" > /dev/null
  41. if ! [ "$?" -eq 0 ] ; then
  42. echo "can't read from database"
  43. return 1
  44. fi;
  45. $PSQL "insert into location (user_agent) values ('___test___');" > /dev/null
  46. if ! [ "$?" -eq 0 ] ; then
  47. echo "can't write to database"
  48. return 1
  49. fi;
  50. $PSQL "delete from location where user_agent ='___test___';" > /dev/null
  51. return 0
  52. }
  53. check_unixodbc() {
  54. echo "select * from location;" | $ISQL > /dev/null
  55. if ! [ "$?" -eq 0 ] ; then
  56. echo "can't read from database"
  57. return 1
  58. fi;
  59. echo "insert into location (id, user_agent) values ('$RANDOM', '___test___');" | $ISQL > /dev/null
  60. if ! [ "$?" -eq 0 ] ; then
  61. echo "can't write to database"
  62. return 1
  63. fi;
  64. echo "delete from location where user_agent ='___test___';" | $ISQL > /dev/null
  65. return 0
  66. }