|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Nextcloud installation on Raspbian over LAMP base |
| 4 | +# Tested with 2017-03-02-raspbian-jessie-lite.img |
| 5 | +# |
| 6 | +# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com> |
| 7 | +# GPL licensed (see end of file) * Use at your own risk! |
| 8 | +# |
| 9 | +# Usage: |
| 10 | +# |
| 11 | +# ./installer.sh nextcloud.sh <IP> (<img>) |
| 12 | +# |
| 13 | +# See installer.sh instructions for details |
| 14 | +# |
| 15 | +# More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/ |
| 16 | +# |
| 17 | + |
| 18 | +VER=11.0.3 |
| 19 | +ADMINUSER_=admin |
| 20 | +DBADMIN_=ncadmin |
| 21 | +DBPASSWD_=ownyourbits |
| 22 | +MAXFILESIZE_=768M |
| 23 | +MAXTRANSFERTIME_=3600 |
| 24 | +OPCACHEDIR=/var/www/nextcloud/data/.opcache |
| 25 | + |
| 26 | +install() |
| 27 | +{ |
| 28 | + cd /var/www/ |
| 29 | + wget https://download.nextcloud.com/server/releases/nextcloud-$VER.tar.bz2 -O nextcloud.tar.bz2 |
| 30 | + tar -xvf nextcloud.tar.bz2 |
| 31 | + rm nextcloud.tar.bz2 |
| 32 | + |
| 33 | + ocpath='/var/www/nextcloud' |
| 34 | + htuser='www-data' |
| 35 | + htgroup='www-data' |
| 36 | + rootuser='root' |
| 37 | + |
| 38 | + printf "Creating possible missing Directories\n" |
| 39 | + mkdir -p $ocpath/data |
| 40 | + mkdir -p $ocpath/updater |
| 41 | + mkdir -p $OPCACHEDIR |
| 42 | + |
| 43 | + printf "chmod Files and Directories\n" |
| 44 | + find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640 |
| 45 | + find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750 |
| 46 | + |
| 47 | + printf "chown Directories\n" |
| 48 | + # recommended defaults do not play well with updater app |
| 49 | + # re-check this with every new version |
| 50 | + #chown -R ${rootuser}:${htgroup} ${ocpath}/ |
| 51 | + chown -R ${htuser}:${htgroup} ${ocpath}/ |
| 52 | + chown -R ${htuser}:${htgroup} ${ocpath}/apps/ |
| 53 | + chown -R ${htuser}:${htgroup} ${ocpath}/config/ |
| 54 | + chown -R ${htuser}:${htgroup} ${ocpath}/data/ |
| 55 | + chown -R ${htuser}:${htgroup} ${ocpath}/themes/ |
| 56 | + chown -R ${htuser}:${htgroup} ${ocpath}/updater/ |
| 57 | + chown -R ${htuser}:${htgroup} $OPCACHEDIR |
| 58 | + |
| 59 | + chmod +x ${ocpath}/occ |
| 60 | + |
| 61 | + printf "chmod/chown .htaccess\n" |
| 62 | + if [ -f ${ocpath}/.htaccess ]; then |
| 63 | + # breaks updater, see above |
| 64 | + #chmod 0644 ${ocpath}/.htaccess |
| 65 | + chmod 0664 ${ocpath}/.htaccess |
| 66 | + chown ${rootuser}:${htgroup} ${ocpath}/.htaccess |
| 67 | + fi |
| 68 | + if [ -f ${ocpath}/data/.htaccess ]; then |
| 69 | + chmod 0644 ${ocpath}/data/.htaccess |
| 70 | + chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess |
| 71 | + fi |
| 72 | + |
| 73 | +cat > /etc/apache2/sites-available/000-default.conf <<'EOF' |
| 74 | +<VirtualHost _default_:80> |
| 75 | + DocumentRoot /var/www/nextcloud |
| 76 | + <IfModule mod_rewrite.c> |
| 77 | + RewriteEngine On |
| 78 | + RewriteCond %{HTTPS} !=on |
| 79 | + RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] |
| 80 | + </IfModule> |
| 81 | +</VirtualHost> |
| 82 | +EOF |
| 83 | + |
| 84 | + mkdir -p /usr/lib/systemd/system |
| 85 | + cat > /usr/lib/systemd/system/nextcloud-domain.service <<'EOF' |
| 86 | +[Unit] |
| 87 | +Description=Register Current IP as Nextcloud trusted domain |
| 88 | +Requires=network.target |
| 89 | +After=mysql.service |
| 90 | +
|
| 91 | +[Service] |
| 92 | +ExecStart=/bin/bash /usr/local/bin/nextcloud-domain.sh |
| 93 | +
|
| 94 | +[Install] |
| 95 | +WantedBy=multi-user.target |
| 96 | +EOF |
| 97 | + systemctl enable nextcloud-domain |
| 98 | + |
| 99 | + cat > /usr/local/bin/nextcloud-domain.sh <<'EOF' |
| 100 | +#!/bin/bash |
| 101 | +IFACE=$( ip r | grep "default via" | awk '{ print $5 }' ) |
| 102 | +IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 ) |
| 103 | +cd /var/www/nextcloud |
| 104 | +sudo -u www-data php occ config:system:set trusted_domains 1 --value=$IP |
| 105 | +EOF |
| 106 | +} |
| 107 | + |
| 108 | +configure() |
| 109 | +{ |
| 110 | + cd /var/www/nextcloud/ |
| 111 | + |
| 112 | + sudo -u www-data php occ maintenance:install --database \ |
| 113 | + "mysql" --database-name "nextcloud" --database-user "$DBADMIN_" --database-pass \ |
| 114 | + "$DBPASSWD_" --admin-user "$ADMINUSER_" --admin-pass "$DBPASSWD_" |
| 115 | + |
| 116 | + sudo -u www-data php occ background:cron |
| 117 | + |
| 118 | + sed -i '$s|^.*$| '\''memcache.local'\'' => '\''\\\\OC\\\\Memcache\\\\APCu'\'',\\n);|' /var/www/nextcloud/config/config.php |
| 119 | + |
| 120 | + sed -i "s/post_max_size=.*/post_max_size=$MAXFILESIZE_/" /var/www/nextcloud/.user.ini |
| 121 | + sed -i "s/upload_max_filesize=.*/upload_max_filesize=$MAXFILESIZE_/" /var/www/nextcloud/.user.ini |
| 122 | + sed -i "s/memory_limit=.*/memory_limit=$MAXFILESIZE_/" /var/www/nextcloud/.user.ini |
| 123 | + |
| 124 | + # slow transfers will be killed after this time |
| 125 | + cat >> /var/www/nextcloud/.user.ini <<< "max_execution_time=$MAXTRANSFERTIME_" |
| 126 | + |
| 127 | + echo "*/15 * * * * php -f /var/www/nextcloud/cron.php" > /tmp/crontab_http |
| 128 | + crontab -u www-data /tmp/crontab_http |
| 129 | + rm /tmp/crontab_http |
| 130 | +} |
| 131 | + |
| 132 | +cleanup() |
| 133 | +{ |
| 134 | + [ "$STATE" != "1" ] && return |
| 135 | + apt-get autoremove |
| 136 | + apt-get clean |
| 137 | + rm /var/lib/apt/lists/* -r |
| 138 | + rm -f /home/pi/.bash_history |
| 139 | + |
| 140 | + systemctl disable ssh |
| 141 | + nohup halt &>/dev/null & |
| 142 | +} |
| 143 | +# License |
| 144 | +# |
| 145 | +# This script is free software; you can redistribute it and/or modify it |
| 146 | +# under the terms of the GNU General Public License as published by |
| 147 | +# the Free Software Foundation; either version 2 of the License, or |
| 148 | +# (at your option) any later version. |
| 149 | +# |
| 150 | +# This script is distributed in the hope that it will be useful, |
| 151 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 152 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 153 | +# GNU General Public License for more details. |
| 154 | +# |
| 155 | +# You should have received a copy of the GNU General Public License |
| 156 | +# along with this script; if not, write to the |
| 157 | +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
| 158 | +# Boston, MA 02111-1307 USA |
| 159 | + |
0 commit comments