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

116 lines
4.1 KiB
Bash
Executable File

#!/bin/bash
CONTAINER=$1
APPNAME="pydio"
APPURL="https://download.pydio.com/pub/core/archives/pydio-core-7.0.4.tar.gz"
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}"
# Update packages
lxc exec $CONTAINER -- apt update
# Install packages
lxc exec $CONTAINER -- apt install -y curl wget tar unzip
# Install database
lxc exec $CONTAINER -- apt install -y postgresql
# 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 PHP
lxc exec $CONTAINER -- apt install -y php
lxc exec $CONTAINER -- apt install -y php-intl
lxc exec $CONTAINER -- apt install -y php-mbstring
lxc exec $CONTAINER -- apt install -y php-xml
lxc exec $CONTAINER -- apt install -y php-gd
lxc exec $CONTAINER -- apt install -y php-pgsql
lxc exec $CONTAINER -- apt install -y php-curl
lxc exec $CONTAINER -- apt install -y php-mail php-mail-mime php-mail-mimedecode
lxc exec $CONTAINER -- apt install -y php-sabre-dav
lxc exec $CONTAINER -- apt install -y redis-server php-redis
# Configure PHP
lxc exec $CONTAINER -- sed -i -e "s|;date.timezone.*|date.timezone = \"${TIMEZONE}\"|" /etc/php/7.0/fpm/php.ini
lxc exec $CONTAINER -- sed -i -e 's/^\(output_buffering\) = .*$/\1 = Off/g' /etc/php/7.0/fpm/php.ini
lxc exec $CONTAINER -- sed -i -e 's/^\(file_uploads\) = .*$/\1 = On/g' /etc/php/7.0/fpm/php.ini
lxc exec $CONTAINER -- sed -i -e 's/^\(post_max_size\) = .*$/\1 = 2G/g' /etc/php/7.0/fpm/php.ini
lxc exec $CONTAINER -- sed -i -e 's/^\(upload_max_filesize\) = .*$/\1 =2G/g' /etc/php/7.0/fpm/php.ini
lxc exec $CONTAINER -- sed -i -e 's/^\(max_execution_time\) = .*$/\1 = 300/g' /etc/php/7.0/fpm/php.ini
lxc exec $CONTAINER -- sed -i -e 's/^\(max_input_time\) = .*$/\1 = 300/g' /etc/php/7.0/fpm/php.ini
lxc exec $CONTAINER -- sed -i -e 's/^\(memory_limit\) = .*$/\1 = 256M/g' /etc/php/7.0/fpm/php.ini
lxc exec $CONTAINER -- phpenmod intl
lxc exec $CONTAINER -- phpenmod mbstring
lxc exec $CONTAINER -- phpenmod xml
lxc exec $CONTAINER -- phpenmod dom
lxc exec $CONTAINER -- phpenmod gd
lxc exec $CONTAINER -- phpenmod pdo
lxc exec $CONTAINER -- phpenmod curl
lxc exec $CONTAINER -- phpenmod opcache
lxc exec $CONTAINER -- phpenmod redis
lxc exec $CONTAINER -- systemctl restart php7.0-fpm.service
# Install Nginx
lxc exec $CONTAINER -- apt install -y nginx
# Configure Nginx
lxc file edit "$CONTAINER/etc/nginx/sites-available/${APPNAME}" <<EOF
server {
server_name ${APPNAME}.${DOMAIN};
root ${INSTALLDIR}/${APPNAME};
access_log /var/log/nginx/${APPNAME}.access.log;
error_log /var/log/nginx/${APPNAME}.error.log;
index index.php index.html;
client_max_body_size 2G;
# Prevent Clickjacking
add_header X-Frame-Options "SAMEORIGIN";
# Manually deny some paths to ensure Pydio security
location ~* ^/(?:\.|conf|data/(?:files|personal|logs|plugins|tmp|cache)|plugins/editor.zoho/agent/files) {
deny all;
}
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;
}
}
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
# 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}"