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

Revision 30253, 8.9 KB (checked in by jmt12, 5 years ago)

It is now safe to run this script multiple times... only the first time will change anything. Subsequent runs will notice the changes are already made.

  • 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" ]
13then
14    echo 'Error! GSDLHOME not set. Please source setup.bash before running.'
15    echo
16    exit 0
17fi
18if [ "${GSDLOS}x" == "x" ]
19then
20    echo 'Error! GSDLOS not set. Please source setup.bash before running.'
21    echo
22    exit 0
23fi
24
25# Black magic to determine the actual name of the extension folder (in case I
26# change from tdb-edit to tdb in the future (writing in hindsight))
27EXTNAME=${PWD##*/}
28
29# - Symlink the source file into place
30printf ' * Symlinking TDB source files into place... '
31if [ -f "${GSDLHOME}/common-src/src/lib/tdbclass.h" ]
32then
33    echo 'already present'
34else
35    ln -f -s "${GSDLHOME}/ext/${EXTNAME}/src/lib/tdbclass.h" "${GSDLHOME}/common-src/src/lib/tdbclass.h"
36    ln -f -s "${GSDLHOME}/ext/${EXTNAME}/src/lib/tdbclass.cpp" "${GSDLHOME}/common-src/src/lib/tdbclass.cpp"
37    echo 'Done!'
38fi
39
40# - Makefile.in
41printf ' * Enabling TDB support in common function library... '
42MAKEFILE="${GSDLHOME}/common-src/src/lib/Makefile.in"
43# - I have no idea why this is commented out in the Makefile
44sed -i 's:#GSDL_DIR = ../../..:GSDL_DIR = ../../..:' "${MAKEFILE}"
45grep -q 'DUSE_TDB' "${MAKEFILE}"
46if [ $? -eq 1 ]
47then
48    # - Test for extension support in the makefile
49    grep -q 'EXT_DEFINES' "${MAKEFILE}"
50    if [ $? -eq 1 ]
51    then
52    # - No Extension variables yet - add them in with TDB parts
53    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}"
54    sed -i 's:DEFS = @DEFS@ .*:& $(EXT_DEFINES):' "${MAKEFILE}"
55    sed -i 's:INCLUDES = -I. .*:& $(EXT_INCLUDES):' "${MAKEFILE}"
56    sed -i 's:unitool.cpp:& \\\n        $(EXT_SOURCES):' "${MAKEFILE}"
57    sed -i 's:unitool.o:& \\\n        $(EXT_OBJECTS):' "${MAKEFILE}"
58    else
59    # - Extension support already present - add TDB parts
60    sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' "${MAKEFILE}"
61    sed -i 's:EXT_INCLUDES =.*:& -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib:' "${MAKEFILE}"
62    sed -i 's:EXT_SOURCES =.*:& tdbclass.cpp:' "${MAKEFILE}"
63    sed -i 's:EXT_OBJECTS =.*:& tdbclass.o:' "${MAKEFILE}"
64    fi
65    echo 'Done!'
66else
67    echo 'already enabled'
68fi
69grep -q 'DUSE_TDB' "${MAKEFILE}"
70if [ $? -eq 1 ]
71then
72  echo "Error! Update of ${MAKEFILE} failed."
73  exit
74fi
75
76printf ' * Enabling TDB support in collection server... '
77# - Makefile.in
78MAKEFILE="${GSDLHOME}/runtime-src/src/colservr/Makefile.in"
79grep -q 'DUSE_TDB' "${MAKEFILE}"
80if [ $? -eq 1 ]
81then
82    # - Test for extension support in the makefile
83    grep -q 'EXT_DEFINES' "${MAKEFILE}"
84    if [ $? -eq 1 ]
85    then
86    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}"
87    sed -i 's:DEFS = @DEFS@:& $(EXT_DEFINES):' "${MAKEFILE}"
88    sed -i 's:INCLUDES = -I. -I$(GSDL_DIR):& $(EXT_INCLUDES):' "${MAKEFILE}"
89    else
90    sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' "${MAKEFILE}"
91    sed -i 's:EXT_INCLUDES =.*:& -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib:' "${MAKEFILE}"
92    fi
93    echo 'Done!'
94else
95    echo 'already enabled'
96fi
97grep -q 'DUSE_TDB' "${MAKEFILE}"
98if [ $? -eq 1 ]
99then
100    echo "Error! Update of ${MAKEFILE} failed."
101    exit
102fi
103
104# - collectset.cpp
105SRCFILE="${GSDLHOME}/runtime-src/src/colservr/collectset.cpp"
106grep -q 'tdbclass.h' "${SRCFILE}"
107if [ $? -eq 1 ]
108then
109    grep -q '@EXTENSION HEADERS@' "${SRCFILE}"
110    if [ $? -eq 1 ]
111    then
112    sed -i 's:collectset\:\:collectset (text_t& gsdlhome, text_t& collecthome):// @EXTENSION HEADERS@\n#include "tdbclass.h //TDB\n\n&:' "${SRCFILE}"
113    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}"
114    else
115    sed -i 's:// @EXTENSION HEADERS@:&\n#include "tdbclass.h" //TDB:' "${SRCFILE}"
116    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}"
117    fi
118fi
119grep -q 'tdbclass.h' "${SRCFILE}"
120if [ $? -eq 1 ]
121then
122    echo "Error! Update of ${SRCFILE} failed."
123    exit
124fi
125
126# - collectserver.cpp
127# There are now sanity tests in collectserver to ensure appropriate indexer and
128# infodbtype are compiled into colservr. While not fatal to leave this as is,
129# it does cause vast amounts of error messages in (Apache) logs
130SRCFILE="${GSDLHOME}/runtime-src/src/colservr/collectserver.cpp"
131grep -q 'TDB' "${SRCFILE}"
132if [ $? -eq 1 ]
133then
134    grep -q '@EXTENSION DATASOURCES@' "${SRCFILE}"
135    if [ $? -eq 1 ]
136    then
137    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}"
138    else
139    sed -i 's:  // @EXTENSION DATASOURCES@:&\n  if (infodbtype == "tdb") { return; } // TDB Do nothing\n  if (infodbtype == "tdbserver") { return; } // TDBServer Do nothing:' "${SRCFILE}"
140    fi
141fi
142grep -q 'TDB' "${SRCFILE}"
143if [ $? -eq 1 ]
144then
145    echo "Error! Update of ${SRCFILE} failed."
146    exit
147fi
148
149printf ' * Enabling TDB support in Greenstone receptionist... '
150# - Makefile.in
151MAKEFILE="${GSDLHOME}/runtime-src/src/recpt/Makefile.in"
152grep -q 'DUSE_TDB' "${MAKEFILE}"
153if [ $? -eq 1 ]
154then
155    grep -q 'EXT_DEFINES' "${MAKEFILE}"
156    if [ $? -eq 1 ]
157    then
158    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}"
159    sed -i 's:DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DHAVE_CONFIG_H:& $(EXT_DEFINES):' "${MAKEFILE}"
160    sed -i 's:INCLUDES = -I. -I$(GSDL_DIR):& $(EXT_INCLUDES):' "${MAKEFILE}"
161    sed -i 's:LDFLAGS = @LDFLAGS@ @ARCH_DEP_FLAGS@:& $(EXT_LDFLAGS):' "${MAKEFILE}"
162    sed -i 's:LIBS = @LIBS@ $(GDBM_LIBS):& $(EXT_LIBS):' "${MAKEFILE}"
163    else
164    sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' "${MAKEFILE}"
165    sed -i 's:EXT_INCLUDES =.*:& -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib:' "${MAKEFILE}"
166    sed -i 's:EXT_LDFLAGS =.*:& -L$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/lib:' "${MAKEFILE}"
167    sed -i 's:EXT_LIBS =.*:& -ltdb:' "${MAKEFILE}"
168    fi
169    echo 'Done!'
170else
171    echo 'already enabled'
172fi
173grep -q 'DUSE_TDB' "${MAKEFILE}"
174if [ $? -eq 1 ]
175then
176    echo "Error! Update of ${MAKEFILE} failed."
177fi
178
179
180printf ' * Enabling TDB support in OAI Server receptionist... '
181# - Makefile.in
182MAKEFILE="${GSDLHOME}/runtime-src/src/oaiservr/Makefile.in"
183grep -q 'DUSE_TDB' "${MAKEFILE}"
184if [ $? -eq 1 ]
185then
186    grep -q 'EXT_DEFINES' "${MAKEFILE}"
187    if [ $? -eq 1 ]
188    then
189    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}"
190    sed -i 's:DEFS = @DEFS@:& $(EXT_DEFINES):' "${MAKEFILE}"
191    sed -i 's:INCLUDES = -I$(COMMON_DIR)/src/lib:& $(EXT_INCLUDES):' "${MAKEFILE}"
192    sed -i 's:LDFLAGS = @LDFLAGS@ @ARCH_DEP_FLAGS@:& $(EXT_LDFLAGS):' "${MAKEFILE}"
193    sed -i 's:LIBS = @LIBS@ $(GDBM_LIBS):& $(EXT_LIBS):' "${MAKEFILE}"
194    else
195    sed -i 's:EXT_DEFINES =.*:& -DUSE_TDB:' "${MAKEFILE}"
196    sed -i 's:EXT_INCLUDES =.*:& -I$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/include -I$(GSDL_DIR)/ext/'${EXTNAME}'/src/lib:' "${MAKEFILE}"
197    sed -i 's:EXT_LDFLAGS =.*:& -L$(GSDL_DIR)/ext/'${EXTNAME}'/'${GSDLOS}'/lib:' "${MAKEFILE}"
198    sed -i 's:EXT_LIBS =.*:& -ltdb:' "${MAKEFILE}"
199    fi
200    echo 'Done!'
201else
202    echo 'already enabled'
203fi
204grep -q 'DUSE_TDB' "${MAKEFILE}"
205if [ $? -eq 1 ]
206then
207    echo "Error! Update of ${MAKEFILE} failed."
208fi
209
210echo
211echo '===================================================='
212echo
213echo 'TDB support has now been merged into Greenstone.'
214echo 'Please return to the main Greenstone directory and '
215echo 'rerun:'
216echo
217echo ' ./configure <any required arguments>'
218echo ' make'
219echo ' make install'
220echo
221echo 'to complete TDB installation.'
222echo
223echo 'Should you later wish to remove TDB support run:'
224echo
225echo ' ./disable_tdb.sh'
226echo
227echo '===================================================='
228echo
229
230exit 0
Note: See TracBrowser for help on using the browser.