[685] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | # Criado por João Alfredo Knopik Junior <jakjr@celepar.pr.gov.br> |
---|
| 4 | # Colaborações: |
---|
| 5 | # "William Fernando Merlotto" <william@prognus.com.br> |
---|
| 6 | # "Alexandre Felipe Muller de Souza" <amuller@celepar.pr.gov.br> |
---|
| 7 | |
---|
| 8 | set -e # Para caso de erro |
---|
| 9 | |
---|
| 10 | if [ $UID != 0 ]; then { |
---|
| 11 | echo "Este script deve ser executado como superusuario, root ou sudo"; |
---|
| 12 | exit 1; |
---|
| 13 | } |
---|
| 14 | fi |
---|
| 15 | |
---|
| 16 | apt-get update || { echo "Falha ao atualizar o apt-get"; exit 1; } |
---|
| 17 | |
---|
| 18 | apt-get install -y dialog debconf-utils |
---|
| 19 | |
---|
| 20 | ## Mudamos o debconf para critical, para que não sejam feitas perguntas desnecessárias. |
---|
| 21 | debconf-set-selections ./arqs-conf/debconf.critical |
---|
| 22 | ## Fim da configuração do DebConf |
---|
| 23 | |
---|
[1331] | 24 | BACKTITLE='Instalação do ExpressoLivre 2.0' |
---|
[685] | 25 | INTRO=' |
---|
| 26 | Bem-Vindo(a) a instalação do ExpressoLivre! |
---|
| 27 | |
---|
| 28 | 3 (três) perguntas serão feitas a você. |
---|
| 29 | - Escolha uma senha. |
---|
| 30 | - Escolha uma organização. |
---|
| 31 | - Escolha um domÃnio. |
---|
| 32 | |
---|
| 33 | Com estas informações o script poderá |
---|
| 34 | instalar e configurar o ExpressoLivre. |
---|
| 35 | ' |
---|
| 36 | #..................................................................... |
---|
| 37 | dialog --backtitle "$BACKTITLE" \ |
---|
| 38 | --cr-wrap \ |
---|
| 39 | --msgbox "$INTRO" \ |
---|
| 40 | 17 55 && |
---|
| 41 | #..................................................................... |
---|
| 42 | LDAP_PWD=$( dialog --stdout --inputbox 'Digite uma senha:' 0 0 ) |
---|
| 43 | #..................................................................... |
---|
| 44 | ORG=$( dialog --stdout --inputbox 'Digite uma organização:(ex.: celepar)' 0 55 ) |
---|
| 45 | #..................................................................... |
---|
| 46 | DOMAIN=$( dialog --stdout --inputbox 'Digite seu domÃnio:(ex.: '$ORG'.com.br)' 0 55 ) |
---|
| 47 | |
---|
| 48 | #..................................................................... |
---|
| 49 | dialog --backtitle "$BACKTITLE" --cr-wrap --msgbox \ |
---|
| 50 | "A instalação dos pacotes necessários para o ExpressoLivre começará agora." 10 65 && |
---|
| 51 | #..................................................................... |
---|
| 52 | |
---|
[745] | 53 | 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; } |
---|
[685] | 54 | |
---|
| 55 | ############################################################################################ |
---|
| 56 | # GET VARs |
---|
| 57 | LDAP_DN=`php ./arqs-conf/makedn.php $DOMAIN` |
---|
| 58 | LDAP_DC=`php ./arqs-conf/makedc.php $DOMAIN` |
---|
| 59 | LDAP_PWD_MD5=`slappasswd -v -s $LDAP_PWD -h {MD5}` |
---|
| 60 | LDAP_PWD_MD5=`php ./arqs-conf/regexp.php $LDAP_PWD_MD5` |
---|
| 61 | HEADER_PWD=`php ./arqs-conf/pass.php $LDAP_PWD` |
---|
| 62 | ############################################################################################ |
---|
| 63 | # APACHE |
---|
| 64 | # descomente para gerar o certificado para o https |
---|
| 65 | #apache2-ssl-certificate; |
---|
| 66 | |
---|
[2937] | 67 | a2enmod rewrite |
---|
| 68 | a2enmod ssl |
---|
[685] | 69 | |
---|
| 70 | cp -r -p ../../../expresso/ /var/www/ |
---|
[2937] | 71 | cp ./arqs-conf/etc/apache2/apache2.conf.lenny /etc/apache2/apache2.conf |
---|
| 72 | cp ./arqs-conf/etc/apache2/sites-available/default.lenny /etc/apache2/sites-available/expresso |
---|
| 73 | cp ./arqs-conf/etc/apache2/ports.conf.lenny /etc/apache2/ports.conf |
---|
[1113] | 74 | cp -r -p ./arqs-conf/etc/apache2/ssl/ /etc/apache2/ |
---|
[685] | 75 | |
---|
| 76 | cp ./arqs-conf/etc/php5/apache2/php.ini /etc/php5/apache2/ |
---|
| 77 | mkdir /php_sessions/ || { echo "Diretório já existe. [OK]"; } |
---|
| 78 | chmod -R 777 /php_sessions/ |
---|
| 79 | |
---|
[2937] | 80 | a2ensite expresso |
---|
| 81 | a2dissite default |
---|
| 82 | |
---|
| 83 | # Linha adicionada para resolver alguns warnings quando "apache2ctl configtest" |
---|
| 84 | 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 |
---|
| 85 | |
---|
[685] | 86 | /etc/init.d/apache2 restart |
---|
| 87 | |
---|
| 88 | ############################################################################################ |
---|
| 89 | # OPENLDAP |
---|
| 90 | /etc/init.d/slapd stop |
---|
| 91 | 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 |
---|
| 92 | cp ./arqs-conf/etc/ldap/schema/* /etc/ldap/schema/ |
---|
| 93 | rm -rf /var/lib/ldap |
---|
| 94 | mkdir /var/lib/ldap |
---|
[2937] | 95 | chown -R openldap:openldap /var/lib/ldap/ |
---|
[685] | 96 | /etc/init.d/slapd start |
---|
| 97 | /etc/init.d/slapd stop |
---|
| 98 | |
---|
| 99 | sleep 2 |
---|
| 100 | 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 |
---|
| 101 | |
---|
| 102 | sleep 2 |
---|
| 103 | slapadd -v -l /tmp/expresso.ldif |
---|
| 104 | chown -R openldap. /var/lib/ldap/* |
---|
| 105 | |
---|
| 106 | sleep 2 |
---|
| 107 | /etc/init.d/slapd start |
---|
| 108 | rm /tmp/expresso.ldif |
---|
| 109 | ############################################################################################ |
---|
| 110 | # CYRUS |
---|
| 111 | cp ./arqs-conf/etc/imapd.conf /etc/ |
---|
| 112 | cp ./arqs-conf/etc/cyrus.conf /etc/ |
---|
| 113 | sed -e "s/LDAP_DN/$LDAP_DN/g" ./arqs-conf/etc/saslauthd.conf > /etc/saslauthd.conf |
---|
| 114 | cp ./arqs-conf/etc/default/saslauthd-lenny /etc/default/saslauthd |
---|
| 115 | |
---|
| 116 | cp -p ./arqs-conf/usr/bin/cyradm_expresso /usr/bin/ |
---|
| 117 | |
---|
| 118 | /etc/init.d/saslauthd restart |
---|
| 119 | sleep 4 |
---|
| 120 | |
---|
| 121 | /etc/init.d/cyrus2.2 restart |
---|
| 122 | |
---|
| 123 | sleep 4 |
---|
| 124 | ./arqs-conf/cyrus.pl $LDAP_PWD |
---|
| 125 | |
---|
| 126 | ############################################################################################ |
---|
| 127 | # POSTFIX |
---|
| 128 | sed -e "s/LDAP_DN/$LDAP_DN/g" -e "s/DOMAIN/$DOMAIN/g" ./arqs-conf/etc/postfix/main.cf > /etc/postfix/main.cf |
---|
| 129 | sed -e "s/DOMAIN/$DOMAIN/g" ./arqs-conf/etc/postfix/expresso-dominios > /etc/postfix/expresso-dominios |
---|
| 130 | cp ./arqs-conf/etc/postfix/master.cf /etc/postfix/ |
---|
| 131 | adduser postfix mail |
---|
| 132 | /etc/init.d/postfix restart |
---|
| 133 | postmap /etc/postfix/expresso-dominios |
---|
| 134 | |
---|
| 135 | sleep 10 |
---|
| 136 | |
---|
| 137 | ############################################################################################ |
---|
| 138 | # mkpasswd |
---|
| 139 | mkdir /home/expressolivre || { echo "Diretório já existe. [OK]"; } |
---|
| 140 | cp ./arqs-conf/home/expressolivre/* /home/expressolivre/ |
---|
[2937] | 141 | chown -R www-data:www-data /home/expressolivre/ |
---|
[685] | 142 | ############################################################################################ |
---|
| 143 | # HEADER_INC_PHP |
---|
| 144 | sed -e "s/HEADER_PWD/$HEADER_PWD/g" ./arqs-conf/header.inc.php > /var/www/expresso/header.inc.php |
---|
[2937] | 145 | chown www-data:www-data /var/www/expresso/header.inc.php |
---|
[685] | 146 | |
---|
| 147 | ############################################################################################ |
---|
[745] | 148 | # POSTGRES |
---|
| 149 | apt-get install -y postgresql postgresql-common postgresql-client postgresql-client-common || { echo "Erro ao iniciar. Sem problema.[OK]";} |
---|
| 150 | #parando o serviço e fazendo backup |
---|
| 151 | /etc/init.d/postgresql-8.3 stop |
---|
| 152 | mv /var/lib/postgresql/8.3/main /var/lib/postgresql/8.3/main_backup_$(date +%s) |
---|
[685] | 153 | |
---|
[745] | 154 | #alterando o proprietário do diretório temporariamente |
---|
[2937] | 155 | chown postgres:postgres /var/lib/postgresql/8.3 |
---|
[745] | 156 | |
---|
| 157 | 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' |
---|
| 158 | |
---|
| 159 | #restaurando o proprietário do diretório |
---|
[2937] | 160 | chown root:root /var/lib/postgresql/8.3 |
---|
[745] | 161 | echo "COPIANDO ARQUIVOS DE CONFIGURACAO DO EXPRESSO PARA O PGSQL...." |
---|
| 162 | cp ./arqs-conf/etc/postgresql/8.3/main/postgresql.conf /etc/postgresql/8.3/main/ |
---|
| 163 | cp ./arqs-conf/etc/postgresql/8.3/main/pg_hba.conf /etc/postgresql/8.3/main/ |
---|
| 164 | /etc/init.d/postgresql-8.3 start |
---|
| 165 | |
---|
| 166 | su - postgres -c 'dropdb expresso' || { echo "Banco expresso não existia. [OK]"; } |
---|
| 167 | su - postgres -c 'createdb -E LATIN1 expresso' || { echo "Problemas na criação do banco expresso. [Falhou]"; exit 1;} |
---|
| 168 | |
---|
| 169 | 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 |
---|
| 170 | |
---|
| 171 | su - postgres -c 'psql -f /tmp/expresso.dump expresso' |
---|
| 172 | |
---|
| 173 | rm /tmp/expresso.dump |
---|
| 174 | |
---|
[1255] | 175 | ##### CREATE WORKFLOW DATABASE |
---|
| 176 | cp ./arqs-conf/workflow.dump /tmp |
---|
| 177 | su - postgres -c 'psql < /tmp/workflow.dump -U postgres' |
---|
| 178 | rm /tmp/workflow.dump |
---|
| 179 | #### END CREATE |
---|
| 180 | |
---|
[745] | 181 | /etc/init.d/postgresql-8.3 restart |
---|
| 182 | |
---|
[1113] | 183 | ############################################################################################ |
---|
[1174] | 184 | echo Acerta permissoes das pastas crls e temp em /var/www/expresso/security: |
---|
| 185 | chown www-data:www-data /var/www/expresso/security/temp |
---|
[1113] | 186 | chown www-data:www-data /var/www/expresso/logs |
---|
[1174] | 187 | chown -R www-data:www-data /var/www/expresso/security/crls |
---|
[2937] | 188 | chown www-data:www-data /var/www/expresso/security/crl_admin/crl_admin.py |
---|
[1174] | 189 | chmod 755 /var/www/expresso/security/temp |
---|
| 190 | chmod 755 /var/www/expresso/security/crls |
---|
| 191 | chmod 755 /var/www/expresso/security/crl_admin/crl_admin.py |
---|
[745] | 192 | |
---|
[1113] | 193 | ############################################################################################ |
---|
| 194 | |
---|
[685] | 195 | ## Mudamos o debconf para high, default do Debian Etch. |
---|
| 196 | debconf-set-selections ./arqs-conf/debconf.high |
---|
| 197 | ## Fim da configuração do DebConf |
---|
| 198 | |
---|
| 199 | dialog --backtitle "$BACKTITLE" --cr-wrap --msgbox "FIM. www.expressolivre.org" 7 55 && |
---|
| 200 | |
---|
| 201 | echo '.' |
---|