separate package for reducing dependency
[platform/core/api/system-settings.git] / tests / scripts / convert_vconf_script_to_sql.sh
1 #!/bin/bash
2 MY_DIR="$( cd "$(dirname $(readlink -f "$0"))" ; pwd -P )"
3
4 db_name=vconf.db
5 tableName=vconf
6
7 vconf_internal_keys_script=$MY_DIR/vconf_all.sh
8 vconf_internal_keys_script_copy=$MY_DIR/vconf_all_copy.sh
9 dbScriptFile=vconf.sql
10
11 create_table(){
12
13 sqlite3 $db_name << EOF
14 DROP TABLE IF EXISTS ${tableName};
15
16 CREATE TABLE IF NOT EXISTS ${tableName} (
17 layer CHAR NOT NULL,
18 key CHAR NOT NULL,
19 value CHAR,
20 type CHAR,
21 read_privilege,
22 write_privilege,
23 PRIMARY KEY ( layer, key )
24 );
25
26 PRAGMA synchronous=OFF;
27 PRAGMA count_changes=OFF;
28 PRAGMA journal_mode=MEMORY;
29 PRAGMA temp_store=MEMORY;
30 EOF
31
32 }
33
34 create_insert_script(){
35
36 if [ ! -f "${vconf_internal_keys_script}" ]
37 then
38         echo "vconf-internal-keys script not found! [${vconf_internal_keys_script}]"
39         exit -1;
40 fi
41
42         cp -f ${vconf_internal_keys_script} ${vconf_internal_keys_script_copy}
43
44         cat /dev/null > ${dbScriptFile}
45
46         echo "BEGIN TRANSACTION;" >> ${dbScriptFile}
47
48         # sed -i 's/General notification/General_notification/g' ${vconf_internal_keys_script_copy}
49         sed -i 's/ create-string / \"string\" /g' ${vconf_internal_keys_script_copy}
50         sed -i 's/ create-int32 / \"int32\" /g' ${vconf_internal_keys_script_copy}
51         sed -i 's/ create-bool / \"bool\" /g' ${vconf_internal_keys_script_copy}
52
53         sed -i 's/\${TZ_SYS_GLOBALUSER_DATA}/\/opt\/usr\/data/g' ${vconf_internal_keys_script_copy}
54
55         cat ${vconf_internal_keys_script_copy} | grep buxton2ctl | awk -v tableName=$tableName -F'\"' '{ printf "INSERT INTO %s ( layer, key, value, type, read_privilege, write_privilege ) values ( \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\" );\n", tableName, $4, $6, $8, $2, $10, $12 }' > ${dbScriptFile}
56
57         echo "COMMIT TRANSACTION;"
58
59         echo "sqlite insert table!"
60         sqlite3 $db_name < ${dbScriptFile}
61         echo "sqlite insert end!"
62 }
63
64
65 main(){
66     create_table
67         create_insert_script
68 }
69
70 main $*