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

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

Trying to make symlinks smart enough to work under both Greenstone2 and Greenstone3

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