blob: 53a8e1db0a176c0ceef5244356d5b9956d1052b8 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/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!
12backend_list="rpm deb ipk"
13
14pm_installed=false
15
16for 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 "#LOCALSTATEDIR#/lib/dpkg/status" ]; then
24 pm_installed=true
25 break
26 fi
27 ;;
28
29 "ipk")
30 if [ -s "/var/lib/opkg/status" ]; then
31 pm_installed=true
32 break
33 fi
34 ;;
35 esac
36done
37
38remove_rcsd_link () {
39 if [ -n "`which update-rc.d`" ]; then
40 update-rc.d -f run-postinsts remove
41 fi
42}
43
44if [ -z "$pi_dir" ]; then
45 remove_rcsd_link
46 exit 0
47fi
48
49[ -e #SYSCONFDIR#/default/postinst ] && . #SYSCONFDIR#/default/postinst
50
51if [ "$POSTINST_LOGGING" = "1" ]; then
52 rm -f $LOGFILE
53 append_log=">>$LOGFILE 2>&1"
54fi
55
56exec_postinst_scriptlets() {
57 for i in `ls $pi_dir`; do
58 i=$pi_dir/$i
59 echo "Running postinst $i..."
60 [ "$POSTINST_LOGGING" = "1" ] && eval echo "Running postinst $i..." $append_log
61 if [ -x $i ]; then
62 eval sh -c $i $append_log
63 rm $i
64 else
65 echo "ERROR: postinst $i failed."
66 [ "$POSTINST_LOGGING" = "1" ] && eval echo "ERROR: postinst $i failed." $append_log
67 remove_pi_dir=0
68 fi
69 done
70}
71
72remove_pi_dir=1
73if $pm_installed; then
74 case $pm in
75 "ipk")
76 eval opkg configure $append_log
77 ;;
78
79 "deb")
80 eval dpkg --configure -a $append_log
81 ;;
82 esac
83else
84 exec_postinst_scriptlets
85fi
86
87# since all postinstalls executed successfully, remove the postinstalls directory
88# and the rcS.d link
89if [ $remove_pi_dir = 1 ]; then
90 rm -rf $pi_dir
91 remove_rcsd_link
92fi