install.sh 9.15 KB
#!/bin/bash

#-------------------#
# OTMEDIA LIA       #
# Install script    #
# version : 1.1.0   #
#-------------------#

# nyx login name
username=${LOGNAME}

# Color variables
txtred=$(tput setaf 1) # red
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
txtred=$(tput setaf 5) # Purple
txtcyn=$(tput setaf 6) # Cyan
txtwht=$(tput setaf 7) # White
txtrst=$(tput sgr0) # Text reset.
#/color

#
### Global Variables
#
PWD=$(pwd)
OTMEDIA_HOME=$PWD
test=$(arch)
if [ "$test" == "x86_64" ]; then ARCH=".64"; else ARCH=""; fi
#/Global


#
# Put to 0 to disable dependencies of a pass
# and 1 to enable
#
PASS1=1     # First Pass 
PASS2=1     # Second and Third Pass
CONFPASS=1  # Confidence Pass
EXPLOITCONFPASS=1   # SOLR query and trigg

echo -e "\nWill do install for :"
if [ $PASS1 -eq 1 ];then echo "- Pass 1";fi
if [ $PASS2 -eq 1 ];then echo "- Pass 2";fi
if [ $CONFPASS -eq 1 ];then echo "- Confidence Pass";fi
if [ $EXPLOITCONFPASS -eq 1 ];then echo "- Exploit Confidence Pass";fi

#
### CHECK Dependencies ###
#
echo -e "\n\t${txtblu}Check Dependencies${txtrst}\n"

## make
test=$(whereis make)
if [ "$test" == "make:" ]
then
    echo -e "${txtred}ERROR${txtrst} make not found\n You have to install make\n sudo apt-get install make"
    exit 1;
fi
echo -e "make \t ${txtgrn}OK${txtrst}"

## CC
test=$(whereis cc)
if [ "$test" == "cc:" ]
then
    echo -e "${txtred}ERROR${txtrst} cc not found\n You have to install cc\n sudo apt-get install gcc"
    exit 1;
fi
echo -e "cc \t ${txtgrn}OK${txtrst}"

## AVCONV
test=$(whereis avconv)
if [ "$test" == "avconv:" ]
then
    echo -e "${txtred}ERROR${txtrst} avconv not found\n You have to install avconv\n sudo apt-get install libav-tools"
    exit 1;
fi
echo -e "libav-tools : avconv \t ${txtgrn}OK${txtrst}"

## JAVA
test=$(whereis java)
if [ "$test" == "java:" ]
then
    echo -e "${txtred}ERROR${txtrst} java not found\n You have to install java JRE\n sudo apt-get install openjdk-7-jre"
    exit 1;
fi
echo -e "Java : JRE \t ${txtgrn}OK${txtrst}"
test=$(whereis javac)
if [ "$test" == "javac:" ]
then
    echo -e "${txtred}ERROR${txtrst} javac not found\n You have to install java JDK\n sudo apt-get install openjdk-7-jdk"
    exit 1;
fi
echo -e "Java : JDK \t ${txtgrn}OK${txtrst}"

if [ $EXPLOITCONFPASS -eq 1 ]
then
    ## Python
    test=$(whereis python)
    if [ "$test" == "python:" ]
    then
        echo -e "${txtred}ERROR${txtrst} python not found\n You have to install python\n sudo apt-get install python"
        exit 1;
    fi
    echo -e "python : \t ${txtgrn}OK${txtrst}"
    
    ## csh shell
    test=$(whereis csh)
    if [ "$test" == "csh:" ]
    then
        echo -e "${txtred}ERROR${txtrst} csh shell not found\n You have to install csh shell\n sudo apt-get install csh"
        exit 1;
    fi
    echo -e "csh shell : \t ${txtgrn}OK${txtrst}"
fi

## Perl
test=$(whereis perl)
if [ "$test" == "perl:" ]
then
    echo -e "${txtred}ERROR${txtrst} perl not found\n You have to install perl\n sudo apt-get install perl"
    exit 1;
fi
echo -e "perl : \t ${txtgrn}OK${txtrst}"

## iconv
test=$(whereis iconv)
if [ "$test" == "iconv:" ]
then
    echo -e "${txtred}ERROR${txtrst} iconv not found\n You have to install iconv\n sudo apt-cache search iconv"
    exit 1;
fi
echo -e "iconv : \t ${txtgrn}OK${txtrst}"

## SRI LM
if [ -z "$SRILM" ] || [ -z "$MACHINE_TYPE" ]
then
    echo -e "${txtred}ERROR${txtrst} SRILM toolkit variables are not defined (SRILM and MACHINE_TYPE)\n You have to install SRILM Toolkit\n"
    exit 1;
