Michael Lando | f5f13c4 | 2017-02-19 12:35:04 +0200 | [diff] [blame] | 1 | #/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 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 18 | ### Version 1.0 |
Michael Lando | f5f13c4 | 2017-02-19 12:35:04 +0200 | [diff] [blame] | 19 | ### Date: 10 Aug 2016 |
| 20 | ### |
| 21 | ############################################################################## |
| 22 | |
| 23 | #GLOBALS |
| 24 | |
| 25 | APP_CONFIG_TABLE='application_config' |
| 26 | |
| 27 | #### Functions - Start #### |
| 28 | usage() { echo "Usage: $0 <namespace> <schemaTemplates-folder>, for example: $0 vsp.schemaTemplates schemaTemplates/" 1>&2; exit 1; } |
| 29 | |
| 30 | getFileContent() |
| 31 | { |
| 32 | file=$1 |
| 33 | str=$(<$file) |
| 34 | echo $str |
| 35 | } |
| 36 | |
| 37 | |
| 38 | main() |
| 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 | |
| 53 | exit 0 |
| 54 | } |
| 55 | |
| 56 | #### Functions - End #### |
| 57 | |
| 58 | # Check arguements |
| 59 | if [ "$#" -lt 2 ] || [ "$#" -gt 2 ]; then |
| 60 | usage |
| 61 | fi |
| 62 | |
| 63 | |
| 64 | main $1 $2 |