Fix upgrade script number
[platform/core/security/cert-svc.git] / etc / upgrade / 242.cert-svc-db-upgrade.sh.in
1 #!/bin/bash
2 PATH=/bin:/usr/bin:/sbin:/usr/sbin
3
4 # Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
5 #
6 #    Licensed under the Apache License, Version 2.0 (the "License");
7 #    you may not use this file except in compliance with the License.
8 #    You may obtain a copy of the License at
9 #
10 #        http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #    Unless required by applicable law or agreed to in writing, software
13 #    distributed under the License is distributed on an "AS IS" BASIS,
14 #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #    See the License for the specific language governing permissions and
16 #    limitations under the License.
17 #
18 # @file        242.cert-svc-db-upgrade.sh.in
19 # @author      Sangwan Kwon (sangwan.kwon@samsung.com)
20 # @brief       cert-svc db migration scripts for platform upgrade 2.4 -> 3.0
21 #
22
23 OLD_DB=@CERT_SVC_OLD_DB_PATH@/certs-meta-old.db
24 NEW_DB=@CERT_SVC_DB_PATH@/certs-meta.db
25
26 MIGRATION_USER_TABLE=@CERT_SVC_DB_PATH@/migration-user-table.sql
27
28 # backup old database
29 mv @CERT_SVC_OLD_DB_PATH@/certs-meta.db $OLD_DB
30 rm -rf @CERT_SVC_OLD_DB_PATH@/certs-meta.db-journal
31
32 # remove deprecated dir
33 rm -rf @CERT_SVC_PKCS12@/storage
34
35 # install new database
36 cp @UPGRADE_DATA_PATH@/certs-meta.db $NEW_DB
37
38 # migration user certs db
39 touch $MIGRATION_USER_TABLE
40 echo "ATTACH DATABASE '$OLD_DB' as 'tmp';" >> $MIGRATION_USER_TABLE
41 echo "INSERT INTO wifi SELECT * FROM tmp.wifi;" >> $MIGRATION_USER_TABLE
42 echo "INSERT INTO vpn SELECT * FROM tmp.vpn;" >> $MIGRATION_USER_TABLE
43 echo "INSERT INTO email SELECT * FROM tmp.email;" >> $MIGRATION_USER_TABLE
44 echo "DETACH DATABASE 'tmp';" >> $MIGRATION_USER_TABLE
45 sqlite3 $NEW_DB ".read $MIGRATION_USER_TABLE"
46 rm -rf $MIGRATION_USER_TABLE
47
48 # update schema version to 2.4 (this is for bundle upgrade)
49 sqlite3 $NEW_DB "UPDATE schema_info SET version='1', description='Tizen 2.4' \
50                                  WHERE version='2';"
51
52 # update disabled certs on db
53 disabled_certs_cnt=`sqlite3 $OLD_DB "SELECT count(*) FROM disabled_certs;"`
54 if [ "$disabled_certs_cnt" != "0" ]
55 then
56         @UPGRADE_SCRIPT_PATH@/243.cert-svc-disabled-certs-upgrade.sh $OLD_DB $NEW_DB
57 fi
58
59 rm -rf $OLD_DB
60
61 # generate blank journal file newly
62 touch $NEW_DB-journal
63
64 # support backward compatablity
65 ln -sf @TZ_SYS_CA_BUNDLE@ @CERT_SVC_CA_BUNDLE@
66 chown -h @USER_NAME@:@GROUP_NAME@ @CERT_SVC_CA_BUNDLE@
67
68 # change permission
69 chsmack -a @SMACK_DOMAIN_NAME@ @CERT_SVC_DB_PATH@/*
70 chown @USER_NAME@:@GROUP_NAME@ @CERT_SVC_DB_PATH@/*
71 chmod 644 @CERT_SVC_DB_PATH@/*