quarta-feira, 26 de outubro de 2011

Script para instalação do OCS + GLPI [+NAGIOS]

 

#!/bin/bash
# Qualquer comando que falhe, faz um stop ao script
#set -e

# Trata variáveis não definidas como erros
#set -u


instalar(){
yum -y clean all
yum -y check-update
yum -y update
yum -y install wget
echo "**** wget instalado ****"
echo "**** A descarregar repositorios ****"
wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm http://rpms.famillecollet.com/enterprise/remi-release-5.rpm http://rpms.famillecollet.com/RPM-GPG-KEY-remi
#wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm
#wget http://rpms.famillecollet.com/RPM-GPG-KEY-remi
rpm --import RPM-GPG-KEY-remi
echo "**** A instalar Apache+Mysql+PHP+OCSIventory+GLPI ****"
yum -y install mysql system-config-network* system-config-securitylevel* ocsi* glpi glpi* glpi-* phpMyAdmin ntsys man
#Dar permissão a todos os utilizadores da rede 192.168.1.0 Se a sua rede for outra deve alterar a linha seguinte
sed -i "s/allow from ::1/allow from 192.168.1.0\/24/" /etc/httpd/conf.d/phpMyAdmin.conf


service mysqld restart
chkconfig mysqld on
service httpd restart
chkconfig httpd on

#Desactivar o SELINUX e a firewall do CentOS
sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
chkconfig iptables off
chkconfig ip6tables off
sed -i 's/--disabled/--enabled/g' /etc/sysconfig/system-config-securitylevel


/etc/rc.d/init.d/network restart
service httpd reload


read -p "Introduza a password para a conta do user root do Mysql: " proot
mysqladmin -u root password $proot
echo "Agora entre no browser e corra http://192.168.1.66/ocsreports/install.php"
echo "Depois de instalar o ocs corra de novo este script escolha a configurão da BD para o GLPI"
echo "Só depois deve correr o site http://192.168.1.66/glpi"



}
reiniciar()
{
echo "Para nao reiniciar o computador pressione Ctrl+c, "
echo "porem e recomendavel reinicar."
echo "Para reniciar tecle Enter."
read
echo -n "O computador sera reiniciado em 10 segundos para aplicar as configuracoes realizadas "
for i in `seq 10`
do
clear
echo "+++++++++++++++++++++++++++++++++++++++"
echo""
echo " $i"
echo""
echo "+++++++++++++++++++++++++++++++++++++++"

`sleep 1`
done
`reboot`
}
rede()
{
hostname=" "
echo -n "Digite o hostname > "
read hostname
`echo NETWORKING=yes > /etc/sysconfig/network`
`echo NETWORKING_IPV6=yes >> /etc/sysconfig/network`
`echo HOSTNAME=$hostname >> /etc/sysconfig/network`
`echo '# Do not remove the following line, or various programs' > /etc/hosts`
`echo '# that require network functionality will fail.' >> /etc/hosts`
`echo '127.0.0.1 localhost.localdomain localhost '$hostname'' >> /etc/hosts`
hostname -v $hostname

echo -n "Deseja escolher IP fixo ? [s/n] > "
read opcao
if [ "$opcao" = "s" ]; then
ip=" "
echo -n "Digite o IP [ xxx.xxx.xxx.xxx ] > "
read ip
echo -n "Digite a mascara [ xxx.xxx.xxx.xxx ] > "
read mask
echo -n "Difite o default gateway [ xxx.xxx.xxx.xxx ] > "
read gw
echo -n "Digite o Ip do DNS Server [ xxx.xxx.xxx.xxx ] > "
read ipdns
`echo nameserver $ipdns >> /etc/resolv.conf`
`echo '#Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]' > /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo DEVICE=eth0 >> /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo BOOTPROTO=none >> /etc/sysconfig/network-scripts/ifcfg-eth0`
var=`ifconfig | head -1 | sed 's/ /#/g' | cut -d# -f11`
`echo HWADDR=$var >> /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo IPV6_AUTOCONF=yes >> /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo ONBOOT=yes >> /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo TYPE=Ethernet >> /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo NETMASK=$mask >> /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo IPADDR=$ip >> /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo GATEWAY=$gw >> /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo "O usuario $USER configurou o IP $ip $datevar logado na console $SSH_TTY de $IP;" >> /var/log/script_inicializacao.log`
elif [ "$opcao" = "n" ]; then
echo "Ip atribuito por DHCP"
`echo '#Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]' > /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo DEVICE=eth0 >> /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo BOOTPROTO=dhcp >> /etc/sysconfig/network-scripts/ifcfg-eth0`
var=`ifconfig | head -1 | sed 's/ /#/g' | cut -d# -f11`
`echo HWADDR=$var >> /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo IPV6INIT=yes >> /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo IPV6_AUTOCONF=yes >> /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo ONBOOT=yes >> /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo TYPE=Ethernet >> /etc/sysconfig/network-scripts/ifcfg-eth0`
`echo "O usuario $USER atribuiu IP via DHCP em $datevar logado na console $SSH_TTY de $IP;" >> /var/log/script_inicializacao.log`
fi
#instalar a firewal
install -o root -g root -m 755 firewall /etc/rc.d/init.d
chkconfig --add firewall
service firewall start
chkconfig firewall on

echo -n "Deseja configurar Data? [s/n] > "
read opcao
if [ "$opcao" = "s" ]; then
echo -n "Digite a hora/data no formato [ mm/dd/aaaa hh:mm ] > "
read data
echo " `date -s "$data"` "
datevar=`date`
fi

echo -n "Deseja Reiniciar? [s/n] > "
read opcao

if [ "$opcao" = "s" ]; then
reiniciar
else
/etc/rc.d/init.d/network restart
fi
}
info()
{
clear
vi readme_ConfigurarOCSeGLPI
}
sqlGLPI()
{

echo -n "Já instalou o ocsIventory? [s/n] > "
read opcao
if [ "$opcao" = "n" ]; then
echo "Então entre no browser e corra http://192.168.1.66/ocsreports/install.php"
echo "Depois de instalar o ocs corra de novo este script e reponda que já instalou o ocs"
#mysql --user root -p < ocs.sql
elif [ "$opcao" = "s" ]; then
#read -p "Introduza a password que escolheu para o user OCS: " ocsp
#Password do user ocs: ocssecret
ocsp=ocssecret
texto=`cat /etc/httpd/conf.d/ocsinventory-server.conf | grep 'PerlSetVar OCS_DB_PWD'`
sed -i "s/$texto/PerlSetVar OCS_DB_PWD "$ocsp"/g" /etc/httpd/conf.d/ocsinventory-server.conf
sed -i "s/\"PSWD_BASE\"\]=\"ocs\";/\"PSWD_BASE\"\]=\""$ocsp"\";/g" /etc/ocsinventory/ocsinventory-reports/dbconfig.inc.php

texto=`cat /etc/php.ini | grep "memory_limit"`
texto2=`echo $texto | sed -e "s/[0-9][0-9][mM]/64M/g"`
sed -i "s/$texto/$texto2/g" /etc/php.ini

texto=`cat /etc/php.ini | grep "post_max_size"`
texto2=`echo $texto | sed -e "s/[0-9][mM]/8M/g"`
sed -i "s/$texto/$texto2/g" /etc/php.ini

texto=`cat /etc/php.ini | grep "upload_max_filesize"`
texto2=`echo $texto | sed -e "s/[0-9][mM]/8M/g"`
sed -i "s/$texto/$texto2/g" /etc/php.ini

echo "Introduza a password do user root, definida para o Mysql:"
mysql -uroot -p < glpi.sql
echo " Foram criadas ou alteradas as seguintes contas com para as seguintes passwords "
echo " user:ocs, pass:ocssecret"
echo " user:glpi, pass:glpisecret"
echo " user:synchro, pass:syncsecret"
echo ""
echo " Agora entre no browser e corra http://192.168.1.66/glpi"
fi
}
registar()
{
echo " Vamos registar esta máquina no ocs"
ocsinventory-agent --debug --server=localhost

}
nagios()
{
echo "***** A iniciar a instalação do Nagio: " `date`
echo "***** A instalar os pré-requisitos"
yum -y install httpd
yum -y install gcc
yum -y install glibc glibc-common
yum -y install gd gd-devel

echo "***** A definir o Ambiente"
#Criação do usuário:
useradd -m nagios
echo "PASSWORD" |passwd --stdin nagios

#Agora é preciso criar um grupo que chamaremos de "nagcmd" para permitir que comandos externos sejam passados pela interface web.
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache


echo "***** A Instalar o Nagios"
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm
rpm -Uvh rpmforge-re*.rpm
yum clean all
yum update
yum install nagios nagios-plugin

##make install-webconf

echo "***** A definir a autenticação web"
htpasswd -nb nagiosadmin PASSWORD > /etc/nagios/htpasswd.users
service httpd restart

echo "***** A verificar e corrigir SELINUX"
chcon -R -t httpd_sys_content_t /usr/share/nagios/sbin/
chcon -R -t httpd_sys_content_t /usr/share/nagios/share/

echo "***** A Arrancar o Nagios"
chkconfig --add nagios
chkconfig nagios on
service nagios start

echo "*****Concluido: " `date`





}

i=10
while((i!=0));
do
echo "******************************************************************************"
echo " Selecione o que pretende fazer?"
echo " 0 - Mais informacao"
echo " 1 - Configurar a rede (No final será pedido para reiniciar a maquina)"
echo " 2 - Downlaod do Mysql, Apache, OCSInventory e GLPI e instalacao"
echo " 3 - Preparar a base de dados para o GLPI (so depois de instalar o OCSi"
echo " 4 - Registar a primeira maquina"
echo " 5 - Instalar o nagios"
echo " 9 - Reboot"
echo "******************************************************************************"
echo -n " Escolha a opcao? > "
read i
case $i in
1) rede;;
2) instalar ;;
3) sqlGLPI ;;
0) info ;;
4) registar ;;
5) nagios ;;
9) reiniciar ;;
esac
done

0 comentários :

Enviar um comentário