diff --git a/seeddms.sh b/seeddms.sh index d76224d..f5a10f6 100755 --- a/seeddms.sh +++ b/seeddms.sh @@ -1,53 +1,41 @@ -#!/bin/bash +#!/bin/sh SOURCE_DIR=$(realpath $(dirname "${0}"))/seeddms -# Install dependencies for SeedDMS -apt-get -y --no-install-recommends install ghostscript id3 imagemagick libreoffice-calc libreoffice-impress libreoffice-writer php7.0-gd php7.0-fpm php7.0-mbstring php7.0-pgsql php7.0-xml php-pear poppler-utils unoconv - -# Install SeedDMS -wget https://sourceforge.net/projects/seeddms/files/seeddms-5.1.3/seeddms-quickstart-5.1.3.tar.gz/download -O /srv/seeddms.tgz -tar xzf /srv/seeddms.tgz -C /srv -mv /srv/seeddms51x /srv/seeddms -rm -f /srv/seeddms.tgz - -# Patch Previewers -patch -d /srv/seeddms -p0 <${SOURCE_DIR}/seeddms-previewers.patch +# Build Docker container +docker build -t seeddms ${SOURCE_DIR} # Populate database export SEEDDMS_PWD=$(head -c 18 /dev/urandom | base64) -envsubst <${SOURCE_DIR}/tmp/seeddms-createdb.sql >/tmp/seeddms-createdb.sql -sudo -u postgres psql -f /tmp/seeddms-createdb.sql -rm -f /tmp/seeddms-createdb.sql -export PGPASSWORD=${SEEDDMS_PWD} -psql -f /srv/seeddms/www/install/create_tables-postgres.sql seeddms seeddms +envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql +docker run --rm seeddms cat /srv/seeddms/create_tables-postgres.sql | docker exec -i -e PGPASSWORD=${SEEDDMS_PWD} postgres psql seeddms seeddms + +# Copy existing files into persistent storage +mkdir -p /srv/seeddms/conf +mkdir /srv/seeddms/data +docker run --rm -v /srv/seeddms/conf:/mnt/conf seeddms cp -rp /srv/seeddms/www/conf/. /mnt/conf +docker run --rm -v /srv/seeddms/data:/mnt/conf seeddms cp -rp /srv/seeddms/data/. /mnt/conf +chown -R 8010:8010 /srv/seeddms/data # Configure SeedDMS -envsubst <${SOURCE_DIR}/srv/seeddms/www/conf/settings.xml >/srv/seeddms/www/conf/settings.xml -rm -rf /srv/seeddms/www/install/ +envsubst <${SOURCE_DIR}/srv/seeddms/conf/settings.xml >/srv/seeddms/conf/settings.xml export SEEDDMS_ADMIN_USER=admin export SEEDDMS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) export SEEDDMS_ADMIN_EMAIL=admin@example.com -envsubst <${SOURCE_DIR}/tmp/seeddms-adminpwd.sql >/tmp/seeddms-adminpwd.sql -psql -f /tmp/seeddms-adminpwd.sql seeddms seeddms -unset PGPASSWORD -rm -f /tmp/seeddms-adminpwd.sql +envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql seeddms -# Create OS user -adduser --system --group --home /srv/seeddms --shell /bin/false seeddms -chown -R seeddms:www-data /srv/seeddms/ +# Create SeedDMS service +cp ${SOURCE_DIR}/etc/init.d/seeddms /etc/init.d/seeddms +rc-update add seeddms boot +service seeddms start -# Create PHP and nginx app definition -cp ${SOURCE_DIR}/etc/php/7.0/fpm/pool.d/seeddms.conf /etc/php/7.0/fpm/pool.d/seeddms.conf -cp ${SOURCE_DIR}/etc/nginx/apps-available/seeddms /etc/nginx/apps-available/seeddms -ln -s /etc/nginx/apps-available/seeddms /etc/nginx/apps-enabled/seeddms - -# Restart services -systemctl restart php7.0-fpm -systemctl restart nginx +# Create nginx app definition +cp ${SOURCE_DIR}/etc/nginx/apps/seeddms /etc/nginx/apps/seeddms +cp ${SOURCE_DIR}/etc/nginx/conf.d/seeddms.conf /etc/nginx/conf.d/seeddms.conf +service nginx reload # Install cron job -cp ${SOURCE_DIR}/etc/cron.d/seeddms /etc/cron.d/seeddms +cp ${SOURCE_DIR}/etc/periodic/hourly/seeddms /etc/periodic/hourly/seeddms # Add portal application definition -portal-app-manager seeddms "/seeddms/" "${SEEDDMS_ADMIN_USER}" "${SEEDDMS_ADMIN_PWD}" +portal-app-manager seeddms "https://{host}:8410/" "${SEEDDMS_ADMIN_USER}" "${SEEDDMS_ADMIN_PWD}" diff --git a/seeddms/Dockerfile b/seeddms/Dockerfile new file mode 100644 index 0000000..53a69ff --- /dev/null +++ b/seeddms/Dockerfile @@ -0,0 +1,42 @@ +FROM alpine:3.7 +MAINTAINER Disassembler + +RUN \ + # Install PHP runtime + apk --no-cache add nginx php7-fpm s6 + +RUN \ + # Install runtime dependencies + apk --no-cache add ghostscript imagemagick libreoffice-calc libreoffice-impress libreoffice-writer php7-gd php7-iconv php7-json php7-mbstring php7-pear php7-pdo_pgsql php7-simplexml php7-xml poppler-utils \ + # Install unoconv + && wget https://raw.githubusercontent.com/dagwieers/unoconv/master/unoconv -O /usr/local/bin/unoconv \ + && chmod +x /usr/local/bin/unoconv \ + && ln -s /usr/bin/python3 /usr/bin/python + +RUN \ + # Install SeedDMS + wget https://sourceforge.net/projects/seeddms/files/seeddms-5.1.5/seeddms-quickstart-5.1.5.tar.gz/download -O /srv/seeddms.tgz \ + && tar xzf /srv/seeddms.tgz -C /srv \ + && mv /srv/seeddms51x /srv/seeddms \ + && rm -f /srv/seeddms.tgz \ + && chown -R root:root /srv/seeddms \ + # Create OS user + && addgroup -S -g 8010 seeddms \ + && adduser -S -u 8010 -h /srv/seeddms -s /bin/false -g seeddms -G seeddms seeddms \ + # Cleanup + && cp /srv/seeddms/www/install/create_tables-postgres.sql /srv/seeddms/create_tables-postgres.sql \ + && rm -rf /srv/seeddms/www/install + +COPY docker/ / + +RUN \ + # Patch Previewers + cd /srv/seeddms \ + && patch -p0 converters = array( @@ -9,6 +9,8 @@ diff -ruN orig/SeedDMS/Preview/PdfPreviewer.php pear/SeedDMS/Preview/PdfPreviewe - 'application/vnd.oasis.opendocument.text' => "unoconv -d document -f pdf --stdout -v '%f' > '%o'", 'text/rtf' => "unoconv -d document -f pdf --stdout -v '%f' > '%o'", 'application/msword' => "unoconv -d document -f pdf --stdout -v '%f' > '%o'", +- 'application/vnd.ms-excel' => "unoconv -d document -f pdf --stdout -v '%f' > '%o'", +- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => "unoconv -d document -f pdf --stdout -v '%f' > '%o'", + 'application/vnd.oasis.opendocument.text' => "unoconv -d document -f pdf --stdout -v '%f' > '%o'", + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => "unoconv -d document -f pdf --stdout -v '%f' > '%o'", + 'application/vnd.ms-excel' => "unoconv -d spreadsheet -f pdf --stdout -v '%f' > '%o'", @@ -18,19 +20,16 @@ diff -ruN orig/SeedDMS/Preview/PdfPreviewer.php pear/SeedDMS/Preview/PdfPreviewe + 'application/vnd.oasis.opendocument.presentation' => "unoconv -d presentation -f pdf --stdout -v '%f' > '%o'", + 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => "unoconv -d presentation -f pdf --stdout -v '%f' > '%o'", + 'text/html' => "unoconv -d document -f pdf --stdout -v '%f' > '%o'", -+ 'text/plain' => "unoconv -d document -f pdf --stdout -v '%f' > '%o'", - ); - } /* }}} */ - + 'text/plain' => "unoconv -d document -f pdf --stdout -v '%f' > '%o'", + 'application/postscript' => "ps2pdf '%f' - > '%o'", + 'image/jpeg' => "convert '%f' pdf:- > '%o'", diff -ruN orig/SeedDMS/Preview/Previewer.php pear/SeedDMS/Preview/Previewer.php ---- orig/SeedDMS/Preview/Previewer.php 2017-05-03 14:14:18.000000000 +0200 -+++ pear/SeedDMS/Preview/Previewer.php 2017-10-07 19:02:22.781623907 +0200 -@@ -40,7 +40,19 @@ - 'text/plain' => "convert -resize %wx '%f' '%o'", +--- orig/SeedDMS/Preview/Previewer.php 2017-12-15 08:23:09.000000000 +0100 ++++ pear/SeedDMS/Preview/Previewer.php 2018-01-04 09:56:12.359902000 +0100 +@@ -41,6 +41,18 @@ 'application/pdf' => "convert -density 100 -resize %wx '%f[0]' '%o'", 'application/postscript' => "convert -density 100 -resize %wx '%f[0]' '%o'", -- 'application/x-compressed-tar' => "tar tzvf '%f' | convert -density 100 -resize %wx text:-[0] '%o", -+ 'application/x-compressed-tar' => "tar tzvf '%f' | convert -density 100 -resize %wx text:-[0] '%o'", + 'application/x-compressed-tar' => "tar tzvf '%f' | convert -density 100 -resize %wx text:-[0] '%o'", + 'text/rtf' => "unoconv -d document -e PageRange=1-1 -f pdf --stdout '%f' | convert -resize %wx pdf:- '%o'", + 'application/msword' => "unoconv -d document -e PageRange=1-1 -f pdf --stdout '%f' | convert -resize %wx pdf:- '%o'", + 'application/vnd.oasis.opendocument.text' => "unoconv -d document -e PageRange=1-1 -f pdf --stdout '%f' | convert -resize %wx pdf:- '%o'", diff --git a/seeddms/etc/cron.d/seeddms b/seeddms/etc/cron.d/seeddms deleted file mode 100644 index f9d3b45..0000000 --- a/seeddms/etc/cron.d/seeddms +++ /dev/null @@ -1 +0,0 @@ -5,35 * * * * seeddms cd /srv/seeddms/www/utils/ && /usr/bin/php indexer.php --config ../conf/settings.xml >/dev/null diff --git a/seeddms/etc/init.d/seeddms b/seeddms/etc/init.d/seeddms new file mode 100755 index 0000000..f5f4272 --- /dev/null +++ b/seeddms/etc/init.d/seeddms @@ -0,0 +1,17 @@ +#!/sbin/openrc-run + +description="SeedDMS docker container" + +depend() { + need docker net + use dns logger netmount + after postgres +} + +start() { + /usr/bin/docker run -d --rm --name seeddms --link=postgres -p 127.0.0.1:9010:8010 -v /srv/seeddms/data:/srv/seeddms/data -v /srv/seeddms/conf:/srv/seeddms/www/conf seeddms +} + +stop() { + /usr/bin/docker stop seeddms +} diff --git a/seeddms/etc/nginx/apps-available/seeddms b/seeddms/etc/nginx/apps-available/seeddms deleted file mode 100644 index d10022a..0000000 --- a/seeddms/etc/nginx/apps-available/seeddms +++ /dev/null @@ -1,10 +0,0 @@ -location /seeddms { - alias /srv/seeddms/www; - index index.php; - - location ~ \.php$ { - include snippets/fastcgi-php.conf; - fastcgi_param SCRIPT_FILENAME $request_filename; - fastcgi_pass unix:/run/php/seeddms.sock; - } -} diff --git a/seeddms/etc/nginx/apps/seeddms b/seeddms/etc/nginx/apps/seeddms new file mode 100644 index 0000000..8515fe1 --- /dev/null +++ b/seeddms/etc/nginx/apps/seeddms @@ -0,0 +1,9 @@ +access_log /var/log/nginx/seeddms.access.log; +error_log /var/log/nginx/seeddms.error.log; + +location / { + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Host $host:$server_port; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_pass http://127.0.0.1:9010; +} diff --git a/seeddms/etc/nginx/conf.d/seeddms.conf b/seeddms/etc/nginx/conf.d/seeddms.conf new file mode 100644 index 0000000..44c015e --- /dev/null +++ b/seeddms/etc/nginx/conf.d/seeddms.conf @@ -0,0 +1,11 @@ +server { + listen 8010; + listen [::]:8010; + include apps/seeddms; +} + +server { + listen 8410 ssl http2; + listen [::]:8410 ssl http2; + include apps/seeddms; +} diff --git a/seeddms/etc/periodic/hourly/seeddms b/seeddms/etc/periodic/hourly/seeddms new file mode 100755 index 0000000..5e9157d --- /dev/null +++ b/seeddms/etc/periodic/hourly/seeddms @@ -0,0 +1,3 @@ +#!/bin/sh + +docker exec seeddms "cd /srv/seeddms/www/utils/ && /usr/bin/php indexer.php --config ../conf/settings.xml" >/dev/null diff --git a/seeddms/etc/php/7.0/fpm/pool.d/seeddms.conf b/seeddms/etc/php/7.0/fpm/pool.d/seeddms.conf deleted file mode 100644 index d39d792..0000000 --- a/seeddms/etc/php/7.0/fpm/pool.d/seeddms.conf +++ /dev/null @@ -1,15 +0,0 @@ -[seeddms] -user = seeddms -group = seeddms - -listen = /run/php/seeddms.sock -listen.owner = www-data -listen.group = www-data - -pm = ondemand -pm.max_children = 8 - -php_admin_value[open_basedir] = /srv/seeddms:/tmp:/usr/share/php -php_admin_value[upload_max_filesize] = 100M - -env[LANG]=en_US.UTF-8 diff --git a/seeddms/srv/seeddms/www/conf/settings.xml b/seeddms/srv/seeddms/conf/settings.xml similarity index 90% rename from seeddms/srv/seeddms/www/conf/settings.xml rename to seeddms/srv/seeddms/conf/settings.xml index 7df6617..3c861fb 100644 --- a/seeddms/srv/seeddms/www/conf/settings.xml +++ b/seeddms/srv/seeddms/conf/settings.xml @@ -6,14 +6,14 @@ - + - +