sdsphinx/Sphinx.sh

131 lines
4.9 KiB
Bash
Raw Normal View History

2011-10-24 09:07:16 +02:00
#!/bin/bash
2011-10-24 09:45:50 +02:00
#This program as been create by Damien for Scores et decisions ste
#Email : dlasserre@scores-decisions.com
2011-10-24 09:07:16 +02:00
allVersion=("2.0.1" "0.9.9")
2011-10-28 10:29:00 +02:00
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
}
2011-10-24 09:07:16 +02:00
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')
2011-10-24 09:45:50 +02:00
`rm -r indexeConf tmp sphinx-* wget* libste* *~ 2> /dev/null`
2011-10-24 09:07:16 +02:00
echo -e "- Clean directory"
exit
;;
'--version')
echo -e "1. Last version : 2.0.1"
echo -e "2. Past version : 0.9.9\n"
;;
'--install')
2011-10-28 10:29:00 +02:00
#Environement for installation
2011-10-24 09:07:16 +02:00
if [ ! -e /dbs ];then `mkdir /dbs`; dbs="Success"; fi
2011-10-24 09:45:50 +02:00
#repertoire temporaire.
if [ ! -e tmp ];then `mkdir tmp`; fi
##
2011-10-28 10:29:00 +02:00
if [ ! -e /dbs/sphinx ];then echo -e "/dbs/sphinx Doesn't exist !"; exit; fi
if [ ! -e /dbs/sphinxlog ];then echo -e "/dbs/sphinxlog Doesn't exist !"; exit; fi
if [ ! -e /usr/local/sphinx ];then echo -e "/usr/local/sphinx Doesn't exist !"; exit; fi
if [ ! -e /init.d/sphinxsearch ];then `cp initscript/sphinxsearch /etc/init.d/; update-rc.d sphinxsearch defaults`; fi
2011-10-24 09:45:50 +02:00
#Check if package in directory, if you want to download manually the package
2011-10-24 09:07:16 +02:00
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
2011-10-24 09:45:50 +02:00
`tar -z -xf sphinx-$version.tar.gz -C tmp `
2011-10-24 09:07:16 +02:00
`rm sphinx-$version.tar.gz*`
echo -e " - Extract files..."
echo -e " - Complited"
2011-10-28 10:29:00 +02:00
#If libstemmer not installed in tmp/
2011-10-24 09:07:16 +02:00
if [ -e libstemmer_c.tgz ]
then
echo -e $CYAN"Extract file from libstemmer_c..."$NORMAL
2011-10-28 10:29:00 +02:00
`mv libstemmer_c.tgz tmp/sphinx-$version/libstemmer_c; cd tmp/sphinx-$version/libstemmer_c/ ; tar -zxf libstemmer_c.tgz`
2011-10-24 09:07:16 +02:00
echo -e " - Complited"
else
echo -e $CYAN"Download and Configure libstemmer..."$NORMAL
2011-10-24 09:45:50 +02:00
`cd tmp/sphinx-$version ; wget -b http://snowball.tartarus.org/dist/libstemmer_c.tgz > /dev/null`
2011-10-24 09:07:16 +02:00
loadIndication `(ps -C wget -o pid=)`
2011-10-28 10:29:00 +02:00
`cd tmp/sphinx-$version ; tar -zxf libstemmer_c.tgz`
echo -e "- Complited"
2011-10-24 09:07:16 +02:00
fi
echo -e "- Extract files..."
libstemmer="100%"
echo ""
echo -e $CYAN"Configuration progress..."$ROUGE
2011-10-24 09:45:50 +02:00
`cd tmp/sphinx-$version ; sh configure --with-libstemmer --prefix=/usr/local/sphinx 1> /dev/null `
2011-10-24 09:07:16 +02:00
echo -e $NORMAL"- Complited"
echo -e $NORMAL
echo -e $CYAN"Compilation progress..."$ROUGE
2011-10-28 10:29:00 +02:00
#if [ $version != "2.0.1-beta" ];then `cd tmp/sphinx-$version ; make ` ;
#else
#`cd tmp/sphinx-$version/ ; make install 1> /dev/null`;fi
2011-10-24 09:07:16 +02:00
echo -e $NORMAL" - Complited"
echo -n "Machine MASTER ? (y/n) : "; read response
2011-10-28 10:29:00 +02:00
`touch /usr/local/sphinx/sphinx.conf`;
`cat config/${HOSTNAME}/sphinx.conf > /usr/local/sphinx/sphinx.conf`;
if [ $response = 'y' ];then
2011-10-24 09:07:16 +02:00
echo -e $ROUGE"Mode MASTER activated"$NORMAL
2011-10-28 10:29:00 +02:00
`cat config/${HOSTNAME}/*.conf-MysqlServer >> /usr/local/sphinx/sphinx.conf`;
2011-10-24 09:07:16 +02:00
else
echo -e $ROUGE"Mode SLAVE activated"$NORMAL
2011-10-28 10:29:00 +02:00
`cat config/${HOSTNAME}/*.conf-MysqlServerSlave >> /usr/local/sphinx/sphinx.conf`;
2011-10-24 09:07:16 +02:00
fi
2011-10-28 10:29:00 +02:00
echo -e $VERT"The installation as been finish ! great ! thank's damien :)"$NORMAL
exit
2011-10-24 09:07:16 +02:00
;;
'--refresh')
2011-10-28 10:29:00 +02:00
echo -n "Machine MASTER ? (y/n) : "; read response
`touch /usr/local/sphinx/sphinx.conf`;
`cat config/${HOSTNAME}/sphinx.conf > /usr/local/sphinx/sphinx.conf`;
if [ $response = 'y' ];then
echo -e $ROUGE"Mode MASTER activated"$NORMAL
`cat config/${HOSTNAME}/*.conf-MysqlServer >> /usr/local/sphinx/sphinx.conf`;
2011-10-24 09:07:16 +02:00
else
2011-10-28 10:29:00 +02:00
echo -e $ROUGE"Mode SLAVE activated"$NORMAL
`cat config/${HOSTNAME}/*.conf-MysqlServerSlave >> /usr/local/sphinx/sphinx.conf`;
2011-10-24 09:07:16 +02:00
fi
2011-10-28 10:29:00 +02:00
echo -e $VERT"The refresh as been finish ! great ! thank's damien :)"$NORMAL
exit
2011-10-24 09:07:16 +02:00
;;
*)
#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