6d578c7e9a984eeb73128c1422e69252f1ca3751
[framework/web/wrt-commons.git] / etc_wearable / wrt_commons_reset_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 /bin/rm -rf /opt/share/widget/system/*
18 uninstall_widgets=1
19 if [ "$1" == "--old" ]
20 then
21     /bin/echo "Uninstalling turned off"
22     uninstall_widgets=0
23 fi
24 #Removing of widget desktop icons
25 WIDGET_EXEC_PATH=/opt/usr/apps/
26 WIDGET_PRELOAD_EXEC_PATH=/usr/apps/
27 WIDGET_DESKTOP_PATH=/opt/share/applications/
28 SMACK_RULES_PATH=/etc/smack/accesses.d/
29 WRT_DB=/opt/dbspace/.wrt.db
30 PKGMGR_DB=/opt/dbspace/.pkgmgr_parser.db
31 PLUGINS_INSTALLATION_REQUIRED_PATH=/opt/share/widget/
32 PLUGINS_INSTALLATION_REQUIRED=plugin-installation-required
33
34 if [ -f ${WRT_DB} ]
35 then
36     PKG_NAME_SET=$(/usr/bin/sqlite3 $WRT_DB 'select tizen_appid from WidgetInfo;')
37     for appid in $PKG_NAME_SET
38     do
39         if [ $uninstall_widgets -eq 1 ]
40         then
41             wrt-installer -un $appid 1>/dev/null 2>&1
42         fi
43         pkgId=`echo "$appid" | cut -f1 -d"."`
44         /usr/bin/sqlite3 $PKGMGR_DB "delete from package_info where package=\"$pkgId\""
45         /usr/bin/sqlite3 $PKGMGR_DB "delete from package_app_info where app_id=\"$appid\""
46         /bin/rm -rf ${WIDGET_EXEC_PATH}${pkgId}
47         /bin/rm -rf ${WIDGET_PRELOAD_EXEC_PATH}${pkgId}
48         widget_desktop_file="${WIDGET_DESKTOP_PATH}${appid}.desktop";
49         if [ -f ${widget_desktop_file} ]; then
50             /bin/rm -f $widget_desktop_file;
51         fi
52         widget_smack_rule="${SMACK_RULES_PATH}${pkgId}"
53         if [ -f ${widget_smack_rule} ]; then
54             /bin/rm -f $widget_smack_rule;
55         fi
56     done
57 else
58     echo "${WRT_DB} doesn't exist"
59 fi
60
61 /usr/bin/wrt_commons_create_clean_db.sh
62
63 #TODO: remove this when switched to wrt-plugins-installer completely
64 if [ -e ${PLUGINS_INSTALLATION_REQUIRED_PATH} ] && [ -d ${PLUGINS_INSTALLATION_REQUIRED_PATH} ]
65 then
66     /bin/touch ${PLUGINS_INSTALLATION_REQUIRED_PATH}${PLUGINS_INSTALLATION_REQUIRED}
67 fi
68
69 #update plugins
70 if [ -x /usr/bin/wrt-installer ]
71 then
72     /usr/bin/wrt-installer -p
73 fi