You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

265 lines
9.2 KiB

#!/bin/bash
trap "" 2 20
#
verifica_erro()
{
RESULTADO=$1
MODULO=$2
TIPO=$3
if [ "$RESULTADO" != "0" ] ; then
clear
if [ "$TIPO" = "DESINSTALAR" ] ; then
echo "Erro durante a desinstalacao do Modulo $MODULO"
else
echo "Erro durante a instalacao do Modulo $MODULO, favor verificar as dependencias"
fi
/bin/rm -rf /tmp/install_simplesip.pid
exit $RESULTADO
fi
}
#Descobrindo o caminho do script
dir=$(dirname $0)
path_arquivo=$(cd $dir;pwd)
arquitetura=$(uname -m)
log=/var/log/instaladores_simplesip.log
versao_linux=$(cat /etc/redhat-release | sed 's/[a-zA-Z() ]//g' | cut -d "." -f 1)
[ -e $path_arquivo/dependencias_simplesip.txt ] && pacotes_centos=$(cat $path_arquivo/dependencias_simplesip.txt)
declare -x data=$(date +%F-%H-%M-%S)
#Verifica se o script esta rodando
if [ -e /tmp/install_simplesip.pid ] ; then
clear
echo "Script em Excecucao..."
exit
fi
#Gera PID do scritp
echo $$ > /tmp/install_simplesip.pid
#Realizando backup da pasta de gravacoes
if [ -d /var/spool/asterisk/monitor ] ; then
cd /var/spool/asterisk/monitor/
raiz_monitor=$(pwd -P | cut -d "/" -f2)
if [ "$raiz_monitor" = "var" ] ; then
mkdir -p /hdaux/gravacoes-$data
/bin/mv -f /var/spool/asterisk/monitor /hdaux/gravacoes-$data/
else
mkdir -p /$raiz_monitor/gravacoes-$data
/bin/mv -f /var/spool/asterisk/monitor /$raiz_monitor/gravacoes-$data/
fi
fi
[ -d /etc/asterisk ] && /bin/cp -Rapf /etc/asterisk /tmp/etc_asterisk-$data
[ -d /var/lib/asterisk ] && /bin/cp -Rapf /var/lib/asterisk /tmp/var_lib_asterisk-$data
[ -L /usr/src/libpri ] && unlink /usr/src/libpri
[ -L /usr/src/asterisk ] && unlink /usr/src/asterisk
#Desistalando Pacotes anteriores
if [ 0 -ne $(find /usr/src/ -name "channel*.sh" | wc -l) ] ; then
echo "Desinstalando KHOMP"
bash $(find /usr/src/ -name "channel*.sh" | sort | tail -n1 | xargs ls -1tr | tail -n1) -j
RESULT=$?
verifica_erro $RESULT KHOMP DESINSTALAR
fi
if [ 0 -ne $(find /usr/src -name "spandsp-*" -type d -print | wc -l) ] ; then
echo "Desinstalando SPANDSP"
cd $(find /usr/src -name "spandsp-*" -type d -print | xargs ls -d1tr | tail -n1)
make uninstall >> $log 2>&1
RESULT=$?
verifica_erro $RESULT SPANDSP DESINSTALAR
fi
if [ 0 -ne $(find /usr/src -name "libpri-*" -type d -print | wc -l) ] ; then
echo "Desinstalando LIBPRI"
cd $(find /usr/src -name "libpri-*" -type d -print | xargs ls -d1tr | tail -n1)
make uninstall >> $log 2>&1
RESULT=$?
verifica_erro $RESULT LIBPRI DESINSTALAR
fi
if [ 0 -ne $(find /usr/src -name "dahdi-linux-*" -type d -print | wc -l) ] ; then
echo "Desinstalando DAHDI"
cd $(find /usr/src -name "dahdi-linux-*" -type d -print | xargs ls -d1tr | tail -n1)/linux/
make uninstall >> $log 2>&1
RESULT=$?
verifica_erro $RESULT DAHDI DESINSTALAR
fi
if [ 0 -ne $(find /usr/src -name "asterisk-*" -type d -print | wc -l) ] ; then
echo "Desinstalando ASTERISK"
cd $(find /usr/src -name "asterisk-*" -type d -print | xargs ls -d1tr | tail -n1)
make uninstall-all >> $log 2>&1
RESULT=$?
verifica_erro $RESULT ASTERISK DESINSTALAR
fi
[ -e /etc/init.d/vlibd ] && chkconfig --level 35 vlibd off && rm -rf /etc/init.d/vlibd
[ -e /etc/init.d/dgvfifo ] && chkconfig --level 35 dgvfifo off && rm -rf /etc/init.d/dgvfifo
[ -e /etc/init.d/dahdi ] && chkconfig --level 35 dahdi off && rm -rf /etc/init.d/dahdi
[ -e /etc/init.d/khomp-services ] && chkconfig --level 35 khomp-services off && rm -rf /etc/init.d/khomp-services
[ -L /usr/src/libpri ] && unlink /usr/src/libpri
[ -L /usr/src/asterisk ] && unlink /usr/src/asterisk
/bin/rm -rf /usr/src/instaladores
/bin/rm -rf /usr/src/asterisk*
/bin/rm -rf /usr/src/libpri*
/bin/rm -rf /usr/src/dahdi*
/bin/rm -rf /usr/src/spandsp*
/bin/rm -rf /usr/src/channel_*
/bin/rm -rf /usr/src/usr/src/openr2-*
/bin/rm -rf /etc/asterisk
/bin/rm -rf /var/lib/asterisk
/bin/rm -rf /usr/lib/asterisk
mkdir -p /usr/src/instaladores
#Iniciando Instalacao
cd $path_arquivo/
/bin/cp -Rapf *.gz /usr/src/instaladores/
/bin/cp -Rapf pjproject-* /usr/src/instaladores/
if [ -e $path_arquivo/dependencias_simplesip.txt ] ; then
clear
echo "##########################################"
echo "# VERIFICANDO DEPENDENCIAS #"
echo "##########################################"
[ $versao_linux -ne 7 ] && pacotes_centos=$(cat $path_arquivo/dependencias_simplesip.txt | grep -v "libsqlite3x-devel")
for i in $pacotes_centos ; do [ -z "$(rpm -qa | grep ^$i)" ] && echo "Falta o pacote $i" && DEPENDENCIA=1; done
if [ "$DEPENDENCIA" == "1" ] ; then
echo ""
echo ""
echo "Instale os pacotes acima para continuar"
/bin/rm -rf /tmp/install_simplesip.pid
exit 1
fi
fi
if [ "$arquitetura" = "i686" ] ; then
/bin/cp -Rapf khomp/*i686*.gz /usr/src/instaladores/
else
/bin/cp -Rapf khomp/*64*.gz /usr/src/instaladores/
fi
echo "/usr/local" > /etc/ld.so.conf.d/spandsp.conf
echo "/usr/local/lib" >> /etc/ld.so.conf.d/spandsp.conf
dahdi=$(ls -1 /usr/src/instaladores/dahdi-*.tar.gz 2> /dev/null)
if [ -f "$dahdi" ] ; then
echo "Instalando DAHDI"
sleep 1
tar -zxf /usr/src/instaladores/dahdi-*.tar.gz -C /usr/src
RESULT=$?
verifica_erro $RESULT DESCOMPACTANDO_DAHDI
cd /usr/src/dahdi-*
make clean >> $log 2>&1
make all >> $log 2>&1
make install >> $log 2>&1
RESULT=$?
verifica_erro $RESULT DAHDI_INSTALL
make config >> $log 2>&1
RESULT=$?
verifica_erro $RESULT DAHDI_CONFIG
/bin/cp -Rapf /etc/dahdi/modules /etc/dahdi/modules.ori
echo "" > /etc/dahdi/modules
fi
libpri=$(ls -1 /usr/src/instaladores/libpri-*.tar.gz 2> /dev/null)
if [ -f "$libpri" ] ; then
echo "Instalando LIBPRI"
sleep 1
tar -zxf /usr/src/instaladores/libpri-*.tar.gz -C /usr/src
RESULT=$?
verifica_erro $RESULT DESCOMPACTANDO_LIBPRI
ln -s $(find /usr/src -name "libpri-1*" -type d -print) /usr/src/libpri
cd /usr/src/libpri-*
make clean >> $log 2>&1
make >> $log 2>&1
make install >> $log 2>&1
RESULT=$?
verifica_erro $RESULT LIBPRI
fi
asterisk=$(ls -1 /usr/src/instaladores/asterisk-*.tar.gz 2> /dev/null)
if [ -f "$asterisk" ] ; then
echo "Instalando ASTERISK"
sleep 1
/bin/rm -rf /tmp/pjproject-*
/bin/cp -Rapf /usr/src/instaladores/pjproject-* /tmp/
tar -zxf /usr/src/instaladores/asterisk-*.tar.gz -C /usr/src
RESULT=$?
verifica_erro $RESULT DESCOMPACTANDO_ASTERISK
ln -s $(find /usr/src -name "asterisk-*" -type d -print) /usr/src/asterisk
cd /usr/src/asterisk-*
make clean >> $log 2>&1
./configure --prefix=/usr --libdir=/usr/lib$(getconf LONG_BIT | grep "64") --with-pjproject-bundled >> $log 2>&1
make >> $log 2>&1
make install >> $log 2>&1
RESULT=$?
verifica_erro $RESULT ASTERISK_INSTALL
make samples >> $log 2>&1
make config >> $log 2>&1
RESULT=$?
verifica_erro $RESULT ASTERISK_CONFIG
#Colocando o asterisk na inicializacao do servidor
/bin/mv -f /etc/init.d/asterisk /etc/init.d/rc.pbx
if [ "$versao_linux" = "7" ] ; then
/bin/systemctl enable rc.pbx.service
/bin/systemctl enable dahdi.service
else
LINHA=$(cat -n /etc/init.d/rc.pbx | egrep "start\(\) {" | grep -v "restart" | awk {'print $1'})
sed -i "$LINHA a\sleep 30 #Bug psql no centos6" /etc/init.d/rc.pbx
sed -i "39s/$/sleep 30/" /etc/init.d/rc.pbx
chkconfig --add rc.pbx
chkconfig --add dahdi
chkconfig --level 35 rc.pbx on
chkconfig --level 35 dahdi on
fi
#Codec
cd $path_arquivo/
[ -d codec ] && /bin/cp -Rapf codec/$arquitetura/codec*.so /usr/lib$(getconf LONG_BIT | grep "64")/asterisk/modules/
fi
khomp=$(ls -1 /usr/src/instaladores/channel_*.gz 2> /dev/null)
if [ -f "$khomp" ] ; then
echo "Instalando KHOMP"
sleep 1
cp -Rap /usr/src/instaladores/channel_*.gz /usr/src/
cd /usr/src
gzip -d channel_*.sh.gz
RESULT=$?
verifica_erro $RESULT KHOMP_GZIP
printf 'y\n' | bash channel_*.sh >> $log 2>&1
RESULT=$?
verifica_erro $RESULT KHOMP_BASH_CHANNEL
echo "noload => chan_khomp.so" >> /etc/asterisk/modules.conf
fi
sleep 2
rm -rf /usr/src/instaladores
if [ "$path_arquivo" != "/usr/src/instaladores_simplesip" ] ; then
[ -d /usr/src/instaladores_simplesip ] && rm -rf /usr/src/instaladores_simplesip
/bin/mv -f $path_arquivo /usr/src/
rm -rf $path_arquivo*.tar.gz
fi
[ -d /tmp/etc_asterisk-$data ] && /bin/mv -f /tmp/etc_asterisk-$data/* /etc/asterisk/
[ -d /tmp/var_lib_asterisk-$data ] && for i in $(ls -1 /tmp/var_lib_asterisk-$data/) ; do /bin/rm -rf /var/lib/asterisk/$i && /bin/mv -f /tmp/var_lib_asterisk-$data/$i /var/lib/asterisk/ ; done
[ -e /root/original-ks.cfg ] && /bin/rm -rf /root/original-ks.cfg
[ -e /root/anaconda-ks.cfg ] && /bin/rm -rf /root/anaconda-ks.cfg
[ -e /root/install.log ] && /bin/rm -rf /root/install.log
[ -e /root/install.log.syslog ] && /bin/rm -rf /root/install.log.syslog
[ -e /root/script_pos2.log ] && /bin/rm -rf /root/script_pos2.log
rm -rf /tmp/install_simplesip.pid