#!/bin/bash allVersion=("2.0.1" "0.9.9" "2.0.2") declare -A ERREURS declare -A ASTUCES declare -A ASTUCESDEV 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)"); 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 } if [ `id -u` = 0 ] #Need Root or Sudo then commande=('--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 "--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 echo -e "/dbs not exist !"; exit; fi 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 if [ ! -e sphinx-2.0.1.tar.gz ] || [ ! -e sphinx-0.9.9.tar.gz ] || [ ! -e sphinx-2.0.2.tar.gz ] then if [ ! -z $2 ]; then if [ $2 == "2.0.1" ]; then version="$2-beta" elif [ $2 == "0.9.9" ]; then version="$2-beta" elif [ $2 == "2.0.2" ]; 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 -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