fi
export SRILM_BIN=$SRILM/bin/$MACHINE_TYPE
echo -e "SRILM toolkit : \t ${txtgrn}OK${txtrst}"

### Speeral Configuration ### 

echo -e "\n\t${txtblu}Speeral configuration${txtrst}\n"
read -e -p "Download Speeral bin and data ? (y/n) " speeral
if [ "$speeral" == "y" ]
then
    echo -e "Download Speeral bin and data :"
    scp -r ${username}@nyx:/local/OTMEDIA/OTMEDIA_DATA/Speeral $OTMEDIA_HOME/tools/
fi
echo -e "\n\t${txtblu}Generating Speeral configuration files :${txtrst}\n"
cat $PWD/tools/Speeral/CFG/SpeeralFirstPass.xml.tmp | sed -e "s|<nom>[^<]*</nom>|<nom>$PWD/tools/Speeral/LEX/LEXIQUE_V6.speer</nom>|g" \
    | sed -e "s|<ngramme>[^<]*</ngramme>|<ngramme>$PWD/tools/Speeral/LM/ML_4gOTMEDIA_LEXIQUE_V6</ngramme>|g" \
    | sed -e "s|<binode>[^<]*</binode>|<binode>$PWD/tools/Speeral/LEX/LEXIQUE_V6.speer.bin</binode>|g" \
    > $PWD/tools/Speeral/CFG/SpeeralFirstPass.xml
echo $PWD/tools/Speeral/CFG/SpeeralFirstPass.xml
cat $PWD/tools/Speeral/CFG/SpeeralSecondPass.xml.tmp | sed -e "s|<nom>[^<]*</nom>|<nom>$PWD/tools/Speeral/LEX/LEXIQUE_V6.speer</nom>|g" \
    | sed -e "s|<ngramme>[^<]*</ngramme>|<ngramme>$PWD/tools/Speeral/LM/ML_4gOTMEDIA_LEXIQUE_V6</ngramme>|g" \
    | sed -e "s|<binode>[^<]*</binode>|<binode>$PWD/tools/Speeral/LEX/LEXIQUE_V6.speer.bin</binode>|g" \
    > $PWD/tools/Speeral/CFG/SpeeralSecondPass.xml
echo $PWD/tools/Speeral/CFG/SpeeralSecondPass.xml
cat $PWD/tools/Speeral/CFG/SpeeralThirdPass.xml.tmp | sed -e "s|<nom>[^<]*</nom>|<nom>$PWD/tools/Speeral/LEX/LEXIQUE_V6.speer</nom>|g" \
    | sed -e "s|<ngramme>[^<]*</ngramme>|<ngramme>$PWD/tools/Speeral/LM/ML_4gOTMEDIA_LEXIQUE_V6</ngramme>|g" \
    | sed -e "s|<binode>[^<]*</binode>|<binode>$PWD/tools/Speeral/LEX/LEXIQUE_V6.speer.bin</binode>|g" \
    > $PWD/tools/Speeral/CFG/SpeeralThirdPass.xml
echo $PWD/tools/Speeral/CFG/SpeeralThirdPass.xml


