Bug 21440

Summary: koha-create expects the file passed by $DEFAULTSQL to be in gzip format
Product: Koha Reporter: Andreas Roussos <arouss1980>
Component: Installation and upgrade (command-line installer)Assignee: Andreas Roussos <arouss1980>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: major    
Priority: P3 CC: fridolin.somers, martin.renvoize, nick
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Add support to koha-create to allow it to accept both compressed and uncompressed files for DEFAULTSQL
Version(s) released in:
Attachments: Bug 21440: koha-create expects the file passed by $DEFAULTSQL to be in gzip format
Bug 21440: koha-create expects the file passed by $DEFAULTSQL to be in gzip format
Bug 21440: koha-create expects the file passed by $DEFAULTSQL to be in gzip format

Description Andreas Roussos 2018-09-27 16:02:10 UTC
When setting up a new Koha instance with `koha-create`, you have the
option of specifying an SQL file with default data to load. This is
done by setting the DEFAULTSQL variable in /etc/koha/koha-sites.conf
to point to a filename of your choice.

However, if you set the DEFAULTSQL variable to something like this:

DEFAULTSQL="/home/user/dump.sql"

and then run `koha-create --create-db instance`, you get this error:

gzip: /home/user/dump.sql: not in gzip format

This is due to the following code from debian/scripts/koha-create,
where the call to `zcat` fails if the file is not in gzip format.

if [ -e "$DEFAULTSQL" ]
then
    # Populate the database with default content.
    zcat "$DEFAULTSQL" |
    sed "s/__KOHASITE__/koha_$name/g" |
    mysql --host="$mysqlhost" --user="$mysqluser" --password="$mysqlpwd" "$mysqldb"
Comment 1 Andreas Roussos 2018-09-27 16:08:17 UTC
Created attachment 79541 [details] [review]
Bug 21440: koha-create expects the file passed by $DEFAULTSQL to be in gzip format

koha-create contains a call to `zcat` which fails if the file passed
as an argument is not in gzip format.

This patch fixes the issue by adding the -f flag to the zcat call in
koha-create, as per the top-voted answers in the following SE URLs:
https://unix.stackexchange.com/a/77309
https://unix.stackexchange.com/a/131944

Test plan:
1) in /etc/koha/koha-sites.conf, set the DEFAULTSQL variable to point
   to an _uncompressed_ SQL database dump
2) run `koha-create --create-db instance` and notice how it fails with:
   gzip: /path/to/dump.sql: not in gzip format
3) apply the patch
4) notice the extra line of information "The SQL file can be optionally
   compressed with gzip" in koha-sites.conf
5) run the `koha-create` command again, this time it should work
6) repeat with DEFAULTSQL pointing to a gzip'd dump, it should work too
Comment 2 Martin Renvoize 2018-10-08 13:05:37 UTC
Created attachment 80216 [details] [review]
Bug 21440: koha-create expects the file passed by $DEFAULTSQL to be in gzip format

koha-create contains a call to `zcat` which fails if the file passed
as an argument is not in gzip format.

This patch fixes the issue by adding the -f flag to the zcat call in
koha-create, as per the top-voted answers in the following SE URLs:
https://unix.stackexchange.com/a/77309
https://unix.stackexchange.com/a/131944

Test plan:
1) in /etc/koha/koha-sites.conf, set the DEFAULTSQL variable to point
   to an _uncompressed_ SQL database dump
2) run `koha-create --create-db instance` and notice how it fails with:
   gzip: /path/to/dump.sql: not in gzip format
3) apply the patch
4) notice the extra line of information "The SQL file can be optionally
   compressed with gzip" in koha-sites.conf
5) run the `koha-create` command again, this time it should work
6) repeat with DEFAULTSQL pointing to a gzip'd dump, it should work too

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 3 Martin Renvoize 2018-10-08 13:06:00 UTC
Nice little fix that works well, signing off.
Comment 4 Chris Cormack 2018-10-08 20:31:42 UTC
Created attachment 80235 [details] [review]
Bug 21440: koha-create expects the file passed by $DEFAULTSQL to be in gzip format

koha-create contains a call to `zcat` which fails if the file passed
as an argument is not in gzip format.

This patch fixes the issue by adding the -f flag to the zcat call in
koha-create, as per the top-voted answers in the following SE URLs:
https://unix.stackexchange.com/a/77309
https://unix.stackexchange.com/a/131944

Test plan:
1) in /etc/koha/koha-sites.conf, set the DEFAULTSQL variable to point
   to an _uncompressed_ SQL database dump
2) run `koha-create --create-db instance` and notice how it fails with:
   gzip: /path/to/dump.sql: not in gzip format
3) apply the patch
4) notice the extra line of information "The SQL file can be optionally
   compressed with gzip" in koha-sites.conf
5) run the `koha-create` command again, this time it should work
6) repeat with DEFAULTSQL pointing to a gzip'd dump, it should work too

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Comment 5 Nick Clemens (kidclamp) 2018-10-09 16:23:29 UTC
Awesome work all!

Pushed to master for 18.11
Comment 6 Martin Renvoize 2018-10-15 10:45:08 UTC
Pushed to 18.05.x for 18.05.05
Comment 7 Fridolin Somers 2018-10-24 09:07:42 UTC
Pushed to 17.11.x for 17.11.11