f547a7b7bd389aee119d160ebee75481616bedda
[scm/bb/tizen-distro.git] / meta / recipes-devtools / run-postinsts / run-postinsts / run-postinsts
1 #!/bin/sh
2 #
3 # Copyright 2007 Openedhand Ltd.
4 #
5 # Author: Richard Purdie <rpurdie@openedhand.com>
6 #
7
8 # The following script will run all the scriptlets found in #SYSCONFDIR#/deb-postinsts,
9 # #SYSCONFDIR#/ipk-postinsts or #SYSCONFDIR#/rpm-posinsts.
10
11 # the order of this list is important, do not change!
12 backend_list="rpm deb ipk"
13
14 pm_installed=false
15
16 for pm in $backend_list; do
17         pi_dir="#SYSCONFDIR#/$pm-postinsts"
18
19         [ -d $pi_dir ] && break
20
21         case $pm in
22                 "deb")
23                         if [ -s "/var/lib/dpkg/status" ]; then
24                                 pm_installed=true
25                                 break
26                         fi
27                         ;;
28
29                 "ipk")
30                         pm_installed=true
31                         ;;
32         esac
33 done
34
35 remove_rcsd_link () {
36         if [ -n "`which update-rc.d`" ]; then
37                 update-rc.d -f run-postinsts remove
38         fi
39 }
40
41 if [ -z "$pi_dir" ]; then
42         remove_rcsd_link
43         exit 0
44 fi
45
46 [ -e #SYSCONFDIR#/default/postinst ] && . #SYSCONFDIR#/default/postinst
47
48 if [ "$POSTINST_LOGGING" = "1" ]; then
49         rm -f $LOGFILE
50         append_log=">>$LOGFILE 2>&1"
51 fi
52
53 exec_postinst_scriptlets() {
54         for i in `ls $pi_dir`; do
55                 i=$pi_dir/$i
56                 echo "Running postinst $i..."
57                 [ "$POSTINST_LOGGING" = "1" ] && eval echo "Running postinst $i..." $append_log
58                 if [ -x $i ]; then
59                         eval sh -c $i $append_log
60                         rm $i
61                 else
62                         echo "ERROR: postinst $i failed."
63                         [ "$POSTINST_LOGGING" = "1" ] && eval echo "ERROR: postinst $i failed." $append_log
64                         remove_pi_dir=0
65                 fi
66         done
67 }
68
69 remove_pi_dir=1
70 if $pm_installed; then
71         case $pm in
72                 "ipk")
73                         eval opkg-cl configure $append_log
74                         ;;
75
76                 "deb")
77                         eval dpkg --configure -a $append_log
78                         ;;
79         esac
80 else
81         exec_postinst_scriptlets
82 fi
83
84 # since all postinstalls executed successfully, remove the postinstalls directory
85 # and the rcS.d link
86 if [ $remove_pi_dir = 1 ]; then
87         rm -rf $pi_dir
88         remove_rcsd_link
89 fi