if [ $EXPLOITCONFPASS -eq 1 ]
then
    ### LIA ltbox ###
    echo -e "\t${txtblu}Install lia_ltbox${txtrst}\n"
    export LIA_TAGG_LANG="french"
    export LIA_TAGG="$OTMEDIA_HOME/tools/lia_ltbox/lia_tagg/"
    export LIA_PHON_REP="$OTMEDIA_HOME/tools/lia_ltbox/lia_phon/"
    export LIA_BIGLEX="$OTMEDIA_HOME/tools/lia_ltbox/lia_biglex/"

    ### config lia_phon
    cd $LIA_PHON_REP
    make all > /dev/null
    make ressource > /dev/null
    ### config lia_tagg
    cd $LIA_TAGG
    make all > /dev/null
    make ressource.french > /dev/null
    ### config lia_biglex
    cd $LIA_BIGLEX
    make -f makefile.biglex > /dev/null
    cd $OTMEDIA_HOME


    ### SOLR DB ###
    # Tomcat fisrtly
    test=$(dpkg -l | grep "^ii" | grep tomcat)
    if [ "$test" == "" ]
    then
        echo -e "${txtred}ERROR${txtrst} TOMCAT seems to not be installed)\n You have to install TOMCAT\n"
        #exit 1;
        echo -e "\nTOMCAT : \t ${txtred}NOT OK${txtrst}\n"
    else
        echo -e "\nTOMCAT : \t ${txtgrn}OK${txtrst}\n"
    fi
    # SOLR secondly
    echo -e "\t${txtblu}Install SOLR DB${txtrst}\n"
    echo -e "You will need 300 Go of free space to install SOLR DB"
    read -p "Continue ? (y/n) " solr
    if [ "$solr" == "y" ]
    then

        echo -e "Download SOLR DB\r"
        mkdir -p $OTMEDIA_HOME/tools/SOLR 2> /dev/null
        scp -r ${username}@nyx:/local/OTMEDIA/OTMEDIA_DATA/SOLR/otmedia-2013-04.tar.gz $OTMEDIA_HOME/tools/SOLR
        echo -e "Unzip SOLR DB\r"
        res=0
        res=$(tar -xvzf "$OTMEDIA_HOME/tools/SOLR/otmedia-2013-04.tar.gz" -C "$OTMEDIA_HOME/tools/SOLR/")
        if [ $res -eq 2 ]; then echo " ${txtred}NOT OK${txtrst}";
        else echo " ${txtgrn}OK${txtrst}"; fi
    else
        echo "Skipping SOLR install"
    fi
    read -e -p "Configure SOLR DB server ? (y/n) " solr
    if [ "$solr" == "y" ]
    then
        read -p "Enter SOLR server IP :" ip
        if [ "${ip}" == "" ];then ip="localhost";fi
        echo "machine = \"${ip}\"" > $OTMEDIA_HOME/tools/scripts/solrinfo.py
        read -p "Enter SOLR server port :" port
        if [ "${port}" == "" ]; then port="8080";fi
        echo -e "\n\tSOLR server IP ${ip}"
        echo -e "\tSOLR server port ${port}"
        echo "port = \"${port}\"" >> $OTMEDIA_HOME/tools/scripts/solrinfo.py
    else
        echo "Skipping SOLR DB Configuration"
    fi
    echo -e "\nSee SOLR.INSTALL file for more information\n"
fi

### Set Variables in bashrc ###
cat ~/.bashrc | grep -v "OTMEDIA_HOME" | grep -v "SRILM_BIN" | grep -v "main_tools" > ~/.bashrc.org
#cat ~/.bashrc | grep -v "OTMEDIA_HOME" | grep -v "SRILM_BIN" | grep -v "LIA_TAGG" | grep -v "LIA_PHON" | grep -v "LIA_BIGLEX" > ~/.bashrc.org
cp ~/.bashrc.org ~/.bashrc
export OTMEDIA_HOME=$PWD
echo "export OTMEDIA_HOME=$PWD" >> ~/.bashrc
echo "export PATH=\$PATH:$PWD/main_tools" >> ~/.bashrc
echo "export SRILM_BIN=$SRILM/bin/$MACHINE_TYPE" >> ~/.bashrc
#echo "export LIA_TAGG_LANG=french" >> ~/.bashrc
#echo "export LIA_TAGG=$OTMEDIA_HOME/tools/lia_ltbox/lia_tagg/" >> ~/.bashrc
#echo "export LIA_PHON_REP=$OTMEDIA_HOME/tools/lia_ltbox/lia_phon/" >> ~/.bashrc
#echo "export LIA_BIGLEX=$OTMEDIA_HOME/tools/lia_ltbox/lia_biglex/" >> ~/.bashrc

# set global configuration file 
echo "OTMEDIA_HOME=\"$PWD\"" > $OTMEDIA_HOME/cfg/main_cfg.cfg
echo "ARCH=\"$ARCH\"" >> $OTMEDIA_HOME/cfg/main_cfg.cfg
echo "VERBOSE=0" >> $OTMEDIA_HOME/cfg/main_cfg.cfg
echo "DEBUG=0" >> $OTMEDIA_HOME/cfg/main_cfg.cfg
echo "CHECK=0" >> $OTMEDIA_HOME/cfg/main_cfg.cfg
echo "RERUN=0" >> $OTMEDIA_HOME/cfg/main_cfg.cfg

echo -e "\n\t${txtgrn}### Install completed ###${txtrst}\n"
echo -e "do : source ~/.bashrc"
echo -e "or set variable :\n"
echo "export OTMEDIA_HOME=$PWD"
echo "export PATH=\$PATH:$OTMEDIA_HOME/main_tools"
echo "export SRILM_BIN=$SRILM/bin/$MACHINE_TYPE"


echo "${txtwht}             \\\\ "
echo "        ,-~~~-\\\\_"
echo "       (        .\ "
echo "       @\___(__--'${txtrst}"

echo "${txtgrn}Yes${txtylw}I${txtred}Rastafari${txtrst}"