sdsphinx/Sphinx.sh
Damien LASSERRE de34c57180
2011-10-24 09:58:17 +00:00

232 lines
7.8 KiB
Bash
Executable File

#!/bin/bash
#This program as been create by Damien for Scores et decisions ste
#Email : dlasserre@scores-decisions.com
source Programme/parametres.sh
source Programme/function.sh
allVersion=("2.0.1" "0.9.9")
source='files/description.list'
if [ `id -u` = 0 ] #Need Root or Sudo
then
commande=('--configure' '--install' '--all')
for i; do
case $i in
'--help')
`man SphinxHelp` #en cours de création du man !
;;
'--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')
#Environement for installation
if [ ! -e indexeConf ];then `mkdir indexeConf`; indexeConf="Success"; fi
`touch indexeConf/sphinx.conf`
sphinxconf="Success"
if [ ! -e /dbs ];then `mkdir /dbs`; dbs="Success"; fi
#repertoire temporaire.
if [ ! -e tmp ];then `mkdir tmp`; fi
##
if [ ! -e /dbs/sphinx ];then `mkdir /dbs/sphinx`; sphinx="Success"; fi
if [ ! -e /dbs/sphinxlog ];then `mkdir /dbs/sphinxlog`; sphinxlog="Success"; fi
if [ ! -e /init.d/sphinxsearch ];then `cp initscript/sphinxsearch /etc/init.d/; update-rc.d sphinxsearch defaults`;sphinxinit="Success"; fi
#Check if package in directory, if you want to download manually the package
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
`cd tmp/sphinx-$version ; 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=)`
fi
echo -e "- Extract files..."
`cd tmp/sphinx-$version ; tar -zxf libstemmer_c.tgz`
echo -e "- Complited"
`cd tmp/sphinx-$version ; rm libstemmer_c.tgz`
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 ` ;fi
#Make and install binary.
#`cd tmp/sphinx-$version/ ; make install 1> /dev/null`
echo -e $NORMAL" - Complited"
echo ""
echo -e $CYAN"Visualisation"$NORMAL
echo -e "---------------------------------------------------------------------------------------"
echo -e "2. Directory : indexeConf " $VERT $indexeConf $NORMAL
echo -e "3. Directory : /dbs " $VERT $dbs $NORMAL
echo -e "4. Directory : /dbs/sphinx " $VERT $sphinx $NORMAL
echo -e "5. Directory : /dbs/sphinxlog " $VERT $sphinxlog $NORMAL
echo -e "7. File : indexeConf/sphinx.conf " $VERT $sphinxconf $NORMAL
echo -e "8. File : /init.d/sphinxsearch " $VERT $sphinxinit $NORMAL
if [ ! -z $2 ]; then
if [ $2 == "2.0.1" ] || [ $2 = "0.9.9" ] || [ $2 = "0.9.5" ]; then
echo -e "9. Archive : sphinx-$2-beta.tar.gz "$VERT"100%"$NORMAL
else
echo -e "9. Archive : Version : $2 not exist " $ROUGE "Failed" $NORMAL
fi
fi
echo -e "10. Archive : libstemmer_c.tgz " $VERT $libstemmer $NORMAL
echo -e "11. Compilation : tmp/sphinx-$version/src/libstemmer_c "$VERT"Compiled" $NORMAL
echo -e "12. Compilation : tmp/sphinx-$version/src/ "$VERT"Complited" $NORMAL
echo -e $VERT"Directory and Files as beens creates\n" $NORMAL
echo -n "Machine MASTER ? (y/n) : "; read response
if [ $response = 'y' ];then
MASTER=1
echo -e $ROUGE"Mode MASTER activated"$NORMAL
else
MASTER=0
echo -e $ROUGE"Mode SLAVE activated"$NORMAL
fi
liste=`ls config/${HOSTNAME}`
IFS='.'
`cd config/${HOSTNAME}`
for name in `ls`
do
i=0
for index in name
do
listeIndex[$i]=$index
i=$((i+1))
done
done
echo ${listIndex[0]};exit
`cat files/config.sphinx >> indexeConf/sphinx.conf`
`cp indexeConf/sphinx.conf .`
`cp sphinx.conf /usr/local/sphinx/etc/`;
echo -e $VERT"The installation as been finish ! great ! thank's damien :)"$NORMAL
exit
;;
'--add')
#Add a index
if [ ! -e indexeConf/$2.sphinx.conf ]
then
echo -e $CYAN"Adding index progress..."$NORMAL
`cp files/generic.sphinx.conf indexeConf/$2.sphinx.conf`
`sed -e "s/xindex/$2/g" -i indexeConf/$2.sphinx.conf`
createIndexeFile $2 "true"
echo -e " - Check if this index exist"
echo -e " - Create file in indexeConf/$2.sphinx.conf"
echo -e " - Adding index in sphinx.conf"
echo -e $VERT"Index $2 as been create"$NORMAL
`rm tmp`
`cp indexeConf/sphinx.conf .`
exit
else
echo -e $ROUGE"[Erreur]: This index already exist !"$NORMAL
exit
fi
`cp sphinx.conf /usr/local/sphinx/etc/`;
echo -e $VERT"Configuration started" $NORMAL
;;
'--remove')
#Run all action.
if [ -e indexeConf/$2.sphinx.conf ]
then
echo -e $CYAN"Remove progress..."$NORMAL
`rm indexeConf/$2.sphinx.conf`
`cat indexeConf/* > indexeConf/sphinx.conf`
`cat files/config.sphinx >> indexeConf/sphinx.conf`
echo -e " - Delete file indexeConf/$2.sphinx.conf"
echo -e " - Delete data in sphinx.conf"
echo -e $VERT"Index $2 as been delete"$NORMAL
`rm tmp > /dev/null`
`cp indexeConf/sphinx.conf .`
exit
else
echo -e $ROUGE"[Erreur]: This index: $2 not exist ! impossible to remove !"$NORMAL
exit
fi
;;
'--updateQuery')
if [ ! -z $2 ]
then
echo -e $CYAN"Update Query progress..."$NORMAL
query=`cat $3`
`sed -e "s/#xqueryx/$query/g" -i indexeConf/$2.sphinx.conf`
`cat indexeConf/sphinx.conf > tmp`
`cat indexeConf/$2.sphinx.conf > indexeConf/sphinx.conf`
`cat tmp >> indexeConf/sphinx.conf`
echo -e " - Query as been update in index $2"
echo -e " - Refreshing sphinx.conf"
echo -e $VERT"Operion successfull"$NORMAL
`rm tmp > /dev/null`
`cp indexeConf/sphinx.conf .`
exit;
fi
`cp sphinx.conf /usr/local/sphinx/etc/`;
;;
'--refresh')
if [ -d indexeConf ]
then
`rm indexeConf/*~ 2> /dev/null`
echo -e $CYAN"Refreshing progress..."$NORMAL
directory=`ls indexeConf`
for index in ${directory[*]}
do
echo " - Refreshing : "$index
done
`cat indexeConf/*.sphinx.conf > sphinx.conf`
`cat files/config.sphinx >> sphinx.conf`
echo -e $VERT"Refreshing as been finish"$NORMAL
exit
else
echo -e $ROUGE"[Erreur]: nothing has refresh !"$NORMAL
exit
fi
`cp sphinx.conf /usr/local/sphinx/etc/`;
;;
*)
#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