#!/bin/bash # Nextcloud LAMP base installation on Raspbian # 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 nextcloud_lamp.sh () # # See installer.sh instructions for details # # Notes: # Upon each necessary restart, the system will cut the SSH session, therefore # it is required to save the state of the installation. See variable $STATE_FILE # It will be necessary to invoke this a number of times for a complete installation # # More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/ # DBADMIN_=ncadmin DBPASSWD_=ownyourbits OPCACHEDIR=/var/www/nextcloud/data/.opcache CONFDIR=/usr/local/etc/nextcloudpi-config.d/ STATE_FILE=/home/pi/.installation_state APTINSTALL="apt-get install -y --no-install-recommends" install() { test -f $STATE_FILE && STATE=$( cat $STATE_FILE 2>/dev/null ) if [ "$STATE" == "" ]; then # RESIZE IMAGE ########################################## SECTOR=$( fdisk -l /dev/sda | grep Linux | awk '{ print $2 }' ) echo -e "d\n2\nn\np\n2\n$SECTOR\n\nw\n" | fdisk /dev/sda || true echo 0 > $STATE_FILE nohup reboot &>/dev/null & elif [ "$STATE" == "0" ]; then # UPDATE EVERYTHING ########################################## resize2fs /dev/sda2 apt-get update apt-get upgrade -y apt-get dist-upgrade -y $APTINSTALL rpi-update echo -e "y\n" | rpi-update echo 1 > $STATE_FILE nohup reboot &>/dev/null & elif [ "$STATE" == "1" ]; then # GET STRETCH SOURCES FOR HTTP2 AND PHP7 ########################################## echo "deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi" >> /etc/apt/sources.list cat > /etc/apt/preferences </etc/apache2/conf-available/http2.conf <> /etc/apache2/apache2.conf < Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" EOF cat > /etc/php/7.0/mods-available/apcu.ini < /etc/php/7.0/mods-available/opcache.ini < /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 EOF a2ensite nextcloud mysql -u root -p$DBPASSWD_ </dev/null & } # 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