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