blob: ad3e6ad43da23a92e70fb931399e2001b2a6ea0a [file] [log] [blame]
Michael Landof5f13c42017-02-19 12:35:04 +02001#/bin/sh
2
3##############################################################################
4###
5### generate-application-config-insert-cql.sh
6###
7### A script that generates the CQL commands to INSERT validation schemas to the application_config table.
8### We keep the schemas FTL files under a folder - this folder will be parsed and INSERT commands will be created.
9###
10### If the path is 'schemaTemplates/composition/myFile.ftl' the result KEY will be: composition.myFile .
11###
12### Usage:
13###
14### ./generate-application-config-insert-cql.sh <namespace> <schemas-folder>
15###
16###
17### Author: Avi Ziv
AviZi280f8012017-06-09 02:39:56 +030018### Version 1.0
Michael Landof5f13c42017-02-19 12:35:04 +020019### Date: 10 Aug 2016
20###
21##############################################################################
22
23#GLOBALS
24
25APP_CONFIG_TABLE='application_config'
26
27#### Functions - Start ####
28usage() { echo "Usage: $0 <namespace> <schemaTemplates-folder>, for example: $0 vsp.schemaTemplates schemaTemplates/" 1>&2; exit 1; }
29
30getFileContent()
31{
32 file=$1
33 str=$(<$file)
34 echo $str
35}
36
37
38main()
39{
40 namespace=$1
41 path=$2
42 for fileName in $(find ${path} -type f)
43 do
44 value=$(getFileContent ${fileName})
45 onlyFilename=$(basename $fileName)
46 name="${onlyFilename%.*}"
47 tempPath=$(dirname $fileName)
48 keyColumn=$(basename $tempPath).$name
49 echo "INSERT INTO $APP_CONFIG_TABLE (namespace,key,value) VALUES ('$namespace', '$keyColumn', '$value');"
50 done
51
52
53exit 0
54}
55
56#### Functions - End ####
57
58# Check arguements
59if [ "$#" -lt 2 ] || [ "$#" -gt 2 ]; then
60 usage
61fi
62
63
64main $1 $2