#!/bin/bash # Criado por João Alfredo Knopik Junior # Colaborações: # "William Fernando Merlotto" # "Alexandre Felipe Muller de Souza" set -e # Para caso de erro if [ $UID != 0 ]; then { echo "Este script deve ser executado como superusuario, root ou sudo"; exit 1; } fi apt-get update || { echo "Falha ao atualizar o apt-get"; exit 1; } apt-get install -y dialog debconf-utils ## Mudamos o debconf para critical, para que não sejam feitas perguntas desnecessárias. debconf-set-selections ./arqs-conf/debconf.critical ## Fim da configuração do DebConf BACKTITLE='Instalação do ExpressoLivre 2.0' INTRO=' Bem-Vindo(a) a instalação do ExpressoLivre! 3 (três) perguntas serão feitas a você. - Escolha uma senha. - Escolha uma organização. - Escolha um domínio. Com estas informações o script poderá instalar e configurar o ExpressoLivre. ' #..................................................................... dialog --backtitle "$BACKTITLE" \ --cr-wrap \ --msgbox "$INTRO" \ 17 55 && #..................................................................... LDAP_PWD=$( dialog --stdout --inputbox 'Digite uma senha:' 0 0 ) #..................................................................... ORG=$( dialog --stdout --inputbox 'Digite uma organização:(ex.: celepar)' 0 55 ) #..................................................................... DOMAIN=$( dialog --stdout --inputbox 'Digite seu domínio:(ex.: '$ORG'.com.br)' 0 55 ) #..................................................................... dialog --backtitle "$BACKTITLE" --cr-wrap --msgbox \ "A instalação dos pacotes necessários para o ExpressoLivre começará agora." 10 65 && #..................................................................... apt-get install -y apache2-mpm-prefork libapache2-mod-php5 apache2-utils php5 php5-common php5-dev php5-gd php5-imap php5-ldap php5-pgsql php5-cgi php5-cli slapd ldap-utils db4.2-util cyrus-admin-2.2 cyrus-clients-2.2 cyrus-common-2.2 cyrus-doc-2.2 cyrus-imapd-2.2 libcyrus-imap-perl22 postfix postfix-ldap libsasl2-2 libsasl2-modules sasl2-bin nmap vim libmail-imapclient-perl libparse-recdescent-perl libterm-readkey-perl libterm-readline-perl-perl zip unzip graphviz lsb-base openssl ssl-cert || { echo "Impossível continuar, erro no nome dos pacotes"; exit 1; } ############################################################################################ # GET VARs LDAP_DN=`php ./arqs-conf/makedn.php $DOMAIN` LDAP_DC=`php ./arqs-conf/makedc.php $DOMAIN` LDAP_PWD_MD5=`slappasswd -v -s $LDAP_PWD -h {MD5}` LDAP_PWD_MD5=`php ./arqs-conf/regexp.php $LDAP_PWD_MD5` HEADER_PWD=`php ./arqs-conf/pass.php $LDAP_PWD` ############################################################################################ # APACHE # descomente para gerar o certificado para o https #apache2-ssl-certificate; a2enmod rewrite a2enmod ssl cp -r -p ../../../expresso/ /var/www/ cp ./arqs-conf/etc/apache2/apache2.conf.lenny /etc/apache2/apache2.conf cp ./arqs-conf/etc/apache2/sites-available/default.lenny /etc/apache2/sites-available/expresso cp ./arqs-conf/etc/apache2/ports.conf.lenny /etc/apache2/ports.conf cp -r -p ./arqs-conf/etc/apache2/ssl/ /etc/apache2/ cp ./arqs-conf/etc/php5/apache2/php.ini /etc/php5/apache2/ mkdir /php_sessions/ || { echo "Diretório já existe. [OK]"; } chmod -R 777 /php_sessions/ a2ensite expresso a2dissite default # Linha adicionada para resolver alguns warnings quando "apache2ctl configtest" HOST=`hostname` ; mv /etc/hosts /etc/hosts.ori ; echo 127.0.0.1 $DOMAIN localhost $HOST > /etc/hosts ; cat /etc/hosts.ori >> /etc/hosts ; rm /etc/hosts.ori /etc/init.d/apache2 restart ############################################################################################ # OPENLDAP /etc/init.d/slapd stop sed -e "s/LDAP_DN/$LDAP_DN/g" -e "s/LDAP_PWD_MD5/$LDAP_PWD_MD5/g" ./arqs-conf/etc/ldap/slapd.conf.lenny > /etc/ldap/slapd.conf cp ./arqs-conf/etc/ldap/schema/* /etc/ldap/schema/ rm -rf /var/lib/ldap mkdir /var/lib/ldap chown -R openldap:openldap /var/lib/ldap/ /etc/init.d/slapd start /etc/init.d/slapd stop sleep 2 sed -e "s/LDAP_DN/$LDAP_DN/g" -e "s/LDAP_PWD_MD5/$LDAP_PWD_MD5/g" -e "s/ORG/$ORG/g" -e "s/DOMAIN/$DOMAIN/g" -e "s/LDAP_DC/$LDAP_DC/g" ./arqs-conf/expresso.ldif > /tmp/expresso.ldif sleep 2 slapadd -v -l /tmp/expresso.ldif chown -R openldap. /var/lib/ldap/* sleep 2 /etc/init.d/slapd start rm /tmp/expresso.ldif ############################################################################################ # CYRUS cp ./arqs-conf/etc/imapd.conf /etc/ cp ./arqs-conf/etc/cyrus.conf /etc/ sed -e "s/LDAP_DN/$LDAP_DN/g" ./arqs-conf/etc/saslauthd.conf > /etc/saslauthd.conf cp ./arqs-conf/etc/default/saslauthd-lenny /etc/default/saslauthd cp -p ./arqs-conf/usr/bin/cyradm_expresso /usr/bin/ /etc/init.d/saslauthd restart sleep 4 /etc/init.d/cyrus2.2 restart sleep 4 ./arqs-conf/cyrus.pl $LDAP_PWD ############################################################################################ # POSTFIX sed -e "s/LDAP_DN/$LDAP_DN/g" -e "s/DOMAIN/$DOMAIN/g" ./arqs-conf/etc/postfix/main.cf > /etc/postfix/main.cf sed -e "s/DOMAIN/$DOMAIN/g" ./arqs-conf/etc/postfix/expresso-dominios > /etc/postfix/expresso-dominios cp ./arqs-conf/etc/postfix/master.cf /etc/postfix/ adduser postfix mail /etc/init.d/postfix restart postmap /etc/postfix/expresso-dominios sleep 10 ############################################################################################ # mkpasswd mkdir /home/expressolivre || { echo "Diretório já existe. [OK]"; } cp ./arqs-conf/home/expressolivre/* /home/expressolivre/ chown -R www-data:www-data /home/expressolivre/ ############################################################################################ # HEADER_INC_PHP sed -e "s/HEADER_PWD/$HEADER_PWD/g" ./arqs-conf/header.inc.php > /var/www/expresso/header.inc.php chown www-data:www-data /var/www/expresso/header.inc.php ############################################################################################ # POSTGRES apt-get install -y postgresql postgresql-common postgresql-client postgresql-client-common || { echo "Erro ao iniciar. Sem problema.[OK]";} #parando o serviço e fazendo backup /etc/init.d/postgresql-8.3 stop mv /var/lib/postgresql/8.3/main /var/lib/postgresql/8.3/main_backup_$(date +%s) #alterando o proprietário do diretório temporariamente chown postgres\: /var/lib/postgresql/8.3 su - postgres -c 'export LANG=pt_BR.ISO-8859-1;/usr/lib/postgresql/8.3/bin/initdb -E latin1 -D /var/lib/postgresql/8.3/main' #restaurando o proprietário do diretório chown root\: /var/lib/postgresql/8.3 echo "COPIANDO ARQUIVOS DE CONFIGURACAO DO EXPRESSO PARA O PGSQL...." cp ./arqs-conf/etc/postgresql/8.3/main/postgresql.conf /etc/postgresql/8.3/main/ cp ./arqs-conf/etc/postgresql/8.3/main/pg_hba.conf /etc/postgresql/8.3/main/ /etc/init.d/postgresql-8.3 start su - postgres -c 'dropdb expresso' || { echo "Banco expresso não existia. [OK]"; } su - postgres -c 'createdb -E LATIN1 expresso' || { echo "Problemas na criação do banco expresso. [Falhou]"; exit 1;} sed -e "s/LDAP_DN/$LDAP_DN/g" -e "s/LDAP_PWD/$LDAP_PWD/g" -e "s/ORG/$ORG/g" -e "s/DOMAIN/$DOMAIN/g" ./arqs-conf/expresso.dump > /tmp/expresso.dump su - postgres -c 'psql -f /tmp/expresso.dump expresso' rm /tmp/expresso.dump ##### CREATE WORKFLOW DATABASE cp ./arqs-conf/workflow.dump /tmp su - postgres -c 'psql < /tmp/workflow.dump -U postgres' rm /tmp/workflow.dump #### END CREATE /etc/init.d/postgresql-8.3 restart ############################################################################################ echo Acerta permissoes das pastas crls e temp em /var/www/expresso/security: chown www-data:www-data /var/www/expresso/security/temp chown www-data:www-data /var/www/expresso/logs chown -R www-data:www-data /var/www/expresso/security/crls chown www-data:www-data /var/www/expresso/security/crl_admin/crl_admin.py chmod 755 /var/www/expresso/security/temp chmod 755 /var/www/expresso/security/crls chmod 755 /var/www/expresso/security/crl_admin/crl_admin.py ############################################################################################ ## Mudamos o debconf para high, default do Debian Lenny. debconf-set-selections ./arqs-conf/debconf.high ## Fim da configuração do DebConf dialog --backtitle "$BACKTITLE" --cr-wrap --msgbox "FIM. www.expressolivre.org" 7 55 && echo '.'