root/main/trunk/greenstone2/perllib/cpan/compile-dbd-mysql.sh @ 32788

Revision 32788, 10.8 KB (checked in by ak19, 9 months ago)

Expanded to include compilation support for Linux. Sadly the Linux testing VM doesn't even have make installed, so this script won't help, but it is useful to get MySQL installed (but not initialised for use) within a Greenstone and to have the DBD (and DBI) perl package compiled and installed too.

  • Property svn:executable set to *
Line 
1###################################################
2# A basic cascade-make to install the DBD::mysql v 4.033 perl package to work with the GreenstoneSQLPlugin/Plugout
3#
4# Requires an internet connection to download required packages etc
5#
6# No dependencies
7#
8#
9# Compiling AND INSTALLING of all packages takes place in the temporary cpan/tmp folder. A select subset of the compiled/installed
10# products are then copied into their final destinations: lib/../<pkg> is copied into cpan, and lib/../auto/<pkg> is copied into cpan/auto
11#
12#
13###################################################
14
15if [ "x$1" = "x--help" ] || [ "x$1" = "x-h" ]; then
16    echo "Usage: $0 [--clean|--keep|--help|-h]"
17    echo "  Run without flags to compile and remove unnecessary stuff at the end."
18    echo "  Run with --keep to retain the cpan/tmp subdir at compilation's end."
19    echo "  Run with --clean to remove all traces of compilation completely so you can recompile from scratch"
20    echo "  Run with --help/-h to see this Usage statement again"
21    exit 0
22fi
23
24if [ "x$GSDL3SRCHOME" = "x" ] ; then
25    echo "** GSDL3SRCHOME not set, sourcing gs3-setup.sh"
26    echo ""
27    cd ../../..
28    source ./gs3-setup.sh
29    cd $GSDLHOME/perllib/cpan
30fi
31
32echo ""
33echo "**************************"
34
35########################## VARIABLES ######################
36
37# Expected defaults:
38# - This script was originally created for Mac High Sierra where the DBI perl package was installed #   but the DBD perl package is missing (which needs to be compiled against MySQL 5.7.23 that we
39#   will download and adjust for the purpose)
40# - The DBI perl package tends to be installed on Mac and Linux Ubuntu. If not, set NEED_PERL_DBI
41#   to true to compile it up against the MySQL that this script will download.
42# - Regardless of whether you have a MySQL installed, this script needs to download MySQL v 5.7.23
43#   in specific to compile (DBI and) DBD against it.
44#   MySQL tends to be installed on Linux. If the version installed is 5.7.23, you may not want to
45#   keep the MySQL that this script downloads. In that case set KEEP_MYSQL_DOWNLOAD to false.
46# - The Ubunutu 16.04 assigned to me had both DBI and DBD installed so I didn't need to run this
47#   script at all.
48
49NEED_PERL_DBI=false # set to true if your machine doesn't have DBI
50KEEP_MYSQL_DOWNLOAD=true # needed for compiling DBD (and DBI). Set to false if custom MySQL to be removed after compiling
51NEED_PERL_DBD=true # only set to false, if you want this script to ONLY get and extract MySQL for you
52
53# Need mysql 5.7.23 to compile DBD (and DBI) against. Regardless of whether user wants to use this mysql,
54# we need to download, unpack and adjust it for compiling up DBD (and optionally DBI).
55# The version of mysql we want is 5.7.23, we get the MacOS 10.13 (High Sierra) binary
56# and extract it into GSDLHOME as mysql-5.7.23
57MYSQL_BIN=mysql-5.7.23
58MYSQL_MIRROR=http://mysql.inspire.net.nz/Downloads/MySQL-5.7
59
60# $GSDLOS can be "darwin" on Mac, else "linux".
61# Alternatively, can test `uname`: echoed value can be "Darwin" (on Mac) or "Linux"
62if [ "x$GSDLOS" = "xdarwin" ] ; then
63    MYSQL_TARBALL="${MYSQL_BIN}-macos10.13-x86_64" 
64else
65    MYSQL_TARBALL="${MYSQL_BIN}-linux-glibc2.12-x86_64"
66fi
67
68# We want DBD::mysql version 4.033
69# This package is necessary on Mac High Sierra (v10.13)
70# Assigned Ubuntu had DBD (and DBI) but VM testing Ubuntu had neither
71DBD_MYSQL=DBD-mysql-4.033
72DBD_MYSQL_DOWNLOAD=https://cpan.metacpan.org/authors/id/C/CA/CAPTTOFU/$DBD_MYSQL.tar.gz
73
74# We may need DBI::DBD version 1.634, if DBI not installed (on machines with no DBD and DBI)
75# see http://wiki.greenstone.org/doku.php?id=en:user_advanced:greenstonesqlplugs
76# and https://metacpan.org/pod/release/TIMB/DBI-1.634/lib/DBI/DBD.pm
77DBI_DBD=DBI-1.634
78DBI_DBD_DOWNLOAD=https://cpan.metacpan.org/authors/id/T/TI/TIMB/$DBI_DBD.tar.gz
79
80
81########################## DON'T CHANGE ####################
82CPAN_DIR=$GSDLHOME/perllib/cpan
83
84# PERL_FOLDER is something like "perl-5.18" (even if the full version number is 5.18.2)
85PERL_VERSION=`perl -e 'print "5.".substr($],3,2);'`
86# full perl version number like 5.18.2 or 5.22.1 (actually "5 version 22 subversion 1)
87PERL_FULL_VERSION=`perl -e 'print "5.".substr($],3,2).".".substr($],7,1);'`
88PERL_FOLDER="perl-${PERL_VERSION}" #`perl -e 'print "perl-5.".substr($],3,2);'`
89
90# make the dirs cpan/$PERL_FOLDER and its subdir auto if they don't already exist
91mkdir -p $CPAN_DIR/$PERL_FOLDER/auto
92
93WGET_FLAGS=--no-check-certificate
94# folder where we'll put the downloaded files, the compile products and the temporary install products
95# after everything is installed there, we copy just the relevant installed files to their final locations
96# then the tmp file gets deleted
97TEMP_DBI_DBD_DIR=$CPAN_DIR/tmp-mysql
98TEMP_STATIC_LIBS_DIR=$GSDLHOME/$MYSQL_BIN/mysql-static
99MYSQL_DIR=$GSDLHOME/$MYSQL_BIN
100
101
102##########################
103
104# if --clean was passed in
105if [ "x$1" = "x--clean" ] ; then
106    pushd $CPAN_DIR
107    if [ -d "$PERL_FOLDER/DBD" ]; then
108    rm -rf $PERL_FOLDER/DBD
109    fi
110    if [ -d "$PERL_FOLDER/auto/DBD" ]; then
111    rm -rf $PERL_FOLDER/auto/DBD
112    fi
113    echo "** Done cleaning DBD::mysql related packages"
114
115    if [ -e "$PERL_FOLDER/DBI.pm" ]; then
116    rm -f $PERL_FOLDER/DBI.pm
117    fi
118    if [ -d "$PERL_FOLDER/DBI" ]; then
119    rm -rf $PERL_FOLDER/DBI
120    fi
121    if [ -d "$PERL_FOLDER/auto/DBI" ]; then
122    rm -rf $PERL_FOLDER/auto/DBI
123    fi
124    echo "** Done cleaning DBI::DBD related packages"
125    popd
126    exit 0
127fi
128
129# Go into $GSDLHOME
130pushd $GSDLHOME
131
132# download and untar mysql into $GSDLHOME
133if [ ! -d $GSDLHOME/$MYSQL_BIN ]; then
134    if [ ! -e $GSDLHOME/$MYSQL_TARBALL.tar.gz ]; then
135    echo "** Getting the mysql tarball"
136    wget $WGET_FLAGS $MYSQL_MIRROR/$MYSQL_TARBALL.tar.gz
137    fi
138    echo "** Extracting the mysql tarball into $GSDLHOME and renaming to $MYSQLBIN"
139    tar -xvzf $MYSQL_TARBALL.tar.gz
140    # there's 2 tarballs inside, untar the one with identical name to outer
141    # and rename to $GSDLHOME/mysql-5.7.23
142#    cd $MYSQL_TARBALL
143#    tar -xvzf $MYSQL_TARBALL.tar.gz
144#    cd $GSDLHOME
145#    mv $MYSQL_TARBALL/$MYSQL_TARBALL $GSDLHOME/$MYSQL_BIN
146    mv $MYSQL_TARBALL $GSDLHOME/$MYSQL_BIN
147fi
148
149# copy just the static .a libraries into their own folder
150if [ ! -d $TEMP_STATIC_LIBS_DIR ]; then
151    echo "** Creating $TEMP_STATIC_LIBS_DIR and copying $MYSQL_BIN/lib/*.a into it"
152    mkdir -p $TEMP_STATIC_LIBS_DIR
153    cp $GSDLHOME/$MYSQL_BIN/lib/*.a $TEMP_STATIC_LIBS_DIR/.
154fi
155
156# Ensure a clean new temp folder to compile (DBI and) DBD into
157echo "** Creating $TEMP_DBI_DBD_DIR (anew)"
158if [ -d $TEMP_DBI_DBD_DIR ]; then
159    rm -rf $TEMP_DBI_DBD_DIR
160fi
161mkdir $TEMP_DBI_DBD_DIR
162
163
164if [ "x$NEED_PERL_DBI" = "xtrue" ] ; then
165    # download and untar DBI::DBD v 1.634
166    if [ ! -d $GSDLHOME/$DBI_DBD ]; then
167        cd $GSDLHOME
168        if [ ! -e $GSDLHOME/$DBI_DBD.tar.gz ]; then
169        echo "** Getting the DBI::DBD tarball"
170        wget $WGET_FLAGS $DBI_DBD_DOWNLOAD
171        fi
172        echo "** Extracting the DBI::DBD tarball into $GSDLHOME"
173        tar -xvzf $DBI_DBD.tar.gz
174    fi
175    # start compiling DBI::DBD into $TEMP_DBI_DBD_DIR
176    echo "** Compiling the DBI perl package"
177
178    cd $GSDLHOME/$DBI_DBD
179    perl Makefile.PL \
180        PREFIX=$TEMP_DBI_DBD_DIR
181        --cflags=-I$GSDLHOME/$MYSQL_BIN/include \
182        --libs="-L$TEMP_STATIC_LIBS_DIR -lmysqlclient"
183    make
184    make install
185
186    # move built DBI::DBD products into correct CPAN location
187    echo "** Moving relevant DBI::DBD products into $CPAN_DIR/$PERL_FOLDER"
188    cd $CPAN_DIR
189    if [ "x$GSDLOS" = "xdarwin" ] ; then
190        mv $TEMP_DBI_DBD_DIR/lib/perl5/site_perl/$PERL_FULL_VERSION/darwin-thread-multi-2level/DBI.pm $PERL_FOLDER/.
191        mv $TEMP_DBI_DBD_DIR/lib/perl5/site_perl/$PERL_FULL_VERSION/darwin-thread-multi-2level/DBI $PERL_FOLDER/.
192        mv $TEMP_DBI_DBD_DIR/lib/perl5/site_perl/$PERL_FULL_VERSION/darwin-thread-multi-2level/auto/DBI $PERL_FOLDER/auto/.
193    else
194        mv $TEMP_DBI_DBD_DIR/lib/x86_64-linux-gnu/perl/$PERL_FULL_VERSION/DBI.pm $PERL_FOLDER/.
195        mv $TEMP_DBI_DBD_DIR/lib/x86_64-linux-gnu/perl/$PERL_FULL_VERSION/DBI $PERL_FOLDER/.
196        mv $TEMP_DBI_DBD_DIR/lib/x86_64-linux-gnu/perl/$PERL_FULL_VERSION/auto/DBI $PERL_FOLDER/auto/.
197    fi
198fi
199#echo "EXITING"
200#exit
201
202if [ "x$NEED_PERL_DBD" = "xtrue" ] ; then
203    # download and untar DBD::mysql v 4.033
204    if [ ! -d $GSDLHOME/$DBD_MYSQL ]; then
205        cd $GSDLHOME
206        if [ ! -e $GSDLHOME/$DBD_MYSQL.tar.gz ]; then
207        echo "** Getting the DBD::mysql tarball"
208        wget $WGET_FLAGS $DBD_MYSQL_DOWNLOAD
209        fi
210        echo "** Extracting the DBD mysql tarball into $GSDLHOME"
211        tar -xvzf $DBD_MYSQL.tar.gz
212    fi
213    # start compiling DBD::mysql into $TEMP_DBI_DBD_DIR
214    echo "** Compiling this perl package"
215
216    cd $GSDLHOME/$DBD_MYSQL
217    perl Makefile.PL \
218        PREFIX=$TEMP_DBI_DBD_DIR \
219        --cflags=-I$GSDLHOME/$MYSQL_BIN/include \
220        --libs="-L$TEMP_STATIC_LIBS_DIR -lmysqlclient"
221    make
222    make install
223
224    # move built DBD::mysql products into correct CPAN location
225    echo "** Moving relevant DBD::mysql products into $CPAN_DIR/$PERL_FOLDER"
226    cd $CPAN_DIR
227    if [ "x$GSDLOS" = "xdarwin" ] ; then
228        mv $TEMP_DBI_DBD_DIR/lib/perl5/site_perl/$PERL_FULL_VERSION/darwin-thread-multi-2level/DBD $PERL_FOLDER/.
229        mv $TEMP_DBI_DBD_DIR/lib/perl5/site_perl/$PERL_FULL_VERSION/darwin-thread-multi-2level/auto/DBD $PERL_FOLDER/auto/.
230    else   
231        mv $TEMP_DBI_DBD_DIR/lib/x86_64-linux-gnu/perl/$PERL_FULL_VERSION/DBD $PERL_FOLDER/.
232        mv $TEMP_DBI_DBD_DIR/lib/x86_64-linux-gnu/perl/$PERL_FULL_VERSION/auto/DBD $PERL_FOLDER/auto/.
233    fi
234fi
235
236# clean up
237echo "*****************************"
238echo "*** Done compiling DBD::mysql."
239if [ "x$1" != "x--keep" ] ; then
240    echo "** Will now delete temporary DBD::mysql products, and the untarred DBD::mysql"
241    rm -rf $TEMP_DBI_DBD_DIR
242    if [ -d "$GSDLHOME/$DBI_DBD" ]; then
243    rm -rf $GSDLHOME/$DBI_DBD
244    fi
245    if [ -d "$GSDLHOME/$DBD_MYSQL" ]; then
246    rm -rf $GSDLHOME/$DBD_MYSQL
247    fi
248else
249    echo "**   Not deleting the $TEMP_DBI_DBD_DIR"
250fi
251# The static libs folder added to the downloaded MySQL installation was only necessary for compiling.
252# It can be removed now, since MySQL usage doesn't require it.
253rm -rf $TEMP_STATIC_LIBS_DIR
254
255
256if [ "x$KEEP_MYSQL_DOWNLOAD" = "xfalse" ] ; then
257    if [ -d $GSDLHOME/$MYSQL_BIN ]; then
258    echo "**** KEEP_MYSQL_DOWNLOAD set to false, so removing $GSDLHOME/$MYSQL_BIN folder"
259    echo "     now that compilation is done"
260        rm -rf $GSDLHOME/$MYSQL_BIN
261    fi
262fi
263
264# go back to where we started
265popd
266
267echo "*****************************"
268echo ""
269if [ "x$KEEP_MYSQL_DOWNLOAD" = "xfalse" ] ; then
270    echo "** KEEP_MYSQL_DOWNLOAD was set to false,"
271    echo "   so it's assumed you have your own MySQL 5.7.23 installation"
272    echo "   You now need to initialise your MySQL installation."
273else
274    echo "** You now need to initialise the MySQL installation at $GSDLHOME/$MYSQL_BIN"
275fi
276echo "** Follow the instructions from STEP 2 ONWARDS at at http://wiki.greenstone.org/doku.php?id=en:user_advanced:greenstonesqlplugs#installing_one_time_setup"
277echo "** Once that's done, the same page has information on how to use the GreenstoneSQLPlugs in a collection"
278echo ""
279echo "*****************************"
280
Note: See TracBrowser for help on using the browser.