#!/bin/bash # Nextcloud installation on Raspbian over LAMP base # Tested with 2017-03-02-raspbian-jessie-lite.img # # Copyleft 2017 by Ignacio Nunez Hernanz # GPL licensed (see end of file) * Use at your own risk! # # Usage: # # ./installer.sh nc-nextcloud () # # See installer.sh instructions for details # # More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/ # VER_=12.0.0 MAXFILESIZE_=2G MEMORYLIMIT_=768M MAXTRANSFERTIME_=3600 DBADMIN_=ncadmin DESCRIPTION="Install any NextCloud version" export DEBIAN_FRONTEND=noninteractive show_info() { [ -d /var/www/nextcloud ] && \ whiptail --yesno \ --backtitle "NextCloudPi configuration" \ --title "NextCloud installation" \ "This new installation will cleanup current NextCloud instance, including files and database. You can later use nc-init to configure to NextCloudPi defaults ** perform backup before proceding ** You can use nc-backup " \ 20 90 } install() { :; } configure() { local DBPASSWD=$( cat /root/.dbpass ) ## RE-CREATE DATABASE TABLE echo "Starting mariaDB" # launch mariadb if not already running (for docker build) pgrep -x mysqld &>/dev/null || { mysqld & } # wait for mariadb pgrep -x mysqld &>/dev/null || { echo "mariaDB process not found"; return 1; } while :; do [[ -S /var/run/mysqld/mysqld.sock ]] && break sleep 0.5 done echo "Setting up database..." # workaround to emulate DROP USER IF EXISTS ..;) mysql -u root -p$DBPASSWD < /etc/apache2/sites-available/nextcloud.conf <<'EOF' DocumentRoot /var/www/nextcloud CustomLog /var/www/nextcloud/data/access.log combined ErrorLog /var/www/nextcloud/data/error.log SSLEngine on SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key Options +FollowSymlinks AllowOverride All Dav off LimitRequestBody 0 SSLRenegBufferSize 10486000 EOF a2ensite nextcloud echo "Setting up Apache..." cat > /etc/apache2/sites-available/000-default.conf <<'EOF' DocumentRoot /var/www/nextcloud RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] EOF echo "Setting up system..." ## SET LIMITS sed -i "s/post_max_size=.*/post_max_size=$MAXFILESIZE_/" /var/www/nextcloud/.user.ini sed -i "s/upload_max_filesize=.*/upload_max_filesize=$MAXFILESIZE_/" /var/www/nextcloud/.user.ini sed -i "s/memory_limit=.*/memory_limit=$MEMORYLIMIT_/" /var/www/nextcloud/.user.ini # slow transfers will be killed after this time cat >> /var/www/nextcloud/.user.ini <<< "max_execution_time=$MAXTRANSFERTIME_" cat >> /var/www/nextcloud/.user.ini <<< "max_input_time=$MAXTRANSFERTIME_" ## SET CRON echo "*/15 * * * * php -f /var/www/nextcloud/cron.php" > /tmp/crontab_http crontab -u www-data /tmp/crontab_http rm /tmp/crontab_http echo "Don't forget to run nc-init" } cleanup() { rm -f /home/pi/.bash_history systemctl disable ssh } # License # # This script is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This script is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this script; if not, write to the # Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA