ser_to_sr.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env sh
  2. #
  3. # This is a simple script which attempts to convert ser modules so that they
  4. # can be used with the sip-router core. Most of the changes done by the script
  5. # deal with the changes in the database abstraction layer in the sip-router
  6. # source tree.
  7. #
  8. # Run this script in module directory to convert it from ser core to
  9. # sip-router core. The root of the tree should be two levels up, otherwise
  10. # relative paths to headers (../..) would not work and the module will not
  11. # compile.
  12. #
  13. # Some of the changes done by the script:
  14. #
  15. # * Extra defines in the Makefile to make the module link with libsrdb2
  16. # * Path to database headers updated to point to lib/srdb2
  17. # * Database flag names renamed from DB_* to SRDB_*
  18. # (DB_DISABLED -> SRDB_DISABLED)
  19. #
  20. # NOTE: There is no guarantee that the update module would compile or even
  21. # work. Make a backup before running the script. You have been warned!
  22. #
  23. # Written by Jan Janak <[email protected]>
  24. #
  25. if [ ! -f Makefile ] ; then
  26. echo "ERROR: Could not find module Makefile"
  27. echo " Run this file in the module directory"
  28. exit 1
  29. fi
  30. if ! egrep "Makefile\.modules" Makefile >/dev/null ; then
  31. echo "ERROR: Doesn't look like a module..."
  32. exit 1
  33. fi
  34. if ! egrep '^#[ \t]*include[ \t]*".*\/db\/db(_(cmd|con|ctx|drv|fld|gen|pool|rec|res|uri))?\.h[ \t]*"' *.[ch] >/dev/null ; then
  35. echo "The module does not seem to include old database headers..."
  36. exit 0
  37. fi
  38. echo -n "Updating Makefile..."
  39. cp Makefile Makefile.backup
  40. cat Makefile.backup | gawk '
  41. BEGIN {
  42. serlibpath_seen = 0
  43. libs_seen = 0
  44. defs_seen = 0
  45. }
  46. # If the define already exists then skip it, this ensures that
  47. # we do not add the same line more than once.
  48. /^[ \t]*DEFS[ \t]*\+?=.*SER_MOD_INTERFACE/ {
  49. defs_seen = 1
  50. }
  51. /^[ \t]*SER_LIBS[ \t]*\+?=.*srdb2\/srdb2/ {
  52. libs_seen = 1
  53. }
  54. /^[ \t]*SERLIBPATH[ \t]*=/ {
  55. serlibpath_seen = 1
  56. }
  57. # Write everything just before the line including Makefile.modules,
  58. # this is most likely the last line in the Makefile
  59. /^[ \t]*include[ \t]+.*\/Makefile\.modules[ \t]*$/ {
  60. if (serlibpath_seen == 0) print "SERLIBPATH=../../lib"
  61. if (defs_seen == 0) print "DEFS+=-DSER_MOD_INTERFACE"
  62. if (libs_seen == 0) print "SER_LIBS+=$(SERLIBPATH)/srdb2/srdb2"
  63. }
  64. { print $0 }
  65. ' > Makefile
  66. echo "done."
  67. for file in *.[ch] ; do
  68. echo -n "Updating file $file..."
  69. cp $file $file.backup
  70. cat $file.backup | gawk '
  71. /^#[ \t]*include[ \t]*".*\/db\/db(_(cmd|con|ctx|drv|fld|gen|pool|rec|res|uri))?\.h[ \t]*"/ {
  72. sub("/db/", "/lib/srdb2/", $0);
  73. }
  74. /(^|[^a-zA-Z0-9_])DB_(LOAD_SER|DISABLED|CANON|IS_(TO|FROM)|FOR_SERWEB|PENDING|((CALLER|CALLEE)_)?DELETED|MULTIVALUE|FILL_ON_REG|REQUIRED|DIR)([^a-zA-Z0-9_]|$)/ {
  75. gsub("DB_LOAD_SER", "SRDB_LOAD_SER", $0);
  76. gsub("DB_DISABLED", "SRDB_DISABLED", $0);
  77. gsub("DB_CANON", "SRDB_CANON", $0);
  78. gsub("DB_IS_TO", "SRDB_IS_TO", $0);
  79. gsub("DB_IS_FROM", "SRDB_IS_FROM", $0);
  80. gsub("DB_FOR_SERWEB", "SRDB_FOR_SERWEB", $0);
  81. gsub("DB_PENDING", "SRDB_PENDING", $0);
  82. gsub("DB_DELETED", "SRDB_DELETED", $0);
  83. gsub("DB_CALLER_DELETED", "SRDB_CALLER_DELETED", $0);
  84. gsub("DB_CALLEE_DELETED", "SRDB_CALLEE_DELETED", $0);
  85. gsub("DB_MULTIVALUE", "SRDB_MULTIVALUE", $0);
  86. gsub("DB_FILL_ON_REG", "SRDB_FILL_ON_REG", $0);
  87. gsub("DB_REQUIRED", "SRDB_REQUIRED", $0);
  88. gsub("DB_DIR", "SRDB_DIR", $0);
  89. }
  90. { print $0 }
  91. ' >$file
  92. echo "done."
  93. done