sdsphinx/Sphinx.sh
Damien LASSERRE 3aaac41498
2011-11-02 08:24:54 +00:00

212 lines
8.8 KiB
Bash
Executable File

#!/bin/bash
#This program as been create by Damien for Scores et decisions ste
#Email : dlasserre@scores-decisions.com
# Comatible uniquement sous linux
allVersion=("2.0.1" "0.9.9")
declare -A ERREURS
declare -A ASTUCES
#en cours de developpement !
declare -A ASTUCESDEV
#Color declaration
ROUGE="\\033[1;31m"
NORMAL="\\033[0;39m"
CYAN="\\033[1;36m"
VERT="\\033[1;32m"
BOLD="\\033[1m"
UNDERLINE="\\033[4m"
TEXTNONE="\\033[0m"
#Var
dir="Exist"
log="Exist"
dbs="Exist"
sphinx="Exist"
sphinxlog="Exist"
#Tab of erreurs and astuces
ERREURS=(
["CHMOD"]="Execute the script with SUDO or in ROOT"
["DIRECTORY"]="Directory not create"
["CMD"]="This command not exist"
["NOCMD"]="Please enter options")
ASTUCES=(
["CREATE"]="Sphinx --create (prepare l'environement)");
function loadIndication() {
while [ -d "/proc/$1" ]
do #Current PID in /proc |
echo -en "Loading... /\033[1G"; sleep .07
echo -en "Loading... -\033[1G"; sleep .07
echo -en "Loading... / \033[1G"; sleep .07
echo -en "Loading... |\033[1G"; sleep .07
done
}
# Permet de verifier la valider du superadmin sous linux.
if [ `id -u` = 0 ] #Need Root or Sudo
then
commande=('--configure' '--install' '--all')
for i; do
case $i in
'--help')
echo -e $ROUGE"*************************************************************************************************************************************"$NORMAL
echo -e "--install version : Vous permet d'installer configurer et crée les indexe et la libstemmer compilation, installation et configuration";
echo -e "--delete : Vous permet de restaurer les parametres de la machines en supprimer la configuration et l'installation"
echo -e "--help : Vous permet d'acceser a l'aide de SphinxInstall"
echo -e "--refresh : Vous permet de rafraichire les indexes, dans le cas d'une modification des fichier source, exemple BDD ou port, mémoir etc..."
echo -e "--version : Vous retournes les dernieres version disponnibles en téléchargement sur Sphinx."
echo -e $ROUGE"**************************************************************************************************************************************"$NORMAL
exit;
;;
'--delete')
`rm -r indexeConf tmp sphinx-* wget* libste* *~ 2> /dev/null`
echo -e "- Clean directory"
exit
;;
'--version')
echo -e "1. Last version : 2.0.1"
echo -e "2. Past version : 0.9.9\n"
;;
'--install')
if [ ! -e /dbs ];then `mkdir /dbs`; dbs="Success"; fi
if [ ! -e tmp ];then `mkdir tmp`; fi
if [ ! -e /dbs/sphinx ];then echo -e "/dbs/sphinx Doesn't exist !"; exit; fi
if [ ! -e /dbs/sphinxlog ];then `mkdir /dbs/sphinxlog`; exit; fi
if [ ! -e /usr/local/sphinx ];then `mkdir /dbs/sphinx`; exit; fi
if [ ! -e /init.d/sphinxsearch ];then `cp initscript/sphinxsearch /etc/init.d/ > /dev/null` ;`chmod +x /etc/init.d/sphinxsearch > /dev/null`; `update-rc.d sphinxsearch defaults > /dev/null`; fi
if [ ! -e config/${HOSTNAME} ];then `mkdir config/${HOSTNAME}`;fi
if [ ! -e sphinx-2.0.1.tar.gz ] || [ ! -e sphinx-0.9.9.tar.gz ]
then
if [ ! -z $2 ]; then
if [ $2 == "2.0.1" ]; then
version="$2-beta"
elif [ $2 == "0.9.9" ]; then
version="$2"
else
echo -e $ROUGE"[Erreur]: This version not exist !"$NORMAL
exit
fi
echo -e $CYAN"Download Sphinx-$version..."$NORMAL
`wget -b http://sphinxsearch.com/files/sphinx-$version.tar.gz >/dev/null`
loadIndication `(ps -C wget -o pid=)`
`rm wget-log*`
else
echo -e $ROUGE"[Erreur]: Please specifie version, exemple 2.0.1 or 0.9.9"$NORMAL
exit
fi
fi
`tar -z -xf sphinx-$version.tar.gz -C tmp `
`rm sphinx-$version.tar.gz*`
echo -e " - Extract files..."
echo -e " - Complited"
#If libstemmer not installed in tmp/
if [ -e libstemmer_c.tgz ]
then
echo -e $CYAN"Extract file from libstemmer_c..."$NORMAL
`mv libstemmer_c.tgz tmp/sphinx-$version/libstemmer_c; cd tmp/sphinx-$version/libstemmer_c/ ; tar -zxf libstemmer_c.tgz`
echo -e " - Complited"
else
echo -e $CYAN"Download and Configure libstemmer..."$NORMAL
`cd tmp/sphinx-$version ; wget -b http://snowball.tartarus.org/dist/libstemmer_c.tgz > /dev/null`
loadIndication `(ps -C wget -o pid=)`
`cd tmp/sphinx-$version ; tar -zxf libstemmer_c.tgz`
echo -e "- Complited"
fi
echo -e "- Extract files..."
libstemmer="100%"
echo ""
echo -e $CYAN"Configuration progress..."$ROUGE
`cd tmp/sphinx-$version ; sh configure --with-libstemmer --prefix=/usr/local/sphinx 1> /dev/null `
echo -e $NORMAL"- Complited"
echo -e $NORMAL
echo -e $CYAN"Compilation progress..."$ROUGE
if [ $version != "2.0.1-beta" ];then `cd tmp/sphinx-$version ; make; make install ` ;
else
`cd tmp/sphinx-$version/ ; make; make install`;fi
echo -e $NORMAL" - Complited"
echo -n "Machine MASTER ? (y/n) : "; read response
`touch /usr/local/sphinx/etc/sphinx.conf`;
echo -e $ROUGE"Mode MASTER activated"$NORMAL
echo -e "Tapez 'stop' pour quiter l'invite de création des indexes"
while [ indexe != "stop\n" ]; do
echo -e " Entrez indexe : "; read indexe
if [ $response = 'y' ];then
if [ -e config/base/Master/$indexe.conf-MysqlServer ]
then
`cp config/base/Master/$indexe.conf-MysqlServer config/${HOSTNAME}/`
echo -e "Indexe $indexes as been create !";
else
break;
fi
else
if [ -e config/base/Slave/$indexe.conf-MysqlServer ]
then
`cp config/base/Slave/$indexe.conf-MysqlServer config/${HOSTNAME}/`
echo -e "Indexe ''$indexes'' as been create !";
else
break;
fi
fi
done;
`cat config/base/sphinx.conf > /usr/local/sphinx/etc/sphinx.conf `;
`cat config/${HOSTNAME}/*.conf-MysqlServer >> /usr/local/sphinx/etc/sphinx.conf`;
`./Sphinx --refresh`
echo -e $VERT"The installation as been finish ! great ! thank's damien :)"$NORMAL
exit
;;
'--refresh')
`cat config/base/sphinx.conf > /usr/local/sphinx/etc/sphinx.conf`
`cat config/${HOSTNAME}/* >> /usr/local/sphinx/etc/sphinx.conf`
echo -e $VERT"The refresh as been finish ! great ! thank's damien :)"$NORMAL
exit
;;
'--add')
`mkdir config/${HOSTANME}`
echo -n "Machine MASTER ? (y/n) : "; read response
`touch /usr/local/sphinx/etc/sphinx.conf`;
echo -e $ROUGE"Mode MASTER activated"$NORMAL
echo -e "Tapez 'stop' pour quiter l'invite de création des indexes"
while [ indexe != "stop\n" ]; do
echo -e " Entrez indexe : "; read indexe
if [ $response = 'y' ];then
if [ -e config/base/Master/$indexe.conf-MysqlServer ]
then
`cp config/base/Master/$indexe.conf-MysqlServer config/${HOSTNAME}/`
echo -e "Indexe $indexes as been create !";
else
break;
fi
else
if [ -e config/base/Slave/$indexe.conf-MysqlServer ]
then
`cp config/base/Slave/$indexe.conf-MysqlServer config/${HOSTNAME}/`
echo -e "Indexe ''$indexes'' as been create !";
else
break;
fi
fi
done;
`cat config/base/sphinx.conf > /usr/local/sphinx/etc/sphinx.conf `;
`cat config/${HOSTNAME}/*.conf-MysqlServer >> /usr/local/sphinx/etc/sphinx.conf`;
`./Sphinx --refresh`
echo -e $VERT"The installation as been finish ! great ! thank's damien :)"$NORMAL
exit
;;
*)
#Default
echo -e $ROUGE"[Erreur]" ${ERREURS["CMD"]} $NORMAL
exit
;;
esac
done
echo -e $ROUGE"[Erreur]" ${ERREURS["NOCMD"]} $NORMAL
else
echo -e $ROUGE"[Erreur]" ${ERREURS["CHMOD"]} $NORMAL
fi