diff --git a/Dockerfile b/Dockerfile index 172c59c..976d549 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,13 +20,16 @@ # along with this program. If not, see . FROM ubuntu:16.04 + +COPY resources/nextcloud-11.0.0.tar.bz2 /root/ + RUN /bin/bash -c "export DEBIAN_FRONTEND=noninteractive" && \ + echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections && \ apt-get -y update && apt-get install -y \ apache2 \ curl \ libapache2-mod-php7.0 \ php7.0 \ - php7.0-mysql \ php-curl \ php-dompdf \ php-gd \ @@ -36,45 +39,34 @@ RUN /bin/bash -c "export DEBIAN_FRONTEND=noninteractive" && \ php-zip \ php-apcu \ php-ldap \ + php-pgsql \ wget \ - unzip \ pwgen \ - sudo + sudo \ + lbzip2 RUN a2enmod ssl RUN a2enmod headers RUN a2enmod rewrite RUN ln -s /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled -# FIXME: trusted domain -# FIXME: Rewrite Base, proxy settings? - RUN export NC_DATADIR="/var/lib/nextcloud/" && \ export NC_DB_NAME="nextcloud" && \ export NC_DB_TYPE="pgsql" && \ export NC_LOCAL_ADMIN="nc_admin" && \ export NC_LOCAL_ADMIN_PWD="pwgen -y 30 1" && \ - mkdir "$NC_DATADIR" && \ - cd /var/www/html && \ - cd /root/ && wget https://download.nextcloud.com/server/releases/nextcloud-11.0.0.zip && unzip /root/nextcloud-11.0.0.zip && \ + pwgen -y 30 1 > /etc/postgresql-nextcloud.secret && \ + mkdir "$NC_DATADIR" + +RUN cd /root/ && \ + tar -xf "nextcloud-11.0.0.tar.bz2" && \ mv /root/nextcloud/* /var/www/html/ && \ mv /root/nextcloud/.htaccess /var/www/html/.htaccess && \ + rm -Rf /root/nextcloud && \ + rm "nextcloud-11.0.0.tar.bz2" && \ cd /var/www/html/ && \ - chmod +x occ && \ - ./occ maintenance:install --admin-user "$NC_LOCAL_ADMIN" --admin-pass "$NC_LOCAL_ADMIN_PWD" --database "$NC_DB_TYPE" --database-host "$DB_HOST" --database-port "$DB_PORT" --database-name "$NC_DB_NAME" --database-user "$DB_USER" --database-pass "$DB_PASSWORD" --data-dir "$NC_DATADIR" && \ - chown -R www-data "$NC_DATADIR" && \ - ./occ check && \ - ./occ status && \ - ./occ app:list && \ - ./occ upgrade && \ - ./occ config:system:set trusted_domains 3 --value=demo.nextcloud.com && \ - ./occ config:system:set htaccess.RewriteBase --value="/" && \ - ./occ maintenance:update:htaccess && \ - /var/www/html/occ config:system:set --value "\OC\Memcache\APCu" memcache.local && \ - chown -R www-data /var/www && \ - cat /etc/apache2/apache2.conf |awk '//,/AllowOverride None/{sub("None", "All",$0)}{print}' > /tmp/apache2.conf && \ - mv /tmp/apache2.conf /etc/apache2/apache2.conf && \ - sed -i '/SSLEngine on/a Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains;"' /etc/apache2/sites-enabled/default-ssl.conf + chmod +x occ +# perhaps unnecessary? EXPOSE 80 EXPOSE 443 diff --git a/preinst.sh b/preinst.sh new file mode 100644 index 0000000..987b365 --- /dev/null +++ b/preinst.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# @copyright Copyright (c) 2017 Arthur Schiwon +# +# @author Arthur Schiwon +# +# @license GNU AGPL version 3 or any later version +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +NC_PERMCONFDIR="/var/lib/univention-appcenter/apps/nextcloud/conf" +NC_UCR_FILE="$NC_PERMCONFDIR/ucr" + +ls /var/lib/univention-appcenter/apps/nextcloud + +touch "$NC_UCR_FILE" || echo "needs mkdir" && mkdir -p "$NC_PERMCONFDIR" && touch "$NC_UCR_FILE" + +cat >"$NC_UCR_FILE" < +# +# @author Arthur Schiwon +# +# @license GNU AGPL version 3 or any later version +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +NC_PERMCONFDIR="/var/lib/univention-appcenter/apps/nextcloud/conf" + +if [ -e "$NC_PERMCONFDIR/config/config.php" ]; then + cp "$NC_PERMCONFDIR/config/config.php" "/var/www/html/nextcloud/config/" +fi diff --git a/restore_data_before_setup.sh b/restore_data_before_setup.sh new file mode 100644 index 0000000..a6cad36 --- /dev/null +++ b/restore_data_before_setup.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# @copyright Copyright (c) 2017 Arthur Schiwon +# +# @author Arthur Schiwon +# +# @license GNU AGPL version 3 or any later version +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +NC_PERMCONFDIR="/var/lib/univention-appcenter/apps/nextcloud/conf" + +if [ -e "/var/www/html/nextcloud/config/config.php" ]; then + cp -Ra "/var/www/html/nextcloud/config" "$NC_PERMCONFDIR/" +fi diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..0abc044 --- /dev/null +++ b/setup.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +# @copyright Copyright (c) 2017 Arthur Schiwon +# +# @author Arthur Schiwon +# +# @license GNU AGPL version 3 or any later version +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +NC_PERMDATADIR="/var/lib/univention-appcenter/apps/nextcloud/data" +NC_DATADIR="$NC_PERMDATADIR/nextcloud/data" + +NC_PERMCONFDIR="/var/lib/univention-appcenter/apps/nextcloud/conf" +NC_UCR_FILE="$NC_PERMCONFDIR/ucr" + +NC_DB_TYPE="pgsql" +NC_LOCAL_ADMIN="nc_admin" +NC_LOCAL_ADMIN_PWD=`pwgen -y 30 1` + +cd /var/www/html +if [ ! -x occ ]; then + echo "occ missing or not executable" + exit 1 +fi + +mkdir -p "$NC_DATADIR" +chown www-data:www-data -R "$NC_PERMDATADIR/nextcloud" + +./occ maintenance:install \ + --admin-user "$NC_LOCAL_ADMIN" \ + --admin-pass "$NC_LOCAL_ADMIN_PWD" \ + --database "$NC_DB_TYPE" \ + --database-host "$DB_HOST" \ + --database-port "$DB_PORT" \ + --database-name "$DB_NAME" \ + --database-user "$DB_USER" \ + --database-pass "$DB_PASSWORD" \ + --data-dir "$NC_DATADIR" + +STATE=$? +if [[ $STATE != 0 ]]; then + echo "Error while installing Nextcloud" + exit 1; +fi + +chown -R www-data "$NC_DATADIR" + +./occ check +./occ status +./occ app:list +./occ upgrade + +"$NC_UCR_FILE" + +# basic Nextcloud configuration +./occ config:system:set trusted_domains 0 --value="$NC_UCR_DOMAIN" +./occ config:system:set htaccess.RewriteBase --value="/nextcloud/" +./occ maintenance:update:htaccess +./occ config:system:set --value "\OC\Memcache\APCu" memcache.local +./occ app:enable user_ldap +# TODO: Other settings necessary? Proxy? + +# configure LDAP +NC_LDAP_CID=`./occ ldap:create-empty-config| cut -d"'" -f 2` +./occ ldap:set-config "$NC_LDAP_CID" "ldapAgentName" "VAL" +./occ ldap:set-config "$NC_LDAP_CID" "KEY" "VAL" +./occ ldap:set-config "$NC_LDAP_CID" "KEY" "VAL" +./occ ldap:set-config "$NC_LDAP_CID" "KEY" "VAL" +./occ ldap:set-config "$NC_LDAP_CID" "KEY" "VAL" +./occ ldap:set-config "$NC_LDAP_CID" "KEY" "VAL" +./occ ldap:set-config "$NC_LDAP_CID" "KEY" "VAL" +./occ ldap:set-config "$NC_LDAP_CID" "KEY" "VAL" +./occ ldap:set-config "$NC_LDAP_CID" "KEY" "VAL" +./occ ldap:set-config "$NC_LDAP_CID" "KEY" "VAL" +./occ ldap:set-config "$NC_LDAP_CID" "KEY" "VAL" +./occ ldap:set-config "$NC_LDAP_CID" "KEY" "VAL" +./occ ldap:set-config "$NC_LDAP_CID" "KEY" "VAL" +./occ ldap:set-config "$NC_LDAP_CID" "KEY" "VAL" +./occ ldap:set-config "$NC_LDAP_CID" "KEY" "VAL" + +# Apache configuration +cat /etc/apache2/apache2.conf |awk '//,/AllowOverride None/{sub("None", "All",$0)}{print}' > /tmp/apache2.conf && \ +mv /tmp/apache2.conf /etc/apache2/apache2.conf +sed -i '/SSLEngine on/a Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains;"' /etc/apache2/sites-enabled/default-ssl.conf + +# TODO LDAP Configuration +