Ignore:
Timestamp:
2019-02-20T20:21:39+13:00 (5 years ago)
Author:
ak19
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/cpan/compile-dbd-mysql.sh

    r32787 r32788  
    3535########################## VARIABLES ######################
    3636
    37 
    38 # the version of mysql we want is 5.7.23, we get the MacOS 10.13 (High Sierra) binary
     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
    3956# and extract it into GSDLHOME as mysql-5.7.23
    4057MYSQL_BIN=mysql-5.7.23
    4158MYSQL_MIRROR=http://mysql.inspire.net.nz/Downloads/MySQL-5.7
    42 #MYSQL_TARBALL="${MYSQL_BIN}-linux-glibc2.12-x86_64"
    43 MYSQL_TARBALL="${MYSQL_BIN}-macos10.13-x86_64"
    44 
    45 
    46 # We want DBI::mysql version 1.634
     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)
    4775# see http://wiki.greenstone.org/doku.php?id=en:user_advanced:greenstonesqlplugs
    4876# and https://metacpan.org/pod/release/TIMB/DBI-1.634/lib/DBI/DBD.pm
    4977DBI_DBD=DBI-1.634
    5078DBI_DBD_DOWNLOAD=https://cpan.metacpan.org/authors/id/T/TI/TIMB/$DBI_DBD.tar.gz
    51 
    52 # We want DBD::mysql version 4.033
    53 DBD_MYSQL=DBD-mysql-4.033
    54 DBD_MYSQL_DOWNLOAD=https://cpan.metacpan.org/authors/id/C/CA/CAPTTOFU/$DBD_MYSQL.tar.gz
    5579
    5680
     
    7599MYSQL_DIR=$GSDLHOME/$MYSQL_BIN
    76100
     101
    77102##########################
    78103
     
    80105if [ "x$1" = "x--clean" ] ; then
    81106    pushd $CPAN_DIR
    82     if [ -e "$PERL_FOLDER/DBD" ]; then
     107    if [ -d "$PERL_FOLDER/DBD" ]; then
    83108    rm -rf $PERL_FOLDER/DBD
    84109    fi
    85     if [ -e "$PERL_FOLDER/auto/DBD" ]; then
     110    if [ -d "$PERL_FOLDER/auto/DBD" ]; then
    86111    rm -rf $PERL_FOLDER/auto/DBD
    87112    fi
    88113    echo "** Done cleaning DBD::mysql related packages"
    89114
    90     if [ -e "$PERL_FOLDER/DBI" ]; then
     115    if [ -e "$PERL_FOLDER/DBI.pm" ]; then
     116    rm -f $PERL_FOLDER/DBI.pm
     117    fi
     118    if [ -d "$PERL_FOLDER/DBI" ]; then
    91119    rm -rf $PERL_FOLDER/DBI
    92120    fi
    93     if [ -e "$PERL_FOLDER/auto/DBI" ]; then
     121    if [ -d "$PERL_FOLDER/auto/DBI" ]; then
    94122    rm -rf $PERL_FOLDER/auto/DBI
    95123    fi
     
    126154fi
    127155
    128 # download and untar DBI::DBD v 1.634
    129 if [ ! -d $GSDLHOME/$DBI_DBD ]; then
    130     cd $GSDLHOME
    131     if [ ! -e $GSDLHOME/$DBI_DBD.tar.gz ]; then
    132     echo "** Getting the DBI::DBD tarball"
    133     wget $WGET_FLAGS $DBI_DBD_DOWNLOAD
    134     fi
    135     echo "** Extracting the DBI::DBD tarball into $GSDLHOME"
    136     tar -xvzf $DBI_DBD.tar.gz
    137 fi
    138 # start compiling DBI::DBD into $TEMP_DBI_DBD_DIR
    139 echo "** Creating $TEMP_DBI_DBD_DIR (anew) and compiling this perl package"
    140 
     156# Ensure a clean new temp folder to compile (DBI and) DBD into
     157echo "** Creating $TEMP_DBI_DBD_DIR (anew)"
    141158if [ -d $TEMP_DBI_DBD_DIR ]; then
    142159    rm -rf $TEMP_DBI_DBD_DIR
     
    144161mkdir $TEMP_DBI_DBD_DIR
    145162
    146 cd $GSDLHOME/$DBI_DBD
    147 perl Makefile.PL \
    148     PREFIX=$TEMP_DBI_DBD_DIR
    149     --cflags=-I$GSDLHOME/$MYSQL_BIN/include \
    150     --libs="-L$TEMP_STATIC_LIBS_DIR -lmysqlclient"
    151 make
    152 make install
    153 
    154 # move built DBI::DBD products into correct CPAN location
    155 echo "** Moving relevant DBI::DBD products into $CPAN_DIR/$PERL_FOLDER"
    156 cd $CPAN_DIR
    157 mv $TEMP_DBI_DBD_DIR/lib/perl5/site_perl/$PERL_FULL_VERSION/darwin-thread-multi-2level/DBI $PERL_FOLDER/.
    158 mv $TEMP_DBI_DBD_DIR/lib/perl5/site_perl/$PERL_FULL_VERSION/darwin-thread-multi-2level/auto/DBI $PERL_FOLDER/auto/.
    159 
     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
    160199#echo "EXITING"
    161200#exit
    162201
    163 
    164 # download and untar DBD::mysql v 4.033
    165 if [ ! -d $GSDLHOME/$DBD_MYSQL ]; then
    166     cd $GSDLHOME
    167     if [ ! -e $GSDLHOME/$DBD_MYSQL.tar.gz ]; then
    168     echo "** Getting the DBD::mysql tarball"
    169     wget $WGET_FLAGS $DBD_MYSQL_DOWNLOAD
    170     fi
    171     echo "** Extracting the DBD mysql tarball into $GSDLHOME"
    172     tar -xvzf $DBD_MYSQL.tar.gz
    173 fi
    174 # start compiling DBD::mysql into $TEMP_DBI_DBD_DIR
    175 echo "** Compiling this perl package"
    176 
    177 cd $GSDLHOME/$DBD_MYSQL
    178 perl Makefile.PL \
    179     PREFIX=$TEMP_DBI_DBD_DIR \
    180     --cflags=-I$GSDLHOME/$MYSQL_BIN/include \
    181     --libs="-L$TEMP_STATIC_LIBS_DIR -lmysqlclient"
    182 make
    183 make install
    184 
    185 
    186 # move built DBD::mysql products into correct CPAN location
    187 echo "** Moving relevant DBD::mysql products into $CPAN_DIR/$PERL_FOLDER"
    188 cd $CPAN_DIR
    189 mv $TEMP_DBI_DBD_DIR/lib/perl5/site_perl/$PERL_FULL_VERSION/darwin-thread-multi-2level/DBD $PERL_FOLDER/.
    190 mv $TEMP_DBI_DBD_DIR/lib/perl5/site_perl/$PERL_FULL_VERSION/darwin-thread-multi-2level/auto/DBD $PERL_FOLDER/auto/.
     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
    191235
    192236# clean up
     
    196240    echo "** Will now delete temporary DBD::mysql products, and the untarred DBD::mysql"
    197241    rm -rf $TEMP_DBI_DBD_DIR
    198     rm -rf $GSDLHOME/$DBI_DBD
    199     rm -rf $GSDLHOME/$DBD_MYSQL
     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
    200248else
    201249    echo "**   Not deleting the $TEMP_DBI_DBD_DIR"
    202250fi
     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.
    203253rm -rf $TEMP_STATIC_LIBS_DIR
    204254
     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
    205263
    206264# go back to where we started
     
    209267echo "*****************************"
    210268echo ""
    211 echo "** You now need to initialize the MySQL installation at $GSDLHOME/$MYSQL_BIN"
     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
    212276echo "** Follow the instructions from STEP 2 ONWARDS at at http://wiki.greenstone.org/doku.php?id=en:user_advanced:greenstonesqlplugs#installing_one_time_setup"
    213277echo "** Once that's done, the same page has information on how to use the GreenstoneSQLPlugs in a collection"
Note: See TracChangeset for help on using the changeset viewer.