From c42efb51e1ccf4b9430e8fbb5dbc54810fbcae2a Mon Sep 17 00:00:00 2001 From: Wonderfall Date: Wed, 12 Oct 2016 10:32:58 +0200 Subject: [PATCH] nextcloud: also update daily --- nextcloud/daily/Dockerfile | 16 ++++-- nextcloud/daily/run.sh | 25 +++++++-- nextcloud/daily/setup.sh | 110 +++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 11 deletions(-) create mode 100755 nextcloud/daily/setup.sh diff --git a/nextcloud/daily/Dockerfile b/nextcloud/daily/Dockerfile index f8d077c..da35cce 100644 --- a/nextcloud/daily/Dockerfile +++ b/nextcloud/daily/Dockerfile @@ -1,18 +1,23 @@ -FROM alpine:3.4 +FROM alpine:edge MAINTAINER Wonderfall +ARG NEXTCLOUD_VERSION=10.0.1 ARG GNU_LIBICONV_VERSION=1.14 +ARG GPG_nextcloud="2880 6A87 8AE4 23A2 8372 792E D758 99B9 A724 937A" ENV UID=991 GID=991 \ UPLOAD_MAX_SIZE=10G \ APC_SHM_SIZE=128M \ OPCACHE_MEM_SIZE=128 \ - CRON_PERIOD=15m + CRON_PERIOD=15m \ + TZ=Europe/Berlin \ + DB_TYPE=sqlite3 \ + ADMIN_USER=admin \ + ADMIN_PASSWORD=admin RUN echo "@commuedge https://nl.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \ && echo "@testing https://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \ && BUILD_DEPS=" \ - gnupg \ tar \ build-base \ autoconf \ @@ -71,13 +76,14 @@ RUN echo "@commuedge https://nl.alpinelinux.org/alpine/edge/community" >> /etc/a && wget -q https://download.nextcloud.com/server/daily/latest.tar.bz2 \ && tar xjf latest.tar.bz2 --strip 1 -C /nextcloud \ && apk del ${BUILD_DEPS} php7-pear php7-dev \ - && rm -rf /var/cache/apk/* /tmp/* + && rm -rf /var/cache/apk/* /tmp/* /root/.gnupg COPY nginx.conf /etc/nginx/nginx.conf COPY php-fpm.conf /etc/php7/php-fpm.conf COPY opcache.ini /etc/php7/conf.d/00_opcache.ini COPY apcu.ini /etc/php7/conf.d/apcu.ini COPY run.sh /usr/local/bin/run.sh +COPY setup.sh /usr/local/bin/setup.sh COPY occ /usr/local/bin/occ COPY s6.d /etc/s6.d @@ -88,6 +94,6 @@ VOLUME /data /config /apps2 EXPOSE 8888 LABEL description="A server software for creating file hosting services" \ - nextcloud="Nextcloud daily build" + nextcloud="Nextcloud v${NEXTCLOUD_VERSION}" CMD ["run.sh"] diff --git a/nextcloud/daily/run.sh b/nextcloud/daily/run.sh index 3fdff29..16b4785 100644 --- a/nextcloud/daily/run.sh +++ b/nextcloud/daily/run.sh @@ -1,17 +1,30 @@ #!/bin/sh -if [ ! -f /config/config.php ]; then - echo -e " '/data',\n);" > /config/config.php -fi - sed -i -e "s//$UPLOAD_MAX_SIZE/g" /etc/nginx/nginx.conf /etc/php7/php-fpm.conf \ -e "s//$APC_SHM_SIZE/g" /etc/php7/conf.d/apcu.ini \ -e "s//$OPCACHE_MEM_SIZE/g" /etc/php7/conf.d/00_opcache.ini \ -e "s//$CRON_PERIOD/g" /etc/s6.d/cron/run +# Put the configuration and apps into volumes +ln -sf /config/config.php /nextcloud/config/config.php &>/dev/null +ln -sf /apps2 /nextcloud &>/dev/null + chown -R $UID:$GID /nextcloud /data /config /apps2 /etc/nginx /etc/php7 /var/log /var/lib/nginx /tmp /etc/s6.d -ln -s /config/config.php /nextcloud/config/config.php &>/dev/null -ln -s /apps2 /nextcloud &>/dev/null +if [ ! -f /config/config.php ]; then + # New installation, run the setup + /usr/local/bin/setup.sh +else + occ upgrade + if [ \( $? -ne 0 \) -a \( $? -ne 3 \) ]; then + echo "Trying ownCloud upgrade again to work around ownCloud upgrade bug..." + occ upgrade + if [ \( $? -ne 0 \) -a \( $? -ne 3 \) ]; then exit 1; fi + occ maintenance:mode --off + echo "...which seemed to work." + fi +fi + +chown -R $UID:$GID /nextcloud /data /config /apps2 /etc/nginx /etc/php7 /var/log /var/lib/nginx /tmp /etc/s6.d exec su-exec $UID:$GID /bin/s6-svscan /etc/s6.d diff --git a/nextcloud/daily/setup.sh b/nextcloud/daily/setup.sh new file mode 100755 index 0000000..4ebe925 --- /dev/null +++ b/nextcloud/daily/setup.sh @@ -0,0 +1,110 @@ +#!/bin/sh +# Nextcloud +########################## + +#source setup/functions.sh # load our functions +#source /etc/mailinabox.conf # load global vars +CONFIGFILE=/config/config.php + + +# Create an initial configuration file. +instanceid=oc$(echo $PRIMARY_HOSTNAME | sha1sum | fold -w 10 | head -n 1) +cat > $CONFIGFILE < '/data', + + "apps_paths" => array ( + 0 => array ( + "path" => "/nextcloud/apps", + "url" => "/apps", + "writable" => false, + ), + 1 => array ( + "path" => "/apps2", + "url" => "/apps2", + "writable" => true, + ), + ), + + 'memcache.local' => '\OC\Memcache\APCu', + + 'instanceid' => '$instanceid', +); +?> +EOF + +# Create an auto-configuration file to fill in database settings +# when the install script is run. Make an administrator account +# here or else the install can't finish. +adminpassword=$(dd if=/dev/urandom bs=1 count=40 2>/dev/null | sha1sum | fold -w 30 | head -n 1) +cat > /nextcloud/config/autoconfig.php < '/data', + 'dbtype' => '${DB_TYPE:-sqlite3}', + 'dbname' => '${DB_NAME:-nextcloud}', + 'dbuser' => '${DB_USER:-nextcloud}', + 'dbpass' => '${DB_PASSWORD:-password}', + 'dbhost' => '${DB_HOST:-nextcloud-db}', + 'dbtableprefix' => 'oc_', +EOF +if [[ ! -z "$ADMIN_USER" ]]; then + cat >> /nextcloud/config/autoconfig.php < '${ADMIN_USER}', + 'adminpass' => '${ADMIN_PASSWORD}', +EOF +fi +cat >> /nextcloud/config/autoconfig.php < +EOF + +echo "Starting automatic configuration..." +# Execute ownCloud's setup step, which creates the ownCloud database. +# It also wipes it if it exists. And it updates config.php with database +# settings and deletes the autoconfig.php file. +(cd /nextcloud; php7 index.php) +echo "Automatic configuration finished." + +# Update config.php. +# * trusted_domains is reset to localhost by autoconfig starting with ownCloud 8.1.1, +# so set it here. It also can change if the box's PRIMARY_HOSTNAME changes, so +# this will make sure it has the right value. +# * Some settings weren't included in previous versions of Mail-in-a-Box. +# * We need to set the timezone to the system timezone to allow fail2ban to ban +# users within the proper timeframe +# * We need to set the logdateformat to something that will work correctly with fail2ban +# Use PHP to read the settings file, modify it, and write out the new settings array. +echo ${TZ:-UTC} >/etc/timezone + +TIMEZONE=$(cat /etc/timezone) +CONFIG_TEMP=$(/bin/mktemp) +php7 < $CONFIG_TEMP && mv $CONFIG_TEMP $CONFIGFILE + +EOF + +chown -R $UID:$GID /config +# Enable/disable apps. Note that this must be done after the ownCloud setup. +# The firstrunwizard gave Josh all sorts of problems, so disabling that. +# user_external is what allows ownCloud to use IMAP for login. The contacts +# and calendar apps are the extensions we really care about here. +occ app:disable firstrunwizard