Implement install & uninstall by CSC
[framework/web/wrt-installer.git] / etc / wrt_preinstall_widgets.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 _working_dir="/opt/usr/media/Downloads/.preinstallWidgets"
18 _widget_temp="/opt/share/widget/*"
19
20 #Reinstall widget during booting
21 _temp_widget_path="/opt/share/widget/temp_info"
22
23 install_widgets() {
24         _wgt_list=`find $_working_dir -name '*.wgt'`
25     install_failed=0
26         for list in $_wgt_list
27         do
28                 echo "Install $list"
29                 return_string=`wrt-installer -i $list 2>&1 | grep -v plugin`
30         if [ "$return_string" != "${return_string/successful/}" ]; then
31             echo "$list widget installation success"
32             rm -rf $list
33         else
34             echo "$list widget installaiton failed"
35             install_failed=1
36         fi
37         done
38
39     if [ $install_failed -ne 1 ];then
40         echo "preinstall success"
41         rm -rf $_working_dir
42     fi
43 }
44
45 restore_widget() {
46 #Remove temporary directory during widget installation
47 for file in $_widget_temp; do
48     if [[ -d $file  &&  ${file#*temp_[0-9]*} != $file ]]; then
49         rm -rf $file
50     fi
51 done
52
53 FILE_LIST=`ls $_temp_widget_path`
54
55 if [ -n "$FILE_LIST" ]; then
56     echo "There are widgets to need reinstall."
57     for widget in $FILE_LIST; do
58         FILE_NAME=$_temp_widget_path/$widget
59         line=`cat $FILE_NAME`
60         echo "----------------------------------------------------------------"
61         echo "UnInstalling widget : $line ..."
62                 return_string=`wrt-installer -up $line 2>&1 | grep -v plugin`
63         echo "Result $return_string"
64     done
65 else
66     echo "There is no reinstall widget."
67 fi
68 }
69
70 #Plugin installation is temporary code for window SDK
71 /usr/bin/wrt-installer -p
72
73 RECOVER_WIDGETS=`ls $_temp_widget_path`
74 if [ -n "$RECOVER_WIDGETS" ]; then
75     echo "Start Recover"
76     restore_widget
77 fi
78
79 install_widgets