Bug 21440 - koha-create expects the file passed by $DEFAULTSQL to be in gzip format
Summary: koha-create expects the file passed by $DEFAULTSQL to be in gzip format
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Installation and upgrade (command-line installer) (show other bugs)
Version: Main
Hardware: All All
: P3 major (vote)
Assignee: Andreas Roussos
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-27 16:02 UTC by Andreas Roussos
Modified: 2019-10-14 19:56 UTC (History)
3 users (show)

See Also:
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 (2.10 KB, patch)
2018-09-27 16:08 UTC, Andreas Roussos
Details | Diff | Splinter Review
Bug 21440: koha-create expects the file passed by $DEFAULTSQL to be in gzip format (2.16 KB, patch)
2018-10-08 13:05 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 21440: koha-create expects the file passed by $DEFAULTSQL to be in gzip format (2.22 KB, patch)
2018-10-08 20:31 UTC, Chris Cormack
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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 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