summaryrefslogtreecommitdiff
path: root/utils/devel/chart-load-test.sh
blob: bfac7c85b7ffdf07f77e27de890aec4b71b1dcc6 (plain)
  1. #!/bin/bash
  2. #
  3. # chart-load-test.sh [SQLDIR] [CHARTFILE]
  4. #
  5. # Attempts to load the charts and associated GIFI sets. Expected output is
  6. # discarded. Normally run from the top-level LSMB directory to check charts in
  7. # the directory 'sql', a chart directory or file can be given. When passed a
  8. # directory name, it checks all charts in that directory provided that a copy
  9. # of Pg-database.sql is present.
  10. #
  11. # This test script requires that plpgsql have been loaded to template1 and that
  12. # the running user has the ability to create and drop databases. Additionally,
  13. # this copy of chart-load-test.sh will not work with LedgerSMB < 1.3.
  14. #
  15. #######################################################################
  16. # Copyright 2007, The LedgerSMB Core Team
  17. #
  18. # This program is free software; you can redistribute it and/or modify
  19. # it under the terms of the GNU General Public License as published by
  20. # the Free Software Foundation; either version 2 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU General Public License for more details.
  27. # You should have received a copy of the GNU General Public License
  28. # along with this program; if not, write to the Free Software
  29. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  30. #
  31. #######################################################################
  32. sqldir="${1:-sql}"
  33. chart="$2"
  34. db="charttest$$"
  35. # Adjust before using
  36. tsearch="/opt/pgsql813-ppc/share/contrib/tsearch2.sql"
  37. tablefunc="/opt/pgsql813-ppc/share/contrib/tablefunc.sql"
  38. if [ -f "$sqldir" ] ; then
  39. chart=`basename $sqldir`
  40. chartdir=`dirname $sqldir`
  41. sqldir="${chartdir/%\/*\/*\/*/}"
  42. else
  43. chartdir="$sqldir"
  44. fi
  45. if [ ! -d "$sqldir" ] ; then
  46. echo "chart-load-test.sh: Directory '$sqldir' cannot be accessed" 1>&2
  47. exit 1
  48. elif [ ! -f "${sqldir}/Pg-database.sql" ] ; then
  49. echo "chart-load-test.sh: Directory '$sqldir' does not contain Pg-database.sql" 1>&2
  50. elif [ "$chart" -a ! -f "${chartdir}/$chart" ] ; then
  51. echo "chart-load-test.sh: Chart '$chart' cannot be accessed" 1>&2
  52. exit 1
  53. fi
  54. chartdir=${chartdir/#$sqldir/}
  55. chartdir=${chartdir/#\//}
  56. pushd $sqldir > /dev/null
  57. ( for i in `find "${chartdir:-.}" -name "${chart:-*.sql}" -path '*/chart/*' -print`; do
  58. createdb $db
  59. psql -f $tablefunc $db > /dev/null
  60. psql -f $tsearch $db > /dev/null
  61. psql -f Pg-database.sql $db > /dev/null
  62. sleep 3
  63. psql -f "$i" $db > /dev/null
  64. j="${i/chart/gifi}"
  65. if [ -x "$j" ] ; then
  66. psql -f "$j" $db > /dev/null
  67. fi
  68. sleep 3
  69. dropdb $db
  70. done ) 2>&1 | grep -v 'NOTICE' | grep -v '^CREATE' |grep -v '^DROP'
  71. popd > /dev/null