From 6883aa2da7cd91df8eb849170fa3125b60c27a70 Mon Sep 17 00:00:00 2001 From: nachoparker Date: Wed, 22 Nov 2017 17:09:44 +0100 Subject: [PATCH] added armbian support --- armbian.sh | 58 ++++++++++++++++++++++++ docker-armhf/nextcloudpi/Dockerfile | 4 ++ docker/nextcloudpi/Dockerfile | 4 ++ etc/nextcloudpi-config.d/nc-init.sh | 42 ++++++++++++----- etc/nextcloudpi-config.d/nc-nextcloud.sh | 8 ++-- install.sh | 12 ++++- lamp.sh | 9 ++-- nextcloudpi.sh | 4 +- prepare.sh | 3 ++ update.sh | 6 ++- 10 files changed, 129 insertions(+), 21 deletions(-) create mode 100644 armbian.sh diff --git a/armbian.sh b/armbian.sh new file mode 100644 index 00000000..80d217b4 --- /dev/null +++ b/armbian.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# arguments: $RELEASE $LINUXFAMILY $BOARD $BUILD_DESKTOP + +# This is the image customization script for NextCloudPi on Armbian +# +# Copyleft 2017 by Ignacio Nunez Hernanz +# GPL licensed (see end of file) * Use at your own risk! +# +# More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/ +# + + +RELEASE=$1 +LINUXFAMILY=$2 +BOARD=$3 +BUILD_DESKTOP=$4 + +Main() { + case $RELEASE in + jessie) + # your code here + ;; + xenial) + # your code here + ;; + stretch) + # Need sudo access that does not expire + echo -e "1234\n1234" | passwd root + + # indicate that this will be an image build + touch /.ncp-image + + # install NCP + curl -sSL https://raw.githubusercontent.com/nextcloud/nextcloudpi/master/install.sh | bash + + ;; + esac +} # Main + +Main "$@" + +# 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/docker-armhf/nextcloudpi/Dockerfile b/docker-armhf/nextcloudpi/Dockerfile index 7d7d21cd..f62ceec5 100644 --- a/docker-armhf/nextcloudpi/Dockerfile +++ b/docker-armhf/nextcloudpi/Dockerfile @@ -9,6 +9,9 @@ ENV DOCKERBUILD 1 COPY nextcloudpi.sh /usr/local/etc/ RUN \ +# mark as image build +touch /.ncp-image; \ + apt-get update; \ apt-get install --no-install-recommends -y wget ca-certificates; \ @@ -23,6 +26,7 @@ sed -i 's|/media/USBdrive|/data/backups|' nextcloudpi-config.d/nc-backup.sh; \ # specific cleanup rm /usr/local/etc/nextcloudpi.sh; \ +rm /.ncp-image; \ # remove wizard for now rm -r /var/www/ncp-web/wizard; \ diff --git a/docker/nextcloudpi/Dockerfile b/docker/nextcloudpi/Dockerfile index add24736..d80ec758 100644 --- a/docker/nextcloudpi/Dockerfile +++ b/docker/nextcloudpi/Dockerfile @@ -9,6 +9,9 @@ ENV DOCKERBUILD 1 COPY nextcloudpi.sh /usr/local/etc/ RUN \ +# mark as image build +touch /.ncp-image; \ + apt-get update; \ apt-get install --no-install-recommends -y wget ca-certificates; \ @@ -23,6 +26,7 @@ sed -i 's|/media/USBdrive|/data/backups|' nextcloudpi-config.d/nc-backup.sh; \ # specific cleanup rm /usr/local/etc/nextcloudpi.sh; \ +rm /.ncp-image; \ # remove wizard for now rm -r /var/www/ncp-web/wizard; \ diff --git a/etc/nextcloudpi-config.d/nc-init.sh b/etc/nextcloudpi-config.d/nc-init.sh index d06d4953..61370ccd 100644 --- a/etc/nextcloudpi-config.d/nc-init.sh +++ b/etc/nextcloudpi-config.d/nc-init.sh @@ -34,13 +34,20 @@ configure() echo "Setting up database..." - # wait for mariadb + # launch mariadb if not already running + if ! pgrep -c mysqld &>/dev/null; then + mysqld & + fi + 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 + # wait for mariadb + # TODO FIXME armbian build + #while :; do + #[[ -S /run/mysqld/mysqld.sock ]] && break + #sleep 0.5 + #done + sleep 10 # workaround to emulate DROP USER IF EXISTS ..;) local DBPASSWD=$( grep password /root/.my.cnf | cut -d= -f2 ) @@ -58,6 +65,19 @@ EOF ## INITIALIZE NEXTCLOUD + # make sure redis is running first + if ! pgrep -c redis-server &>/dev/null; then + mkdir -p /var/run/redis + chown redis /var/run/redis + sudo -u redis redis-server /etc/redis/redis.conf & + fi + + while :; do + [[ -S /run/redis/redis.sock ]] && break + sleep 0.5 + done + + echo "Setting up Nextcloud..." cd /var/www/nextcloud/ @@ -87,7 +107,7 @@ EOF sudo -u www-data php occ config:system:set mysql.utf8mb4 --type boolean --value="true" # Default trusted domain ( only from nextcloudpi-config ) - test -f /usr/local/bin/nextcloud-domain.sh && bash /usr/local/bin/nextcloud-domain.sh + test -f /.ncp-image || bash /usr/local/bin/nextcloud-domain.sh sudo -u www-data php occ config:system:set trusted_domains 5 --value="nextcloudpi.local" # email @@ -104,11 +124,11 @@ EOF chown -R www-data:www-data data/appdata_${ID} mysql nextcloud <> $REDIS_CONF echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf - sudo usermod -a -G redis www-data + usermod -a -G redis www-data [[ "$DOCKERBUILD" != 1 ]] && { systemctl restart redis-server @@ -77,7 +77,9 @@ configure() echo "Starting mariaDB" # launch mariadb if not already running (for docker build) - [[ "$DOCKERBUILD" == 1 ]] && { mysqld & } + if ! pgrep -c mysqld &>/dev/null; then + mysqld & + fi # wait for mariadb pgrep -x mysqld &>/dev/null || { echo "mariaDB process not found"; return 1; } diff --git a/install.sh b/install.sh index 683d7388..4d91eaeb 100644 --- a/install.sh +++ b/install.sh @@ -53,10 +53,18 @@ activate_script etc/nextcloudpi-config.d/nc-init.sh [[ "$APACHE_EXISTS" != "" ]] && \ a2enmod status reqtimeout env autoindex access_compat auth_basic authn_file authn_core alias access_compat -# cleanup cd - rm -rf $TMPDIR +# extra cleanup only in image generation +[[ -f /.ncp-image ]] && { + apt-get autoremove -y + apt-get clean + rm /var/lib/apt/lists/* -r + rm /.ncp-image +} + + echo "Done. Type 'sudo nextcloudpi-config' to configure NCP @@ -66,6 +74,8 @@ Access NextCloudPi panel on nextcloudpi.local:4443 Access Nextcloud on nextcloudpi.local " +exit 0 + # License # # This script is free software; you can redistribute it and/or modify it diff --git a/lamp.sh b/lamp.sh index e78c9562..748a3a4e 100644 --- a/lamp.sh +++ b/lamp.sh @@ -111,14 +111,17 @@ EOF sed -i '/\[mysqld\]/ainnodb_file_per_table=1' /etc/mysql/mariadb.conf.d/50-server.cnf sed -i '/\[mysqld\]/ainnodb_file_format=barracuda' /etc/mysql/mariadb.conf.d/50-server.cnf - # launch mariadb if not already running (for docker build) - [[ "$DOCKERBUILD" == 1 ]] && { mysqld & } + # launch mariadb if not already running + if ! pgrep -c mysqld &>/dev/null; then + mysqld & + fi # wait for mariadb while :; do - [[ -S /var/run/mysqld/mysqld.sock ]] && break + [[ -S /run/mysqld/mysqld.sock ]] && break sleep 0.5 done + mysql_secure_installation </dev/null ) if [ "$STATE" == "" ]; then + # MARK THE IMAGE AS AN IMAGE BUILD + touch /.ncp-image + # RESIZE IMAGE ########################################## diff --git a/update.sh b/update.sh index 260c8ef0..523c2e2c 100755 --- a/update.sh +++ b/update.sh @@ -112,7 +112,8 @@ done ## BACKWARD FIXES ( for older images ) -[[ "$DOCKERBUILD" != 1 ]] && { +# only for image builds +[[ ! -f /.ncp-image ]] && { # fix notify unattended upgrades repeating lines cat > /usr/local/bin/ncp-notify-unattended-upgrade <