#!/bin/bash

#########################################################################################
# PhP, Apache, PhPMyAdmin:
#########################################################################################

# Pacotes comuns:
/usr/bin/apt-get clean
/usr/bin/apt-get update -y
/usr/bin/apt-get upgrade -y
/usr/bin/apt-get install wput mc make cmake zip unzip dosfstools make build-essential gcc gpp htop git bc -q -y

# Servidor Apache e PhP(cmd) e PhPMysql lib:
/usr/bin/apt-get install apache2 php php-mysql libapache2-mod-php -q -y

# Instalar o PhPMyAdmin na Raspberry Pi:
/usr/bin/apt-get install phpmyadmin -y
# Quadro de instalação:
# 1) Selecionar Apache2 (barra de espeço para marcar, tecla tab, tecla enter)
# 2) Configuring phpmyadmin - Configure database for phpmyadmin with dbconfig-common? Yes (tecla enter) 
# 3) Type your MySql Root Password, tecla tab, tecla enter no OK
# 4) MySql Root Password Confirmation, tecla tab, tecla enter no OK
/usr/sbin/phpenmod mysqli
/usr/sbin/service apache2 restart
/bin/ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
/usr/bin/mysql -u root -pmysqllt38c -Bse "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'mysqllt38c' WITH GRANT OPTION;"

# Diretório padrão:
cd /var/www/html

# Esvazia o cache de pacotes:
/usr/bin/apt-get clean

# Ativar / habilitar short tags do PHP (padrão atual OFF):
/bin/cp /etc/php/7.0/apache2/php.ini /etc/php/7.0/apache2/php.bkp
/bin/sed -i 's/short_open_tag = Off/short_open_tag = On/' /etc/php/7.0/apache2/php.ini
/bin/cp /etc/php/7.0/cli/php.ini /etc/php/7.0/cli/php.bkp
/bin/sed -i 's/short_open_tag = Off/short_open_tag = On/' /etc/php/7.0/cli/php.ini

#####################################################################################################
# Instalando o Serviço Very Secure FTPD:
#####################################################################################################
/usr/bin/apt-get install vsftpd -y

#Editar o arquivo: /etc/vsftpd.conf
/bin/cp /etc/vsftpd.conf /etc/vsftpd.conf.bkp

#Desativar o acesso “anônimo”
#anonymouse_enable=NO (já está bloqueado por padrão)
 
#Permitir o acesso dos utilizadores locais (criados no linux)
#local_enable=YES (já está Liberado por padrão)
#write_enable=YES
/bin/sed -i 's/#write_enable=YES/write_enable=YES/' /etc/vsftpd.conf
 
#Alterar Banner do serviço
#ftpd_banner=Welcome to blah FTP service.
#ftpd_banner=Utfpr - LT38C - Sistemas Embarcados
/bin/sed -i 's/#ftpd_banner=Welcome to blah FTP service./ftpd_banner=Utfpr - LT38C - Sistemas Embarcados/' /etc/vsftpd.conf

#Acesso a todo o sistema de diretórios do rPI
#local_root=/
/bin/echo "local_root=/" >> /etc/vsftpd.conf

#Acesso ao usuario root:
#allow_writeable_chroot=YES
/bin/echo "allow_writeable_chroot=YES" >> /etc/vsftpd.conf
#Retirar o usuário root da lista negra:
/bin/cp /etc/ftpusers /etc/ftpusers.bkp
/bin/sed -i 's/root/ /' /etc/ftpusers

#End