Improve template for phpBB3 importer
authorGerhard Schlager <mail@gerhard-schlager.at>
Fri, 19 Aug 2016 21:46:18 +0000 (23:46 +0200)
committerGerhard Schlager <mail@gerhard-schlager.at>
Fri, 19 Aug 2016 21:48:43 +0000 (23:48 +0200)
- Exit immediately if the database import or any
  other command fails
- Store SHA26 checksum of database dump and
  automatically recreate database if the checksum
  changed since the last database import

templates/import/phpbb3.template.yml

index 29b81bd4a80deb07ae7458df1927f3a9b93665cf..35d185d325971671a223c31db2a739d08fa19b6a 100644 (file)
@@ -74,16 +74,23 @@ hooks:
         chmod: "+x"
         contents: |
           #!/bin/bash
+          set -e
+
           chown discourse /shared/import/settings.yml
           chown discourse -R /shared/import/data
 
           if [ -f "/shared/import/data/phpbb_mysql.sql" ]; then
+            if [ -f "/shared/import/mysql/imported" ] && ! sha256sum --check /shared/import/mysql/imported &>/dev/null ; then
+              echo "Checksum of database dump changed..."
+              rm /shared/import/mysql/imported
+            fi
+
             if [ ! -f "/shared/import/mysql/imported" ]; then
               echo "Loading database dump into MySQL..."
               mysql -uroot -e "DROP DATABASE IF EXISTS phpbb"
               mysql -uroot -e "CREATE DATABASE phpbb"
-              mysql -uroot --default-character-set=utf8 --database=phpbb < /shared/import/data/phpbb_mysql.sql && \
-              touch /shared/import/mysql/imported
+              mysql -uroot --default-character-set=utf8 --database=phpbb < /shared/import/data/phpbb_mysql.sql
+              sha256sum /shared/import/data/phpbb_mysql.sql > /shared/import/mysql/imported
             fi
           else
             sv stop mysql