root/gs2-extensions/tdb/trunk/enable_tdb.sh @ 30239

Revision 30239, 8.6 KB (checked in by jmt12, 5 years ago)

Correcting paths for project name change and making script a little safer by enclosing variable names in braces and paths in quotes (in case they contain spaces)

  • Property svn:executable set to *
Line 
1#!/bin/bash
2# Used to merge in the code needed to add TDB support to Greenstone. The script
3# is responsible for updating both Makefile.in and source code files. You can
4# later run 'disable_tdb.sh' to undo these changes.
5# @author John Thompson, University of Waikato, NZ
6
7echo
8echo '===== Merging TDB support code into Greenstone ====='
9echo
10
11# Test that GSDLHOME is set otherwise we won't be able to find the required files
12if [ "${GSDLHOME}x" == "x" ] ; then echo 'Error! GSDLHOME not set. Please source setup.bash before running.' ; echo ; exit 0 ; fi
13if [ "${GSDLOS}x" == "x" ] ; then echo 'Error! GSDLOS not set. Please source setup.bash before running.' ; echo ; exit 0 ; fi
14
15# Black magic to determine the actual name of the extension folder (in case I
16# change from tdb-edit to tdb in the future (writing in hindsight))
17EXTNAME=${PWD##*/}
18
19echo ' - enabling TDB support in common function library'
20# - Symlink the source file into place
21ln -f -s "${GSDLHOME}/ext/${EXTNAME}/src/lib/tdbclass.h" "${GSDLHOME}/common-src/src/lib/tdbclass.h"
22ln -f -s "${GSDLHOME}/ext/${EXTNAME}/src/lib/tdbclass.cpp" "${GSDLHOME}/common-src/src/lib/tdbclass.cpp"
23# - Makefile.in
24MAKEFILE="${GSDLHOME}/common-src/src/lib/Makefile.in"
25# - I have no idea why this is commented out in the Makefile
26sed -i 's:#GSDL_DIR = ../../..:GSDL_DIR = ../../..:' "${MAKEFILE}"
27grep -q 'DUSE_TDB' "${MAKEFILE}"
28if [ $? -eq 1 ]
29then
30  # - Test for extension support in the makefile
31  grep -q 'EXT_DEFINES' "${MAKEFILE}"
32  if [ $? -eq 1 ]
33  then
34    # - No Extension variables yet - add them in with TDB parts
35    sed -i 's:AR = ar:# Support for adding in extension classes\nEXT_DEFINES = -DUSE_TDB\nEXT_INCLUDES = -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib\nEXT_SOURCES = tdbclass.cpp\nEXT_OBJECTS = tdbclass.o\n\n&:' "${MAKEFILE}"
36    sed -i 's:DEFS = @DEFS@ .*:& $(EXT_DEFINES):' "${MAKEFILE}"
37    sed -i 's:INCLUDES = -I. .*:& $(EXT_INCLUDES):' "${MAKEFILE}"
38    sed -i 's:unitool.cpp:& \\\n        $(EXT_SOURCES):' "${MAKEFILE}"
39    sed -i 's:unitool.o:& \\\n        $(EXT_OBJECTS):' "${MAKEFILE}"
40  else
41    # - Extension support already present - add TDB parts
42    sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' "${MAKEFILE}"
43    sed -i 's:EXT_INCLUDES =.*:& -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib:' "${MAKEFILE}"
44    sed -i 's:EXT_SOURCES =.*:& tdbclass.cpp:' "${MAKEFILE}"
45    sed -i 's:EXT_OBJECTS =.*:& tdbclass.o:' "${MAKEFILE}"
46  fi
47fi
48grep -q 'DUSE_TDB' "${MAKEFILE}"
49if [ $? -eq 1 ]
50then
51  echo "Error! Update of ${MAKEFILE} failed."
52  exit
53fi
54
55echo ' - enabling TDB support in collection server'
56# - Makefile.in
57MAKEFILE="${GSDLHOME}/runtime-src/src/colservr/Makefile.in"
58grep -q 'DUSE_TDB' "${MAKEFILE}"
59if [ $? -eq 1 ]
60then
61  # - Test for extension support in the makefile
62  grep -q 'EXT_DEFINES' "${MAKEFILE}"
63  if [ $? -eq 1 ]
64  then
65    sed -i 's:AR = ar:# Support for adding in extension classes\nEXT_DEFINES = -DUSE_TDB\nEXT_INCLUDES = -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib\n\n&:' "${MAKEFILE}"
66    sed -i 's:DEFS = @DEFS@:& $(EXT_DEFINES):' "${MAKEFILE}"
67    sed -i 's:INCLUDES = -I. -I$(GSDL_DIR):& $(EXT_INCLUDES):' "${MAKEFILE}"
68  else
69    sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' "${MAKEFILE}"
70    sed -i 's:EXT_INCLUDES =.*:& -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib:' "${MAKEFILE}"
71  fi
72fi
73grep -q 'DUSE_TDB' "${MAKEFILE}"
74if [ $? -eq 1 ]
75then
76  echo "Error! Update of ${MAKEFILE} failed."
77  exit
78fi
79
80# - collectset.cpp
81SRCFILE="${GSDLHOME}/runtime-src/src/colservr/collectset.cpp"
82grep -q 'tdbclass.h' "${SRCFILE}"
83if [ $? -eq 1 ]
84then
85  grep -q '@EXTENSION HEADERS@' "${SRCFILE}"
86  if [ $? -eq 1 ]
87  then
88    sed -i 's:collectset\:\:collectset (text_t& gsdlhome, text_t& collecthome):// @EXTENSION HEADERS@\n#include "tdbclass.h //TDB\n\n&:' "${SRCFILE}"
89    sed -i 's:    // Use GDBM if the infodb type is empty or not one of the values above:    // @EXTENSION DATASOURCES@\n    if (infodbtype == "tdb") {db_ptr = new tdbclass(gsdlhome);} //TDB\n    if (infodbtype == "tdbserver") {db_ptr = new tdbclass(gsdlhome);} //TDBServer\n\n&:' "${SRCFILE}"
90  else
91    sed -i 's:// @EXTENSION HEADERS@:&\n#include "tdbclass.h" //TDB:' "${SRCFILE}"
92    sed -i 's:// @EXTENSION DATASOURCES@:&\n    if (infodbtype == "tdb") {db_ptr = new tdbclass(gsdlhome);} //TDB\n    if (infodbtype == "tdbserver") {db_ptr = new tdbclass(gsdlhome);} //TDBServer:' "${SRCFILE}"
93  fi
94fi
95grep -q 'tdbclass.h' "${SRCFILE}"
96if [ $? -eq 1 ]
97then
98  echo "Error! Update of ${SRCFILE} failed."
99  exit
100fi
101
102# - collectserver.cpp
103# There are now sanity tests in collectserver to ensure appropriate indexer and
104# infodbtype are compiled into colservr. While not fatal to leave this as is,
105# it does cause vast amounts of error messages in (Apache) logs
106SRCFILE="${GSDLHOME}/runtime-src/src/colservr/collectserver.cpp"
107grep -q 'TDB' "${SRCFILE}"
108if [ $? -eq 1 ]
109then
110  grep -q '@EXTENSION DATASOURCES@' "${SRCFILE}"
111  if [ $? -eq 1 ]
112  then
113    sed -i 's:  if (infodbtype=="gdbm") {:  // @EXTENSION DATASOURCES@\n  if (infodbtype == "tdb") { return; } // TDB Do nothing\n  if (infodbtype == "tdbserver") { return; } // TDBServer Do nothing\n\n&:' "${SRCFILE}"
114  else
115    sed -i 's:  // @EXTENSION DATASOURCES@:&\n  if (infodbtype == "tdb") { return; } // TDB Do nothing\n  if (infodbtype == "tdbserver") { return; } // TDBServer Do nothing:' "${SRCFILE}"
116  fi
117fi
118grep -q 'TDB' "${SRCFILE}"
119if [ $? -eq 1 ]
120then
121  echo "Error! Update of ${SRCFILE} failed."
122  exit
123fi
124
125echo ' - enabling TDB support in Greenstone receptionist'
126# - Makefile.in
127MAKEFILE="${GSDLHOME}/runtime-src/src/recpt/Makefile.in"
128grep -q 'DUSE_TDB' "${MAKEFILE}"
129if [ $? -eq 1 ]
130then
131  grep -q 'EXT_DEFINES' "${MAKEFILE}"
132  if [ $? -eq 1 ]
133  then
134    sed -i 's:AR = ar:# Support for adding in extension classes\nEXT_DEFINES = -DUSE_TDB\nEXT_INCLUDES = -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib\nEXT_LDFLAGS = -L$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/lib\nEXT_LIBS = -ltdb\n\n&:' "${MAKEFILE}"
135    sed -i 's:DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DHAVE_CONFIG_H:& $(EXT_DEFINES):' "${MAKEFILE}"
136    sed -i 's:INCLUDES = -I. -I$(GSDL_DIR):& $(EXT_INCLUDES):' "${MAKEFILE}"
137    sed -i 's:LDFLAGS = @LDFLAGS@ @ARCH_DEP_FLAGS@:& $(EXT_LDFLAGS):' "${MAKEFILE}"
138    sed -i 's:LIBS = @LIBS@ $(GDBM_LIBS):& $(EXT_LIBS):' "${MAKEFILE}"
139  else
140    sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' "${MAKEFILE}"
141    sed -i 's:EXT_INCLUDES =.*:& -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib:' "${MAKEFILE}"
142    sed -i 's:EXT_LDFLAGS =.*:& -L$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/lib:' "${MAKEFILE}"
143    sed -i 's:EXT_LIBS =.*:& -ltdb:' "${MAKEFILE}"
144  fi
145fi
146grep -q 'DUSE_TDB' "${MAKEFILE}"
147if [ $? -eq 1 ]
148then
149  echo "Error! Update of ${MAKEFILE} failed."
150fi
151
152
153echo ' - enabling TDB support in OAI Server receptionist'
154# - Makefile.in
155MAKEFILE="${GSDLHOME}/runtime-src/src/oaiservr/Makefile.in"
156grep -q 'DUSE_TDB' "${MAKEFILE}"
157if [ $? -eq 1 ]
158then
159  grep -q 'EXT_DEFINES' "${MAKEFILE}"
160  if [ $? -eq 1 ]
161  then
162    sed -i 's:CC = @CC@:# Support for adding in extension classes\nEXT_DEFINES = -DUSE_TDB\nEXT_INCLUDES = -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib\nEXT_LDFLAGS = -L$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/lib\nEXT_LIBS = -ltdb\n\n&:' "${MAKEFILE}"
163    sed -i 's:DEFS = @DEFS@:& $(EXT_DEFINES):' "${MAKEFILE}"
164    sed -i 's:INCLUDES = -I$(COMMON_DIR)/src/lib:& $(EXT_INCLUDES):' "${MAKEFILE}"
165    sed -i 's:LDFLAGS = @LDFLAGS@ @ARCH_DEP_FLAGS@:& $(EXT_LDFLAGS):' "${MAKEFILE}"
166    sed -i 's:LIBS = @LIBS@ $(GDBM_LIBS):& $(EXT_LIBS):' "${MAKEFILE}"
167  else
168    sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' "${MAKEFILE}"
169    sed -i 's:EXT_INCLUDES =.*:& -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib:' "${MAKEFILE}"
170    sed -i 's:EXT_LDFLAGS =.*:& -L$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/lib:' "${MAKEFILE}"
171    sed -i 's:EXT_LIBS =.*:& -ltdb:' "${MAKEFILE}"
172  fi
173fi
174grep -q 'DUSE_TDB' "${MAKEFILE}"
175if [ $? -eq 1 ]
176then
177  echo "Error! Update of ${MAKEFILE} failed."
178fi
179
180echo
181echo '===================================================='
182echo
183echo 'TDB support has now been merged into Greenstone.'
184echo 'Please return to the main Greenstone directory and '
185echo 'rerun:'
186echo
187echo ' ./configure <any required arguments>'
188echo ' make'
189echo ' make install'
190echo
191echo 'to complete TDB installation.'
192echo
193echo 'Should you later wish to remove TDB support run:'
194echo
195echo ' ./disable_tdb.sh'
196echo
197echo '===================================================='
198echo
199
200exit 0
Note: See TracBrowser for help on using the browser.