tizen 2.4 release
[framework/web/wrt-commons.git] / etc / wrt_commons_create_clean_db.sh
1 #!/bin/sh
2 # Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 #
4 #    Licensed under the Apache License, Version 2.0 (the "License");
5 #    you may not use this file except in compliance with the License.
6 #    You may obtain a copy of the License at
7 #
8 #        http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #    Unless required by applicable law or agreed to in writing, software
11 #    distributed under the License is distributed on an "AS IS" BASIS,
12 #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #    See the License for the specific language governing permissions and
14 #    limitations under the License.
15 #
16
17 DB_PATH=/opt/dbspace/
18 DB_USER_PATH=/opt/usr/dbspace/
19
20 function create_db {
21     name=$1
22     dbpath=$2
23     # extract smack label before removal
24     DB_LABEL=""
25     if [ -f $dbpath.$name.db ]
26     then
27         DB_LABEL=`/usr/bin/chsmack $dbpath.$name.db | sed -r "s/.*access=\"([^\"]+)\"/\1/"`
28     fi
29     /bin/rm -f $dbpath.$name.db
30
31     # extract smack label before removal
32     JOURNAL_LABEL=""
33     if [ -f $dbpath.$name.db-journal ]
34     then
35         JOURNAL_LABEL=`/usr/bin/chsmack $dbpath.$name.db-journal | sed -r "s/.*access=\"([^\"]+)\"/\1/"`
36     fi
37     /bin/rm -f $dbpath.$name.db-journal
38
39     SQL="PRAGMA journal_mode = PERSIST;"
40     /usr/bin/sqlite3 $dbpath.$name.db "$SQL"
41     SQL=".read /usr/share/wrt-engine/"$name"_db.sql"
42     /usr/bin/sqlite3 $dbpath.$name.db "$SQL"
43     /bin/touch $dbpath.$name.db-journal
44     /bin/chown 0:5000 $dbpath.$name.db
45     /bin/chown 0:5000 $dbpath.$name.db-journal
46     /bin/chmod 660 $dbpath.$name.db
47     /bin/chmod 660 $dbpath.$name.db-journal
48
49     /usr/bin/pkill -9 security-serv
50
51     # restore smack label
52     if [ -n "$DB_LABEL" ]
53     then
54         /usr/bin/chsmack -a "$DB_LABEL" $dbpath.$name.db
55     fi
56
57     # restore smack label
58     if [ -n "$JOURNAL_LABEL" ]
59     then
60         /usr/bin/chsmack -a "$JOURNAL_LABEL" $dbpath.$name.db-journal
61     fi
62 }
63
64 for name in wrt
65 do
66     create_db $name $DB_PATH
67 done
68
69 for name in wrt_custom_handler wrt_i18n
70 do
71     create_db $name $DB_USER_PATH
72 done