2 # Copyright (C) 2005-2018 by the Quassel Project - devel@quassel-irc.org
3 # Licensed under GNU General Public License version 2, or (at your option)
6 # Call this script whenever you move or rename the SQL files inside this
7 # folder. It'll regenerate 'sql.qrc' for you. If it fails, you can manually
8 # edit the file, too; just follow the pattern already in there.
10 # NOTE: In most cases you must upgrade the database schema version to make a
11 # change, which includes adding upgrade scripts and modifying existing setup
12 # queries. See 'upgradeSchema.sh' for details.
14 set -u # Bash - fail on undefined variable
16 # Path to the directory containing this script, resolving any symlinks, etc
17 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
19 # Name of the current directory
20 SQL_DIR_NAME="${SCRIPT_DIR##*/}"
21 # See https://stackoverflow.com/questions/1371261/get-current-directory-name-without-full-path-in-bash-script/1371283#1371283
23 # SQL resource file (one directory up from this script)
24 SQL_RES_FILE="$SCRIPT_DIR/../sql.qrc"
26 # Add the Qt resource header, overwriting the existing file
27 cat > "$SQL_RES_FILE" <<EOF
28 <!DOCTYPE RCC><RCC version="1.0">
32 # In a subshell, use C locale to sort consistently regardless of
33 # language, change to SQL directory so find output stays consistent,
35 # Find all files with a .sql ending...
36 # | ...sort the results by version
37 # | ...modify the beginning to change '.[...]' into ' <file>./SQL[...]' (add the directory path back)
38 # ...and modify the end to add '[...]</file>'
39 # | ...append to the resource file.
40 (export LC_ALL="C" ; cd "$SCRIPT_DIR" ; find . -name "*.sql" | sort --field-separator=/ --key=2,2 --key=4n | sed -e "s/^./ <file>.\/$SQL_DIR_NAME/g" -e "s/$/<\/file>/g" >> "$SQL_RES_FILE" )
41 # Newer versions of sort support a "--version-sort" flag to naturally sort.
42 # Unfortunately, some supported platforms don't yet have that version.
43 # For now, "--field-separator=/ --key=2,2 --key=4n" does -almost- the same
44 # thing (there's a difference when sorting periods versus underscores).
46 # Further explanation for sort command:
48 # > Separate fields by "/"
50 # > Sort by the second field, i.e. "SQLite" or "Postgres"
52 # > Sort by the fourth field using numeric comparison
53 # (e.g. the "##" in "SQL/[database]/versions/##")
55 # Add the Qt resource footer
56 cat >> "$SQL_RES_FILE" <<EOF