lxd-selfhosting-scripts/install-rainloop.bash
2018-02-11 16:09:27 +01:00

101 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
CONTAINER=$1
APPNAME="rainloop"
APPURL="http://www.rainloop.net/repository/webmail/rainloop-community-latest.zip"
TMPDIR="/tmp"
INSTALLDIR="/var/www"
DOMAIN="logerais.com"
TIMEZONE="Europe/Paris"
if [ -z "$CONTAINER" ]; then echo "Missing parameter"; exit 1 ; fi
# Set container timezone
lxc file edit "$CONTAINER/etc/timezone" <<< "${TIMEZONE}"
# Install packages
lxc exec $CONTAINER -- apt update
lxc exec $CONTAINER -- apt install -y curl wget tar unzip
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-curl
lxc exec $CONTAINER -- apt install -y php-intl
lxc exec $CONTAINER -- apt install -y php-json
lxc exec $CONTAINER -- apt install -y php-xml
lxc exec $CONTAINER -- apt install -y php-pgsql
# 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 curl
lxc exec $CONTAINER -- phpenmod iconv
lxc exec $CONTAINER -- phpenmod json
lxc exec $CONTAINER -- phpenmod xml
lxc exec $CONTAINER -- phpenmod dom
lxc exec $CONTAINER -- phpenmod pdo
lxc exec $CONTAINER -- systemctl restart php7.0-fpm.service
# 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}';"
# Install web app
lxc exec $CONTAINER -- mkdir "${INSTALLDIR}/${APPNAME}"
lxc exec $CONTAINER -- chown -R "www-data:www-data" "${INSTALLDIR}/${APPNAME}"
lxc exec $CONTAINER -- bash <<< "cd ${INSTALLDIR}/${APPNAME} && curl -sL https://repository.rainloop.net/installer.php | php"
# 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 ^~ /data {
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