lxd-selfhosting-scripts/install-roundcubemail.bash

121 lines
3.5 KiB
Bash
Raw Normal View History

2018-02-11 16:09:27 +01:00
#!/bin/bash
CONTAINER=$1
APPNAME="roundcubemail"
APPURL="https://github.com/roundcube/roundcubemail/releases/download/1.2.4/roundcubemail-1.2.4-complete.tar.gz"
TMPDIR="/tmp"
INSTALLDIR="/var/www"
DOMAIN="logerais.com"
TIMEZONE="Europe/Paris"
if [ -z "$CONTAINER" ]; then echo "Missing parameter"; exit 1 ; fi
# Configure timezone
lxc file edit "$CONTAINER/etc/timezone" <<< "${TIMEZONE}"
# Install Packages
lxc exec $CONTAINER -- apt update
lxc exec $CONTAINER -- apt install -y curl wget
lxc exec $CONTAINER -- apt install -y aspell aspell-fr hunspell hunspell-fr enchant
lxc exec $CONTAINER -- apt install -y nginx
lxc exec $CONTAINER -- apt install -y postgresql
lxc exec $CONTAINER -- apt install -y php
lxc exec $CONTAINER -- apt install -y php-xml
lxc exec $CONTAINER -- apt install -y php-json
lxc exec $CONTAINER -- apt install -y php-mbstring
lxc exec $CONTAINER -- apt install -y php-intl
lxc exec $CONTAINER -- apt install -y php-ldap
lxc exec $CONTAINER -- apt install -y php-mcrypt
lxc exec $CONTAINER -- apt install -y php-enchant
lxc exec $CONTAINER -- apt install -y php-pgsql
# Install Web App
lxc exec $CONTAINER -- bash <<< "cd ${TMPDIR} && wget ${APPURL}"
lxc exec $CONTAINER -- bash <<< "tar vxzf ${TMPDIR}/${APPNAME}-*.tar.gz -C ${INSTALLDIR}"
lxc exec $CONTAINER -- bash <<< "mv ${INSTALLDIR}/${APPNAME}-* ${INSTALLDIR}/${APPNAME}"
lxc exec $CONTAINER -- chown -R "www-data:www-data" "${INSTALLDIR}/${APPNAME}"
# Create Database
lxc exec $CONTAINER -- su --login postgres <<< "createuser ${APPNAME}"
lxc exec $CONTAINER -- su --login postgres <<< "createdb --owner=${APPNAME} ${APPNAME}"
lxc exec $CONTAINER -- su --login postgres --shell /usr/bin/psql <<< "ALTER USER \"${APPNAME}\" WITH PASSWORD '${APPNAME}';"
# Configure PHP
lxc exec $CONTAINER -- sed -i -e "s|;date.timezone.*|date.timezone = \"${TIMEZONE}\"|" /etc/php/7.0/fpm/php.ini
lxc exec $CONTAINER -- phpenmod dom
lxc exec $CONTAINER -- phpenmod session
lxc exec $CONTAINER -- phpenmod xml
lxc exec $CONTAINER -- phpenmod json
lxc exec $CONTAINER -- phpenmod pdo
lxc exec $CONTAINER -- phpenmod mbstring
lxc exec $CONTAINER -- phpenmod fileinfo
lxc exec $CONTAINER -- phpenmod iconv
lxc exec $CONTAINER -- phpenmod intl
lxc exec $CONTAINER -- phpenmod exif
lxc exec $CONTAINER -- phpenmod ldap
lxc exec $CONTAINER -- systemctl restart php7.0-fpm.service
# Configure Nginx
lxc file edit "$CONTAINER/etc/nginx/sites-available/${APPNAME}" <<EOF
server {
server_name ${APPNAME}.${DOMAIN};
root ${INSTALLDIR}/${APPNAME};
index index.php index.html;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ ^/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {
deny all;
}
location ~ ^/(config|temp|logs)/ {
deny all;
}
location ~ ^/(bin|SQL)/ {
deny all;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location ~ \.php\$ {
try_files \$uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_index index.php;
}
error_log /var/log/nginx/${APPNAME}_error.log;
access_log /var/log/nginx/${APPNAME}_access.log;
}
EOF
lxc exec $CONTAINER -- rm /etc/nginx/sites-enabled/default
lxc exec $CONTAINER -- ln -s "../sites-available/${APPNAME}" "/etc/nginx/sites-enabled/${APPNAME}"
lxc exec $CONTAINER -- systemctl restart nginx.service