From 0909fce6d36022a59cbe8e68bd2c5239b5beec82 Mon Sep 17 00:00:00 2001 From: nachoparker Date: Sat, 20 May 2017 19:10:11 +0200 Subject: add nextcloud instance installation command to ncp-config --- batch.sh | 5 +- etc/nextcloudpi-config.d/NFS.sh | 0 etc/nextcloudpi-config.d/dnsmasq.sh | 0 etc/nextcloudpi-config.d/fail2ban.sh | 0 etc/nextcloudpi-config.d/letsencrypt.sh | 0 etc/nextcloudpi-config.d/modsecurity.sh | 0 etc/nextcloudpi-config.d/nc-database.sh | 0 etc/nextcloudpi-config.d/nc-datadir.sh | 0 etc/nextcloudpi-config.d/nc-httpsonly.sh | 0 etc/nextcloudpi-config.d/nc-limits.sh | 0 etc/nextcloudpi-config.d/nc-nextcloud.sh | 170 ++++++++++++++++++++++++ etc/nextcloudpi-config.d/nc-ramlogs.sh | 0 etc/nextcloudpi-config.d/nc-scan-auto.sh | 0 etc/nextcloudpi-config.d/nc-scan.sh | 0 etc/nextcloudpi-config.d/nc-swapfile.sh | 0 etc/nextcloudpi-config.d/nc-update.sh | 0 etc/nextcloudpi-config.d/nc-wifi.sh | 0 etc/nextcloudpi-config.d/no-ip.sh | 0 etc/nextcloudpi-config.d/unattended-upgrades.sh | 0 nextcloud.sh | 155 --------------------- nextcloudpi.sh | 1 - 21 files changed, 173 insertions(+), 158 deletions(-) mode change 100755 => 100644 etc/nextcloudpi-config.d/NFS.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/dnsmasq.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/fail2ban.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/letsencrypt.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/modsecurity.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/nc-database.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/nc-datadir.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/nc-httpsonly.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/nc-limits.sh create mode 100755 etc/nextcloudpi-config.d/nc-nextcloud.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/nc-ramlogs.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/nc-scan-auto.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/nc-scan.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/nc-swapfile.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/nc-update.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/nc-wifi.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/no-ip.sh mode change 100755 => 100644 etc/nextcloudpi-config.d/unattended-upgrades.sh delete mode 100755 nextcloud.sh diff --git a/batch.sh b/batch.sh index ed5283e7..4048a02d 100755 --- a/batch.sh +++ b/batch.sh @@ -12,15 +12,16 @@ source etc/library.sh # initializes $IMGNAME IP=$1 # First argument is the QEMU Raspbian IP address +NC_SCRIPT=etc/nextcloudpi-config.d/nc-nextcloud.sh IMGBASE="NextCloudPi_$( date "+%m-%d-%y" )_base.img" NO_CONFIG=1 NO_HALT_STEP=1 ./install-nextcloud.sh $IP $IMGBASE +NO_CONFIG=1 ./installer.sh $NC_SCRIPT $IP $( ls -1t *.img | head -1 ) NO_CONFIG=1 ./installer.sh nextcloudpi.sh $IP $( ls -1t *.img | head -1 ) -NO_CONFIG=1 ./installer.sh nextcloud.sh $IP $( ls -1t *.img | head -1 ) IMGFILE=$( ls -1t *.img | head -1 ) -IMGOUT=$( basename "$IMGFILE" _base ).img +IMGOUT=$( basename "$IMGFILE" _base_nc-nextcloud_nextcloudpi.img ).img pack_image "$IMGFILE" "$IMGOUT" md5sum $( ls -1t *.img | head -1 ) diff --git a/etc/nextcloudpi-config.d/NFS.sh b/etc/nextcloudpi-config.d/NFS.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/dnsmasq.sh b/etc/nextcloudpi-config.d/dnsmasq.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/fail2ban.sh b/etc/nextcloudpi-config.d/fail2ban.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/letsencrypt.sh b/etc/nextcloudpi-config.d/letsencrypt.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/modsecurity.sh b/etc/nextcloudpi-config.d/modsecurity.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/nc-database.sh b/etc/nextcloudpi-config.d/nc-database.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/nc-datadir.sh b/etc/nextcloudpi-config.d/nc-datadir.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/nc-httpsonly.sh b/etc/nextcloudpi-config.d/nc-httpsonly.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/nc-limits.sh b/etc/nextcloudpi-config.d/nc-limits.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/nc-nextcloud.sh b/etc/nextcloudpi-config.d/nc-nextcloud.sh new file mode 100755 index 00000000..9524f981 --- /dev/null +++ b/etc/nextcloudpi-config.d/nc-nextcloud.sh @@ -0,0 +1,170 @@ +#!/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_=11.0.3 +ADMINUSER_=admin +DBADMIN_=ncadmin +DBPASSWD_=ownyourbits +MAXFILESIZE_=768M +MAXTRANSFERTIME_=3600 +OPCACHEDIR=/var/www/nextcloud/data/.opcache +DESCRIPTION="Install any NextCloud version" + +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. + +** perform backup before proceding ** + +You can use nc-backup " \ + 20 90 +} + +install() { :; } + +configure() +{ + service apache2 stop + + # RE-CREATE DATABASE TABLE (workaround to emulate DROP USER IF EXISTS ..;) + sleep 40 # TODO wait for mysql to be up + mysql -u root -p$DBPASSWD_ < /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 + + cd /var/www/nextcloud/ + + sudo -u www-data php occ maintenance:install --database \ + "mysql" --database-name "nextcloud" --database-user "$DBADMIN_" --database-pass \ + "$DBPASSWD_" --admin-user "$ADMINUSER_" --admin-pass "$DBPASSWD_" + + sudo -u www-data php occ background:cron + + sed -i '$s|^.*$| '\''memcache.local'\'' => '\''\\\\OC\\\\Memcache\\\\APCu'\'',\\n);|' /var/www/nextcloud/config/config.php + + 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=$MAXFILESIZE_/" /var/www/nextcloud/.user.ini + + # slow transfers will be killed after this time + cat >> /var/www/nextcloud/.user.ini <<< "max_execution_time=$MAXTRANSFERTIME_" + + echo "*/15 * * * * php -f /var/www/nextcloud/cron.php" > /tmp/crontab_http + crontab -u www-data /tmp/crontab_http + rm /tmp/crontab_http + + # Initial Trusted Domain + local IFACE=$( ip r | grep "default via" | awk '{ print $5 }' ) + local IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 ) + sudo -u www-data php occ config:system:set trusted_domains 1 --value=$IP + cd - + + service apache2 start +} + +cleanup() +{ + rm -f /home/pi/.bash_history + + systemctl disable ssh + nohup halt &>/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 + diff --git a/etc/nextcloudpi-config.d/nc-ramlogs.sh b/etc/nextcloudpi-config.d/nc-ramlogs.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/nc-scan-auto.sh b/etc/nextcloudpi-config.d/nc-scan-auto.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/nc-scan.sh b/etc/nextcloudpi-config.d/nc-scan.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/nc-swapfile.sh b/etc/nextcloudpi-config.d/nc-swapfile.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/nc-update.sh b/etc/nextcloudpi-config.d/nc-update.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/nc-wifi.sh b/etc/nextcloudpi-config.d/nc-wifi.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/no-ip.sh b/etc/nextcloudpi-config.d/no-ip.sh old mode 100755 new mode 100644 diff --git a/etc/nextcloudpi-config.d/unattended-upgrades.sh b/etc/nextcloudpi-config.d/unattended-upgrades.sh old mode 100755 new mode 100644 diff --git a/nextcloud.sh b/nextcloud.sh deleted file mode 100755 index e9228312..00000000 --- a/nextcloud.sh +++ /dev/null @@ -1,155 +0,0 @@ -#!/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 nextcloud.sh () -# -# See installer.sh instructions for details -# -# More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/ -# - -VER=11.0.3 -ADMINUSER_=admin -DBADMIN_=ncadmin -DBPASSWD_=ownyourbits -MAXFILESIZE_=768M -MAXTRANSFERTIME_=3600 -OPCACHEDIR=/var/www/nextcloud/data/.opcache - -install() -{ - cd /var/www/ - wget https://download.nextcloud.com/server/releases/nextcloud-$VER.tar.bz2 -O nextcloud.tar.bz2 - tar -xvf nextcloud.tar.bz2 - rm nextcloud.tar.bz2 - - ocpath='/var/www/nextcloud' - htuser='www-data' - htgroup='www-data' - rootuser='root' - - printf "Creating possible missing Directories\n" - mkdir -p $ocpath/data - mkdir -p $ocpath/updater - mkdir -p $OPCACHEDIR - - printf "chmod Files and Directories\n" - find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640 - find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750 - - printf "chown Directories\n" - - chown -R ${htuser}:${htgroup} ${ocpath}/ - chown -R ${htuser}:${htgroup} ${ocpath}/apps/ - chown -R ${htuser}:${htgroup} ${ocpath}/config/ - chown -R ${htuser}:${htgroup} ${ocpath}/data/ - chown -R ${htuser}:${htgroup} ${ocpath}/themes/ - chown -R ${htuser}:${htgroup} ${ocpath}/updater/ - chown -R ${htuser}:${htgroup} $OPCACHEDIR - - chmod +x ${ocpath}/occ - - printf "chmod/chown .htaccess\n" - if [ -f ${ocpath}/.htaccess ]; then - chmod 0644 ${ocpath}/.htaccess - chown ${rootuser}:${htgroup} ${ocpath}/.htaccess - fi - if [ -f ${ocpath}/data/.htaccess ]; then - chmod 0644 ${ocpath}/data/.htaccess - chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess - fi - -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 - - mkdir -p /usr/lib/systemd/system - cat > /usr/lib/systemd/system/nextcloud-domain.service <<'EOF' -[Unit] -Description=Register Current IP as Nextcloud trusted domain -Requires=network.target -After=mysql.service - -[Service] -ExecStart=/bin/bash /usr/local/bin/nextcloud-domain.sh - -[Install] -WantedBy=multi-user.target -EOF - systemctl enable nextcloud-domain - - cat > /usr/local/bin/nextcloud-domain.sh <<'EOF' -#!/bin/bash -IFACE=$( ip r | grep "default via" | awk '{ print $5 }' ) -IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 ) -cd /var/www/nextcloud -sudo -u www-data php occ config:system:set trusted_domains 1 --value=$IP -EOF -} - -configure() -{ - cd /var/www/nextcloud/ - - sudo -u www-data php occ maintenance:install --database \ - "mysql" --database-name "nextcloud" --database-user "$DBADMIN_" --database-pass \ - "$DBPASSWD_" --admin-user "$ADMINUSER_" --admin-pass "$DBPASSWD_" - - sudo -u www-data php occ background:cron - - sed -i '$s|^.*$| '\''memcache.local'\'' => '\''\\\\OC\\\\Memcache\\\\APCu'\'',\\n);|' /var/www/nextcloud/config/config.php - - 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=$MAXFILESIZE_/" /var/www/nextcloud/.user.ini - - # slow transfers will be killed after this time - cat >> /var/www/nextcloud/.user.ini <<< "max_execution_time=$MAXTRANSFERTIME_" - - echo "*/15 * * * * php -f /var/www/nextcloud/cron.php" > /tmp/crontab_http - crontab -u www-data /tmp/crontab_http - rm /tmp/crontab_http -} - -cleanup() -{ - [ "$STATE" != "1" ] && return - apt-get autoremove - apt-get clean - rm /var/lib/apt/lists/* -r - rm -f /home/pi/.bash_history - - systemctl disable ssh - nohup halt &>/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 - diff --git a/nextcloudpi.sh b/nextcloudpi.sh index 1d364120..9ce623f8 100644 --- a/nextcloudpi.sh +++ b/nextcloudpi.sh @@ -121,7 +121,6 @@ configure() { :; } cleanup() { - [ "$STATE" != "1" ] && return apt-get autoremove apt-get clean rm /var/lib/apt/lists/* -r -- cgit v1.2.3