sdsphinx/Sphinx.sh

137 lines
4.8 KiB
Bash
Raw Permalink Normal View History

2011-10-24 09:07:16 +02:00
#!/bin/bash
2011-12-08 09:33:02 +01:00
allVersion=("2.0.1" "0.9.9" "2.0.2")
2011-10-31 10:53:31 +01:00
declare -A ERREURS
declare -A ASTUCES
2011-11-02 09:09:03 +01:00
declare -A ASTUCESDEV
2011-10-31 10:53:31 +01:00
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"
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)");
2011-10-28 10:29:00 +02:00
function loadIndication() {
while [ -d "/proc/$1" ]
2011-12-08 09:33:02 +01:00
do #Current PID in /proc
2011-10-28 10:29:00 +02:00
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=('--install' '--all')
2011-10-24 09:07:16 +02:00
for i; do
case $i in
'--help')
echo -e $ROUGE"*************************************************************************************************************************************"$NORMAL
2011-11-02 09:09:03 +01:00
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 "--version : Vous retournes les dernieres version disponnibles en téléchargement sur Sphinx."
echo -e $ROUGE"**************************************************************************************************************************************"$NORMAL
exit;
2011-10-24 09:07:16 +02:00
;;
'--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')
if [ ! -e /dbs ];then echo -e "/dbs not exist !"; exit; fi
2011-10-24 09:45:50 +02:00
if [ ! -e tmp ];then `mkdir tmp`; fi
if [ ! -e /dbs/sphinx ];then `mkdir /dbs/sphinx`; fi
if [ ! -e /usr/local/sphinx ];then `mkdir /dbs/sphinx`; fi
if [ ! -e /dbs/sphinxlog ];then `mkdir /dbs/sphinxlog`; 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
2011-12-08 09:33:02 +01:00
if [ ! -e sphinx-2.0.1.tar.gz ] || [ ! -e sphinx-0.9.9.tar.gz ] || [ ! -e sphinx-2.0.2.tar.gz ]
2011-10-24 09:07:16 +02:00
then
if [ ! -z $2 ]; then
if [ $2 == "2.0.1" ]; then
version="$2-beta"
elif [ $2 == "0.9.9" ]; then
2011-12-08 09:33:02 +01:00
version="$2-beta"
elif [ $2 == "2.0.2" ]; then
version="$2"
2011-10-24 09:07:16 +02:00
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-11-02 09:09:03 +01:00
if [ $version != "2.0.1-beta" ];then `cd tmp/sphinx-$version ; make; make install ` ;
else
`cd tmp/sphinx-$version/ ; make; make install`;fi
2011-10-24 09:07:16 +02:00
echo -e $NORMAL" - Complited"
echo -e $VERT"The installation 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