3.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. # creates a mysql database with kamailiodbctl and deletes it again
  3. # Copyright (C) 2007 1&1 Internet AG
  4. #
  5. # This file is part of Kamailio, a free SIP server.
  6. #
  7. # Kamailio is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version
  11. #
  12. # Kamailio is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. # Needs a mysql database, the root user password must be assigned to
  21. # the 'PW' variable in the file 'dbrootpw' in the test directory, e.g.:
  22. # PW=sql_root_passwd
  23. # If MySQL root password is empty, add in the file the line:
  24. # PWSKIP=yes
  25. . include/common
  26. if [ ! -f dbrootpw ] ; then
  27. echo "no root password, not run"
  28. exit 0
  29. fi ;
  30. . dbrootpw
  31. tmp_name=""$RANDOM"_kamailiodb_tmp"
  32. cd $CTL_DIR
  33. # setup config file
  34. cp $CTLRC $CTLRC.bak
  35. sed -i '' -e "s/# DBENGINE=MYSQL/DBENGINE=MYSQL/g" $CTLRC
  36. sed -i '' -e "s/# INSTALL_EXTRA_TABLES=ask/INSTALL_EXTRA_TABLES=yes/g" $CTLRC
  37. sed -i '' -e "s/# INSTALL_PRESENCE_TABLES=ask/INSTALL_PRESENCE_TABLES=yes/g" $CTLRC
  38. sed -i '' -e "s/# INSTALL_DBUID_TABLES=ask/INSTALL_DBUID_TABLES=yes/g" $CTLRC
  39. cp $DBCTL $DBCTL.bak
  40. sed -i '' -e "s/TEST=\"false\"/TEST=\"true\"/g" $DBCTL
  41. # set the mysql root password
  42. cp $DBCTL.mysql $DBCTL.mysql.bak
  43. sed -i '' -e "s/#PW=\"\"/PW=\"$PW\"/g" $DBCTL.mysql
  44. PWSKIP="$PWSKIP" CHARSET="latin1" ./$DBCTL create $tmp_name > /dev/null
  45. ret=$?
  46. if [ "$ret" -eq 0 ] ; then
  47. PWSKIP="$PWSKIP" ./$DBCTL drop $tmp_name > /dev/null
  48. ret=$?
  49. fi ;
  50. # cleanup
  51. mv $CTLRC.bak $CTLRC
  52. mv $DBCTL.mysql.bak $DBCTL.mysql
  53. mv $DBCTL.bak $DBCTL
  54. exit $ret